这是我的问题,我正在尝试从 ListView 中设置文本。问题是,我会收到一个错误,因为(根据我的日志)我的主要活动的 setContentView 与我想从另一个 .xml (contactList.xml)设置文本的 TextView 不匹配
工作活动(主要)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jobs);
vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
TextView assigned = (TextView) findViewById(R.id.assigned);
new ParseJobs().execute();
ParseJobs() 方法
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (ACKNOWLEDGED.contains("False")) {
/** Updating parsed JSON data into ListView */
ListAdapter adapter = new SimpleAdapter(Jobs.this, contactList, R.layout.list_item, new String[] { job, pays, ready_at }, new int[] { R.id.job1, R.id.pays1, R.id.ready_at1 });
setListAdapter(adapter);
//TextView readyORdue = (TextView) findViewById(R.id.readyORdue);
//readyORdue.setText("Ready At:");
}
if (ACKNOWLEDGED.contains("True")) {
/** Updating parsed JSON data into ListView */
ListAdapter adapter = new SimpleAdapter(Jobs.this, contactList, R.layout.list_item, new String[] { job, pays, due_by }, new int[] { R.id.job1, R.id.pays1, R.id.due_by1 });
setListAdapter(adapter);
//TextView readyORdue = (TextView) findViewById(R.id.readyORdue);
//readyORdue.setText("Due By:");
}
VerifyDriver.dismiss();
}
}
请注意,在我的 ParseJobs 方法中,我正在尝试更新 TextView “readyORdue”,但我会收到错误消息,因为 TextView 属于 SimpleAdapter contactList.xml
所以我的问题是,我将如何从我的contactList XML 布局中设置文本视图?
这是我的日志:
07-17 15:55:16.703: W/dalvikvm(4387): threadid=1: thread exiting with uncaught exception (group=0x40015578)
07-17 15:55:16.703: E/AndroidRuntime(4387): FATAL EXCEPTION: main
07-17 15:55:16.703: E/AndroidRuntime(4387): java.lang.NullPointerException
07-17 15:55:16.703: E/AndroidRuntime(4387): at com.jetdelivery.mobile.Jobs$ParseJobs.onPostExecute(Jobs.java:287)
07-17 15:55:16.703: E/AndroidRuntime(4387): at com.jetdelivery.mobile.Jobs$ParseJobs.onPostExecute(Jobs.java:1)
07-17 15:55:16.703: E/AndroidRuntime(4387): at android.os.AsyncTask.finish(AsyncTask.java:417)
07-17 15:55:16.703: E/AndroidRuntime(4387): at android.os.AsyncTask.access$300(AsyncTask.java:127)
07-17 15:55:16.703: E/AndroidRuntime(4387): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
07-17 15:55:16.703: E/AndroidRuntime(4387): at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 15:55:16.703: E/AndroidRuntime(4387): at android.os.Looper.loop(Looper.java:130)
07-17 15:55:16.703: E/AndroidRuntime(4387): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-17 15:55:16.703: E/AndroidRuntime(4387): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 15:55:16.703: E/AndroidRuntime(4387): at java.lang.reflect.Method.invoke(Method.java:507)
07-17 15:55:16.703: E/AndroidRuntime(4387): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-17 15:55:16.703: E/AndroidRuntime(4387): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-17 15:55:16.703: E/AndroidRuntime(4387): at dalvik.system.NativeStart.main(Native Method)
第 287 行是“readyORdue.setText("Ready At:");"