我正在尝试在下一个代码中填充一个数组字符串。
public void setArray_name_venues(List<Venue> list) {
// storing string resources into Array
for(int i = 0; i < list.size(); i++){
this.name_venues[i] = "" + list.get(i).getName();
}
}
我使用一个 Asynhttp 客户端,我将此方法称为 onFinish 方法。
public void getVenues() {
AsyncHttpClient client = new AsyncHttpClient();
client.get(getQueryVenues4SQ(), null, new JsonHttpResponseHandler() {
@Override
public void onFinish() {
// TODO Auto-generated method stub
//super.onFinish();
File log2 = new File(Environment.getExternalStorageDirectory(),"venlist.txt");
try {
BufferedWriter out = new BufferedWriter(new FileWriter(log2.getAbsolutePath(),false));
for(int i = 0; i < getListCategories().size(); i++){
out.write(listVenues.get(i).toString());
}
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
runOnUiThread(new Runnable() {
public void run() {
setArray_name_venues(listVenues);
Log.i("ArrayVenues", getArray_name_venues().toString());
// Binding resources Array to ListAdapter
customListView.setAdapter(new ArrayAdapter<String>(MainActivity.this, R.layout.list_venues, name_venues));
}
});
runOnUiThread(new Runnable() {
public void run() {
makeToast("Nightclubs cargados", 1);
}
});
}
它在 setArray_name_venues(listVenues) 中失败。
谢谢你的帮助
编辑:
“name_venues”位于公共类 MainActivity 开始处的“String[] name_venues”变量上,在 oncreate 方法之前。
日志猫:
05-30 14:24:14.645: W/dalvikvm(21040): threadid=1: thread exiting with uncaught exception (group=0x410652a0)
05-30 14:24:14.645: E/AndroidRuntime(21040): FATAL EXCEPTION: main
05-30 14:24:14.645: E/AndroidRuntime(21040): java.lang.NullPointerException
05-30 14:24:14.645: E/AndroidRuntime(21040): at victor.martin.loc4sq.MainActivity.setArray_name_venues(MainActivity.java:100)
05-30 14:24:14.645: E/AndroidRuntime(21040): at victor.martin.loc4sq.MainActivity$2$1.run(MainActivity.java:271)
05-30 14:24:14.645: E/AndroidRuntime(21040): at android.app.Activity.runOnUiThread(Activity.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at victor.martin.loc4sq.MainActivity$2.onFinish(MainActivity.java:269)
05-30 14:24:14.645: E/AndroidRuntime(21040): at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:194)
05-30 14:24:14.645: E/AndroidRuntime(21040): at com.loopj.android.http.JsonHttpResponseHandler.handleMessage(JsonHttpResponseHandler.java:123)
05-30 14:24:14.645: E/AndroidRuntime(21040): at com.loopj.android.http.AsyncHttpResponseHandler$1.handleMessage(AsyncHttpResponseHandler.java:84)
05-30 14:24:14.645: E/AndroidRuntime(21040): at android.os.Handler.dispatchMessage(Handler.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at android.os.Looper.loop(Looper.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at android.app.ActivityThread.main(ActivityThread.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 14:24:14.645: E/AndroidRuntime(21040): at java.lang.reflect.Method.invoke(Method.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
05-30 14:24:14.645: E/AndroidRuntime(21040): at dalvik.system.NativeStart.main(Native Method)