我在使用我的数据创建 ListView 时遇到问题。生成它的代码是:
protected void onPostExecute(DtoProjectListItem[] result) {
mProgressDialog.dismiss();
// DtoProjectListItem[] Adapter for ListView
ArrayAdapter<DtoProjectListItem> projects_adapter = new ArrayAdapter<DtoProjectListItem>(
ProjectListActivity.this,
R.layout.activity_project_list_item,
R.id.tvProjectName,
result
);
ListView lvProjects = (ListView) findViewById(R.layout.activity_project_list);
lvProjects.setAdapter(projects_adapter);
}
我得到的错误是:
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x40cad930)
FATAL EXCEPTION: main
java.lang.NullPointerException
at org.my.cihub.ProjectListActivity$GetDataAsyncTask.onPostExecute(ProjectListActivity.java:173)
at org.my.cihub.ProjectListActivity$GetDataAsyncTask.onPostExecute(ProjectListActivity.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
12-08 20:31:03.386: I/Process(21412): Sending signal. PID: 21412 SIG: 9
第 173 行是:
lvProjects.setAdapter(projects_adapter);
有人可以帮我解决这个问题吗?
谢谢!:)