Click here to Skip to main content
16,018,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm in the MainActivityFragment and want to call the activity "CountdownActivity" by pressing a button. This works.
But the try and catch returns the following exception while trying to setContentView(R.layout.activity_countdown); :
Java
android.view.InflateException: Binary XML file line #2: Error inflating class fragment

Bellow you find my code, I think this is all whats necessary.


The new Fragment get called this way:
Java
public void Countdown(Integer time){
        Intent CountdownIntent = new Intent(getActivity(),CountdownActivity.class);
        CountdownIntent.putExtra(Intent.EXTRA_TEXT, time);
        startActivity(CountdownIntent);
    }


activity_countdown.xml
XML
<?xml version="1.0" encoding="utf-8"?>
<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment_countdown"
    android:name="com.test.app.count.CountdownActivityFragment"
    tools:layout="@layout/fragment_countdown"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


fragment_countdown.xml
HTML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.test.app.count.CountdownActivityFragment">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Countdown"
        android:id="@+id/TextView_showCountdownTime"/>

</FrameLayout>


CountdownActivity.class
Java
public class CountdownActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            setContentView(R.layout.activity_countdown);
        }
        catch (Exception e){
            Log.e(CountdownActivity.class.getName(), "Exception: " + e);
        }
    }
}


What I have tried:

I get no error when I delete the part with fragment in activity_countdown.xml and e.g. use a RelativeLayout. But it's not what I want
Posted
Updated 6-Apr-16 13:07pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900