0
我有一些項目列表&每當我點擊其中的任何一個時,我會相應地轉到一個新的意圖。但是當我嘗試再次返回列表時,有些項目會給出正確的結果,而其他項目則會給出錯誤。完成活動時的例外情況
我已經嘗試調用onDestroy & onStop方法中的finish(),以提供錯誤的意圖。我也嘗試過註釋掉這兩種方法,因爲默認情況下它應該會脫離堆棧。但logcat的顯示
01-12 23:04:55.050: E/AndroidRuntime(14445): java.lang.RuntimeException: Unable to stop activity {com.balance.start/com.balance.start.GFX}: java.lang.NullPointerException
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3613)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3679)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.ActivityThread.access$2900(ActivityThread.java:126)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.os.Handler.dispatchMessage(Handler.java:99)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.os.Looper.loop(Looper.java:123)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.ActivityThread.main(ActivityThread.java:4633)
01-12 23:04:55.050: E/AndroidRuntime(14445): at java.lang.reflect.Method.invokeNative(Native Method)
01-12 23:04:55.050: E/AndroidRuntime(14445): at java.lang.reflect.Method.invoke(Method.java:521)
01-12 23:04:55.050: E/AndroidRuntime(14445): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-12 23:04:55.050: E/AndroidRuntime(14445): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-12 23:04:55.050: E/AndroidRuntime(14445): at dalvik.system.NativeStart.main(Native Method)
01-12 23:04:55.050: E/AndroidRuntime(14445): Caused by: java.lang.NullPointerException
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.Activity.performStop(Activity.java:3869)
01-12 23:04:55.050: E/AndroidRuntime(14445): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3608)
這是我的代碼..
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
{
super.onCreate(savedInstanceState);
setContentView(R.layout.report_ledger);
...
}
class MyAdapter extends CursorAdapter {
public MyAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View view, Context ctxt, Cursor c) {
// TODO Auto-generated method stub
TextView tv1 = (TextView) view.findViewById(R.id.tvAB1);
TextView tv2 = (TextView) view.findViewById(R.id.tvAB2);
TextView tv3 = (TextView) view.findViewById(R.id.tvAB3);
TextView tv4 = (TextView) view.findViewById(R.id.tvAB4);
TextView tv5 = (TextView) view.findViewById(R.id.tvAB5);
tv1.setText(c.getString(2));
tv2.setText("" + c.getDouble(3));
tv3.setText("" + c.getDouble(4));
tv4.setText("" + (c.getDouble(4) - c.getDouble(3)));
tv5.setText((c.getDouble(3) > c.getDouble(4) ? "CR." : "DR."));
}
@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = getLayoutInflater();
return inflater.inflate(
R.layout.text_view_for_list_view_account_balance, parent,
false);
}
}
我還沒有實現onClickListener的後退按鈕,因爲我並不需要做思考。我認爲系統應該自己完成活動。 :/
謝謝。
向我們展示這些方法的代碼。 –
Raghav你在問哪個代碼? 這是一個非常冗長的代碼。所以..我把代碼可能是錯誤的原因。 –
你爲什麼在'onDestroy()'中調用'finish()'?當系統完成你的活動時調用onDestroy()。沒有任何目的再次調用finish(),實際上可能是空指針的來源。 – shanet