4

---->> java.lang.RuntimeException: Unable to start activity ComponentInfo{sharedpreferenceex.app.htc.com.listview_lv/sharedpreferenceex.app.htc.com.listview_lv.MyGrid}: android.view.InflateException: Binary XML file line #44: Error inflating class com.android.internal.widget.ActionBarContextView

---->>Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class com.android.internal.widget.ActionBarContextView

---->>Caused by: java.lang.reflect.InvocationTargetException

---->>Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13

I am facing with the above three exceptions.I am just trying to run a app to display a text view in an activity.These exceptions arrives in onCreate method of the activity itself.

I have also looked into all the stackoverflow anwers but could not figure out the problem.

My Manifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".MyGrid"
        android:label="@string/title_activity_my_grid" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

activity xml

 <LinearLayout 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" >


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:textSize="25dp"
    android:id="@+id/tv_example" />

Activity code

public class MyGrid extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_grid);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_my_grid, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

Sathish
  • 459
  • 6
  • 12

2 Answers2

3

I figured it out. The mobile device which I was using did not support the theme I used in the program (Styles.xml). Change the theme based on the device. Setting the wrong theme in styles.xml is the reason for those exceptions.

Sathish
  • 459
  • 6
  • 12
3

For me, this was triggered by switching to AndroidX and turning of jetifier. The solution: change Theme.AppCompat in the app theme with Theme.MaterialComponents.

Cristan
  • 12,083
  • 7
  • 65
  • 69