我送long
價值和String
值從列表活動羣衆演員agenmin activity.But在line 120
顯示java.lang.NullPointerException長baba1
long baba1 = intent1.getExtras().getLong("baba",0); //line number 120
得到java.lang.NullPointerException
從列表活動發送
// 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);
在接收側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)
我開始agenmin活動兩次,這就是在line 120
你確定第120行真的是你說的嗎?因爲似乎沒有任何可能導致'NullPointerException'的東西... – zbr
它因爲我開始活動兩次它解決了我的問題。但如果我初始化長baba1 = 0;它停止給出java.lang.NullPointerException但應用程序用於崩潰謝謝你! :) – pantera