应用程序从纵向模式切换到横向模式时崩溃

时间:2014-03-26 10:43:36

标签: android android-layout android-fragments navigation-drawer

当我从横向模式启动我的应用程序时,它完美运行。但是,当我尝试从纵向模式切换到横向模式时,它会崩溃。我在纵向模式下使用导航抽屉,在横向模式下使用线性布局。

代码:

HomeMainFragment Mfrag;
HomeSideFragment Afrag;
DrawerLayout drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home); // Line 45  

    int screenconfig=getResources().getConfiguration().orientation;

     Mfrag=new HomeMainFragment();       
     Afrag=new HomeSideFragment();

    if(screenconfig==Configuration.ORIENTATION_PORTRAIT){     
    drawer=(DrawerLayout)findViewById(R.id.DrawerL);

 getFragmentManager().beginTransaction().replace(R.id.fm_homesidefrag, Afrag).
    setCustomAnimations(android.R.anim.slide_in_left,   android.R.anim.slide_out_right).commit();       
    }               
        getFragmentManager().beginTransaction().replace(R.id.fm_homemainfrag, Mfrag).
        setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right).commit();

}

日志:

03-26 16:09:42.195: E/AndroidRuntime(24156): FATAL EXCEPTION: main
03-26 16:09:42.195: E/AndroidRuntime(24156): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multipaneviews/com.example.multipaneviews.HomeActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
03-26 16:09:42.195: E/AndroidRuntime(24156):    at com.example.multipaneviews.HomeActivity.onCreate(HomeActivity.java:45)
03-26 16:09:42.195: E/AndroidRuntime(24156):    at android.app.Activity.performCreate(Activity.java:4465)
03-26 16:09:42.195: E/AndroidRuntime(24156):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-26 16:09:42.195: E/AndroidRuntime(24156):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-26 16:09:42.195: E/AndroidRuntime(24156):    ... 12 more
03-26 16:09:42.195: E/AndroidRuntime(24156): Caused by: java.lang.IllegalStateException: Fragment com.example.multipaneviews.HomeSideFragment did not create a view.
03-26 16:09:42.195: E/AndroidRuntime(24156):    at android.app.Activity.onCreateView(Activity.java:4266)
03-26 16:09:42.195: E/AndroidRuntime(24156):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)

0 个答案:

没有答案