Actually iam making an app which displays popular movies ( popular movie app project of udacity course) and i have two activites main activity and detail activity but when i tried to make my app run on a tablet it crashes and can't display even the main activity on launching the app and i dont know what is missing .... Also , i want to know how can i specify that my app should run on different screen sizes for 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 to start activity ComponentInfo{.popularmovies/.popularmovies.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)