在两个活动之间传递字符串路径

时间:2011-07-03 14:01:18

标签: android

我想将字符串路径从一个活动传递到另一个活动......这是我的代码:

第一项活动

protected void onListItemClick(ListView l, View v, int position, long id) {

        String a = MEDIA_PATH + songs.get(position);
        Intent newActivity = new Intent(this, mainscreen.class);

        newActivity.putExtra("VIDEO", a);
        startActivity(newActivity);

    }

第二项活动

     Bundle extras = getIntent().getExtras();
String videos = extras.getString("VIDEO");

我得到一个运行时异常是行

Bundle extras = getIntent().getExtras();

07-03 16:57:03.362: ERROR/AndroidRuntime(7069): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.data/com.example.data.mainscreen}: java.lang.NullPointerException

EDIT(logcat的)

07-03 17:21:58.806: ERROR/AndroidRuntime(8836): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.data/com.example.data.mainscreen}: java.lang.NullPointerException
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.os.Looper.loop(Looper.java:123)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.ActivityThread.main(ActivityThread.java:3687)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at java.lang.reflect.Method.invokeNative(Native Method)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at java.lang.reflect.Method.invoke(Method.java:507)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at dalvik.system.NativeStart.main(Native Method)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836): Caused by: java.lang.NullPointerException
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at com.example.data.mainscreen.<init>(mainscreen.java:12)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at java.lang.Class.newInstanceImpl(Native Method)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at java.lang.Class.newInstance(Class.java:1409)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
07-03 17:21:58.806: ERROR/AndroidRuntime(8836):     ... 11 more

1 个答案:

答案 0 :(得分:0)

您必须将类主屏幕添加到manifest.xml。