java - App Crashes in two pane mode on launching -
actually iam making app displays popular movies ( popular movie app project of udacity course) , have 2 activites main activity , detail activity when tried make app run on tablet crashes , can't display main activity on launching app , dont know missing .... , want know how can specify app should run on different screen sizes tablets..
mainactivity.java
public class mainactivity extends appcompatactivity { private static final string detailfragment_tag ="dftag" ; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (findviewbyid(r.id.movie_detail_container) != null) { mtwopane = true; if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .replace(r.id.movie_detail_container, new moviedetailfragment(),detailfragment_tag) .commit(); log.v(log_tag, "crash "); } } else { mtwopane = false; }
moviedetail.java
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_movie_detail); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.movie_detail_container, new moviedetailfragment()) .commit(); } }
activity_main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment_movie" android:name=".moviesfragment" tools:context=".moviesfragment" tools:layout="@android:layout/list_content" android:layout_width="match_parent" android:layout_height="match_parent" />
sw600dp\activity_main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:baselinealigned="false" android:divider="?android:attr/dividerhorizontal" android:orientation="horizontal"> <fragment android:id="@+id/fragment_movie" android:name=".moviesfragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" /> <framelayout android:id="@+id/movie_detail_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="4" />
activity_movie_detail.xml
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/movie_detail_container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".moviedetail" tools:ignore="mergerootframe" />
logcat
java.lang.runtimeexception: unable start activity componentinfo{.popularmovies/.popularmovies.mainactivity}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2059)
i think not getting xml resource reference correctly. try add "movie_detail_container" in /mainactivity xml too. , try
Comments
Post a Comment