在创建android的片段中的空指针异常?

时间:2014-03-31 07:15:35

标签: android nullpointerexception android-activity fragment

当我在Android版本2.2.1中运行我的应用程序时,我收到以下异常。

     FATAL EXCEPTION: main
     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vfc.mardemo1/com.vfc.register.RegUserDetailActivity}: java.lang.NullPointerException
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)  
     at android.app.ActivityThread.access$2300(ActivityThread.java:126)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:123)
     at android.app.ActivityThread.main(ActivityThread.java:4633)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:521)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     at dalvik.system.NativeStart.main(Native Method)


     Caused by: java.lang.NullPointerException
     at com.vfc.register.RegUserDetailActivity$PlaceholderFragment.onCreateView(RegUserDetailActivity.java:65)
     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
     at android.app.Activity.performStart(Activity.java:3781)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2642)

第65行没有代码,我的活动只包含63个LOC。

有人可以帮助我。

该应用程序在冰淇淋三明治及以上运行良好。

这是活动代码

    public class RegisterActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    overridePendingTransition(R.anim.fadein, R.anim.fadeout);
    setContentView(R.layout.register_activity);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MENU) {
        // do nothing
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.register_fragment,
                container, false);
        return rootView;
    }
}

public void onReg(View v) {
    Intent i = new Intent(RegisterActivity.this,
            RegUserDetailActivity.class);
    startActivity(i);
}

}

0 个答案:

没有答案