-3

我正在创建个人资料页面。此页面将从登录页面获取所有数据,这些数据将是必填字段,例如 First_Name、Last_Name 等。我正在从登录活动发送一个 Intent,但在配置文件活动中它会抛出 NullPointerException。

登录(主要活动)活动的代码是:

Bundle Basket = new Bundle();
Basket.putString("First_Name", first_name);
Basket.putString("Last_Name", last_name);
Basket.putString("Email", emails);
Basket.putString("Password",password);
Basket.putInt("Id", id);
Basket.putInt("Role", role);
Basket.putInt("status", status);
Basket.putInt("Active", active);
Intent dashboard = new Intent(MainActivity.this,Dashboard.class);
dashboard.putExtras(Basket);
startActivity(dashboard);

Profile.java 的代码是

public void onCreate(Bundle SavedInstance){
    super.onCreate(SavedInstance);
    setContentView(R.layout.profile);
    fn = (TextView) findViewById (R.id.f_p_n_1);
    ln = (TextView) findViewById (R.id.l_p_n_1);
    em = (TextView) findViewById (R.id.e_p_n_1);
    b1 = (ImageButton) findViewById (R.id.home );
    b2 = (ImageButton) findViewById (R.id.setting );
    b3 = (ImageButton) findViewById (R.id.feedback );

    Bundle extras = this.getIntent().getExtras();
    f_n = extras.getString("First_Name");
    System.out.println(f_n);

我的 manifest.xml 文件是

 <activity
        android:name="com.yousaf.naveed.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.yousaf.naveed.register"></activity>
    <activity android:name="com.yousaf.naveed.Dashboard">
        <intent-filter >
            <action android:name="android.intent.action.VIEW"/>
            <action android:name="android.intent.action.GET_CONTENT"/>
             <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>
    <activity android:name="com.yousaf.naveed.Trip"></activity>
    <activity android:name="com.yousaf.naveed.Request"></activity>
    <activity android:name="com.yousaf.naveed.Profile">
        <intent-filter >
            <action android:name="android.intent.action.VIEW"/>
            <action android:name="android.intent.action.GET_CONTENT"/>
             <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>

我不确定问题出在哪里。谢谢您的帮助。其完整的 Logcat 是

10-29 03:58:17.313: E/AndroidRuntime(23257): FATAL EXCEPTION: main
10-29 03:58:17.313: E/AndroidRuntime(23257): java.lang.RuntimeException: Unable to   start activity ComponentInfo{com.yousaf.naveed/com.yousaf.naveed.Dashboard}:    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yousaf.naveed/com.yousaf.naveed.Profile}: java.lang.NullPointerException
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.os.Looper.loop(Looper.java:150)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.main(ActivityThread.java:4389)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at java.lang.reflect.Method.invokeNative(Native Method)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at java.lang.reflect.Method.invoke(Method.java:507)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at dalvik.system.NativeStart.main(Native Method)
10-29 03:58:17.313: E/AndroidRuntime(23257): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yousaf.naveed/com.yousaf.naveed.Profile}: java.lang.NullPointerException
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1692)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:656)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.widget.TabHost.setCurrentTab(TabHost.java:326)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.widget.TabHost.addTab(TabHost.java:216)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at com.yousaf.naveed.Dashboard.onCreate(Dashboard.java:37)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
10-29 03:58:17.313: E/AndroidRuntime(23257):    ... 11 more
10-29 03:58:17.313: E/AndroidRuntime(23257): Caused by: java.lang.NullPointerException
10-29 03:58:17.313: E/AndroidRuntime(23257):    at  com.yousaf.naveed.Profile.onCreate(Profile.java:26)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
10-29 03:58:17.313: E/AndroidRuntime(23257):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
4

1 回答 1

0
Intent dashboard = new Intent(MainActivity.this, Dashboard.class);

我的猜测是:替换DashboardProfile.

于 2013-10-28T22:56:39.880 回答