我试图解析一些JSON数据.我的代码工作了一段时间,我不知道我改变了什么突然破坏了代码.当我运行我的代码时,我没有收到任何运行时错误或警告.我创建一个新的AsyncTask并执行它.当我调用.get()这个新任务时,调试器在这一行停止并花费超过30分钟.我无法获得调试器或在运行期间完成此任务.
JSON:
protected void setUp(Context context) {
_context = context;
getConfig();
}
// get config file
protected void getConfig() {
if (config != null)
return;
config = new Config();
String url = configURL;
AsyncTask<String, Integer, JSONObject> jsonTask = new DownloadJSONTask()
.execute(url);
JSONObject configItem = null;
try {
configItem = jsonTask.get(); //debugger pauses here
if (configItem == null)
return;
config.configVersion = configItem.getString("field_configversion");
config.currentAppVersion = configItem
.getString("field_currentappversion");
config.getSupportURL = configItem.getString("field_getsupporturl");
config.getCatalogURL = configItem.getString("field_getcatalogurl");
config.getDataVersion = configItem.getString("field_dataversion");
config.getDataUrl = configItem.getString("field_dataurl");
config.getDataApiKey …Run Code Online (Sandbox Code Playgroud) 我有一个Car具有此构造函数的对象:
public Car(int idCar, String name)
{
this.idCar = idCar;
this.name = name;
}
Run Code Online (Sandbox Code Playgroud)
这里我没有任何问题所以我创建了一个Car名为的对象newCar,如下所示:
Car newCar = new Car(1,"StrongCar");
Run Code Online (Sandbox Code Playgroud)
我有它的问题是我想把它传递newCar给我AsyncTask,modifyCar作为参数命名,但我不知道该怎么做.
我搜索过SO,我发现了这个问题:AsyncTask传递自定义对象,
但它并没有解决我的问题,因为在解决方案中它给出了它们只传递String给AsyncTask而不是完全对象.
我想要的是将完全对象作为参数传递给AsyncTask.
根据我在上面提出的问题中给出的解决方案,我试图将此对象传递给AsyncTask.
new modifyCar(newCar).execute();
Run Code Online (Sandbox Code Playgroud)
所以我声明AsyncTask是这样的:
class modifyCar extends AsyncTask<Car, Integer, ArrayList<Evento>> {
protected void onPreExecute()
{
}
protected ArrayList<Evento> doInBackground(Car... newCarAsync)
{
//The rest of the code using newCarAsync
}
protected void onProgressUpdate()
{
}
protected void onPostExecute() …Run Code Online (Sandbox Code Playgroud)