0

I am sending long value and String value as extras from list activity to agenmin activity.But get java.lang.NullPointerException at line 120

    long baba1 = intent1.getExtras().getLong("baba",0); //line number 120

Sending from list activity

          // long id from from listview

            Intent i = new Intent(list.this, agenmin.class);
            i.putExtra("baba", id);
            startActivity(i); 

             //int position from listview
            String c= Integer.toString(position);
            Intent i1 = new Intent(list.this, agenmin.class);
            i1.putExtra("abc", c);
            startActivity(i1); 

At receiving side agenmin

            Intent i1 = getIntent();
        String easyPuzzle;
        easyPuzzle=i1.getStringExtra("abc");
        textView2.setText(easyPuzzle);

        Toast.makeText(getApplicationContext(), "Position " + (mess)+" ROWID " +(easyPuzzle), Toast.LENGTH_LONG).show();


           Intent intent1 = getIntent();
        long baba1 = intent1.getExtras().getLong("baba",0);
        String strLong1 = Long.toString(baba1);
        textView3.setText(strLong1);

Logcat:

      05-27 20:43:45.169: E/AndroidRuntime(593): FATAL EXCEPTION: main
      05-27 20:43:45.169: E/AndroidRuntime(593): java.lang.NullPointerException
      05-27 20:43:45.169: E/AndroidRuntime(593):    at com.indianic.demo.calendark.agenmin$1.onClick(agenmin.java:120)

I started the agenmin activity twice thats the reason for 'java.lang.NullPointerException at line 120

4

2 回答 2

1

尝试这个:

PendingIntent intent1 = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

于 2013-05-27T15:39:02.803 回答
0

为什么你有两个意图开始agenmin活动?

这样你就开始了agenmin两次活动,但每次开始只多给一次。然后无法获得第二个额外内容,当您尝试使用它的值时它会崩溃。

只需这样做:

Intent i = new Intent(list.this, agenmin.class);
i.putExtra("baba", id);
i.putExtra("abc", c);
startActivity(i);

我建议您阅读更多有关意图是什么以及它们如何工作的信息。例如这里。要开始一项不同的活动,您只需要一个意图。您可以根据需要在其中添加任意数量的额外内容。

于 2013-05-27T15:58:22.463 回答