gpt4 book ai didi

java - 构造函数 Intent(DataCountUtilities, Class) 未定义

转载 作者:行者123 更新时间:2023-12-01 14:24:24 26 4
gpt4 key购买 nike

尝试使用以下方法在 Activity 和服务之间传递数据时出现以下错误,我真的不确定原因:

数据计数实用程序:

public class DataCountUtilities {

//swap the content of a string by switching place
//each pair of consecutive characters
//If string length is odd last character is left in place
public String swappedMdn(Context ctx){
TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
//Extract the phone number from the TelephonyManager instance
String mdn = tm.getLine1Number();
//Insure MDN is 10 characters
if (mdn.length() < 10 || mdn == null) mdn ="0000000000";
//Extract last 10 digits of MDN
if (mdn.length() > 10) mdn = mdn.substring(mdn.length() - 10, mdn.length());
char data[] = mdn.toCharArray();
char digit;
for (int index = 0; index < mdn.length() - (mdn.length())%2; index+=2){
digit = data[index];
data[index] = data[index+1];
data[index+1] = digit;


Intent i = new Intent(DataCountUtilities.this, DataCountService.class);
i.putExtra("key", mdn);
startActivity(i);

}

return String.valueOf(data);

}

private void startActivity(Intent i) {
// TODO Auto-generated method stub

}}

最佳答案

Intent 需要一个 Context 作为第一个参数。

换行

Intent i = new Intent(DataCountUtilities.this, DataCountService.class);

Intent i = new Intent(ctx, DataCountService.class);

关于java - 构造函数 Intent(DataCountUtilities, Class<DataCountService>) 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17282388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com