我对编程非常陌生。我有一个程序,有很多很多方法可以相互连续运行。我的应用程序冻结,直到完成计算。我想把所有内容都放在AsyncTask中,但我很难理解它是如何工作的。
这就是我所拥有的单独的java文件。
import android.os.AsyncTask;
public class ConvertToStringToIntt extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(String... timeString) {
String time = timeString;
time = time.replace(":","");
int value = -2;
try {
value = Integer.parseInt(time);
} catch (NumberFormatException e) {
Message.message(this, "String time could not be converted to int");
}
return value;
}
}
此方法基本上采用时间字符串并将其作为int返回。但我在String time = timeString
中收到错误;
说:
不兼容的类型必需:java.lang.String找到: java.lang.String中[]
我不知道这意味着什么。任何帮助都会很棒,谢谢。
答案 0 :(得分:0)
使用您的方法,如果您确定只传递一个字符串//无论业务逻辑如何
public class ConvertToStringToIntt extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(String... timeString) {
String time = timeString[0];
time = time.replace(":","");
int value = -2;
try {
value = Integer.parseInt(time);
} catch (NumberFormatException e) {
Message.message(this, "String time could not be converted to int");
}
return value;
}
}