KeenLearner KeenLearner - 2 months ago 16
Android Question

Solving Binary XML file line #3: Error inflating class <unknown>

This error occured when i updated android studio, i've spent several hours trying to figure out the fix for it but have had no success. The code is to show an activity that lets the user create a note that they can place in their text and then save it for viewing later on.

DisplayNote

public class DisplayNote extends AppCompatActivity {
private NoteDataBase mydb;
EditText name;
EditText content;
private CoordinatorLayout coordinatorLayout;
String dateString;
int id_To_Update = 0;
Snackbar snackbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewnotepad);
name = (EditText) findViewById(R.id.txtname);
content = (EditText) findViewById(R.id.txtcontent);

coordinatorLayout = (CoordinatorLayout) findViewById(R.id
.coordinatorLayout);
mydb = new NoteDataBase(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
Bundle extras = getIntent().getExtras();
if (extras != null) {
int Value = extras.getInt("id");
if (Value > 0) {
snackbar = Snackbar
.make(coordinatorLayout, "Note Id : " + String.valueOf(Value), Snackbar.LENGTH_LONG);
snackbar.show();
Cursor rs = mydb.getData(Value);
id_To_Update = Value;
rs.moveToFirst();
String nam = rs.getString(rs.getColumnIndex(NoteDataBase.name));
String contents = rs.getString(rs.getColumnIndex(NoteDataBase.remark));
if (!rs.isClosed()) {
rs.close();
}
name.setText((CharSequence) nam);
content.setText((CharSequence) contents);
}
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.display_menu, menu);
return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.Save:
Bundle extras = getIntent().getExtras();
Calendar c = Calendar.getInstance();
System.out.println("Current time => " + c.getTime());
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String formattedDate = df.format(c.getTime());
dateString = formattedDate;
if (extras != null) {
int Value = extras.getInt("id");
if (Value > 0) {
if (content.getText().toString().trim().equals("")
|| name.getText().toString().trim().equals("")) {
snackbar = Snackbar
.make(coordinatorLayout, "Please fill in name of the note", Snackbar.LENGTH_LONG);
snackbar.show();
} else {
if (mydb.updateNotes(id_To_Update, name.getText()
.toString(), dateString, content.getText()
.toString())) {
snackbar = Snackbar
.make(coordinatorLayout, "Note updated!", Snackbar.LENGTH_LONG);
snackbar.show();
} else {
snackbar = Snackbar
.make(coordinatorLayout, "Error occurred when updating", Snackbar.LENGTH_LONG);
snackbar.show();
}
}
} else {
if (content.getText().toString().trim().equals("")
|| name.getText().toString().trim().equals("")) {
snackbar = Snackbar
.make(coordinatorLayout, "Please fill in content of the note", Snackbar.LENGTH_LONG);
snackbar.show();
} else {
if (mydb.insertNotes(name.getText().toString(), dateString,
content.getText().toString())) {
snackbar = Snackbar
.make(coordinatorLayout, "Note successfully added", Snackbar.LENGTH_LONG);
snackbar.show();
} else {
snackbar = Snackbar
.make(coordinatorLayout, "Error occurred when saving note", Snackbar.LENGTH_LONG);
snackbar.show();
}
}
}
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}


}

Viewnotepad.xml

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

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:weightSum="2" >

<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="top|center"
android:text="NAME" />

<EditText
android:id="@+id/txtname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="top|center"
android:inputType="textAutoCorrect"
android:hint="Name of note here"
android:layout_weight="1.5"
>
</EditText>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:orientation="vertical"
android:weightSum="2" >

<EditText
android:id="@+id/txtcontent"
android:hint="Your text here"
android:gravity="top|start"
android:layout_width="match_parent"
android:layout_height="0dp"
android:inputType="textMultiLine">
</EditText>
</LinearLayout>

</LinearLayout>
</android.support.design.widget.CoordinatorLayout>


Error Log

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shakeel.appidea2/com.example.shakeel.appidea2.diary.DisplayNote}: android.view.InflateException: Binary XML file line #3: Binary XML file line #3: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
at android.app.ActivityThread.access$900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: android.view.InflateException: Binary XML file line #3: Binary XML file line #3: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.example.shakeel.appidea2.diary.DisplayNote.onCreate(DisplayNote.java:34)
at android.app.Activity.performCreate(Activity.java:6272)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5551) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
at com.example.shakeel.appidea2.diary.DisplayNote.onCreate(DisplayNote.java:34) 
at android.app.Activity.performCreate(Activity.java:6272) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5551) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
at com.example.shakeel.appidea2.diary.DisplayNote.onCreate(DisplayNote.java:34) 
at android.app.Activity.performCreate(Activity.java:6272) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5551) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:182)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:176)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
at com.example.shakeel.appidea2.diary.DisplayNote.onCreate(DisplayNote.java:34) 
at android.app.Activity.performCreate(Activity.java:6272) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
at android.app.ActivityThread.access$900(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5551) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 

Answer
Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.

You are using AppCompatActivity and CoordinatorLayout, but the theme for your activity (android:theme on the <activity> in the manifest) does not inherit from Theme.AppCompat.