我有两个Class page1和page2。当单击page1中的按钮时,如何将页面1中的数据从page1传输到整数
我尝试了几个代码: Page1.Class
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = null;
switch (position)
{
case 0:
i = new Intent(this, page2.class );
i.putExtra("Konum", 2);
break;
}
startActivity(i);
Page2.Class
Intent intent = getIntent();
private Integer konum = intent.getIntExtra("Konum", 0);
但不起作用! 当点击page1中的按钮时,如何将第1页的数据从page1传输到整数
EROR:
09-27 19:50:19.556: E/AndroidRuntime(528): FATAL EXCEPTION: main
09-27 19:50:19.556: E/AndroidRuntime(528): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ru.truba.touchgallery/ru.truba.touchgallery.GalleryUrlActivity}: java.lang.NullPointerException
09-27 19:50:19.556: E/AndroidRuntime(528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-27 19:50:19.556: E/AndroidRuntime(528): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-27 19:50:19.556: E/AndroidRuntime(528): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-27 19:50:19.556: E/AndroidRuntime(528): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-27 19:50:19.556: E/AndroidRuntime(528): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 19:50:19.556: E/AndroidRuntime(528): at android.os.Looper.loop(Looper.java:123)
09-27 19:50:19.556: E/AndroidRuntime(528): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-27 19:50:19.556: E/AndroidRuntime(528): at java.lang.reflect.Method.invokeNative(Native Method)
答案 0 :(得分:0)
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", 1);
startActivity(i);
和oncreate()之后的其他活动
Bundle extras = getIntent().getExtras();
int value1 = extras.getint("Value1",0);
上的详细教程