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,因为我认为这不是必需的。我认为系统应该自己完成活动。:/

谢谢。

4

1 回答 1

0

恐怕你来电finish()onDestroy()。实际上finish()需要在您想要finish()您的活动时调用,其中onDestroy()方法会自动调用。onDestroy()取而代之的是,如果需要,您可以使您的意图或其他对象为空。

于 2013-01-13T18:30:00.380 回答