What does this error mean? Binary XML file line # 8: Error inflating class

I can not find a normal explanation anywhere

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFF" android:orientation="vertical"> <com.example.android.threepointscircle.DrawActivity.DrawView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/drawView"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:id="@+id/backButton" android:text="back" /> </RelativeLayout> 

Above - markup

Here is the beginning of the class. Error occurs when connecting the listener

 public class DrawActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.draw_activity); Button backButton = (Button) findViewById(R.id.backButton); backButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { /** Интент для перехода на отрисовку результатов просчета*/ Intent drawActivity = new Intent(DrawActivity.this, MainActivity.class); startActivity(drawActivity); } }); } } 
  • You have some kind of error in the markup apparently. Show this markup - YuriySPb
  • I suspect that some forbidden character is present. - iluxa1810
  • And there may also be a wrong or incomplete class. Or liba not connected - YuriySPb
  • Added markup - Velsevool
  • I’m not sure, it’s not possible to use slashes in attributes. Instead, there are special characters ... - iluxa1810

2 answers 2

If you want to indicate in the markup a widget of a class that is someone's inner class, then you need to separate the classes with $ instead of a dot

Those. in your case, the record should be

 <com.example.android.threepointscircle.DrawActivity$DrawView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/drawView"/> 

Or try this:

 <view class="com.example.android.threepointscircle.DrawActivity$DrawView" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/drawView"/> 
  • If I do this, then the IDE swears that the start tag is not closed. (Tag start is not closed) - Velsevool
  • @Velsevool, updated the answer - YuriySPb
  • If I use the second option, I get the error Binary XML file line # 8: Error inflating class com.example.android.threepointscircle.DrawActivity $ DrawView - Velsevool
  • @Velsevool, try to put it into a separate file and try both ways. If all one falls, then the problem may be in the class itself. - Yuriy SPb
  • thank. I'll try, I will unsubscribe from the result. But I have to note that the error pops up when I try to connect the listener for the button. Without it, everything works OK. Link to my first question - Stackoverflow.com/questions/564426/… - Velsevool

Probably this button is stored in a separate layout, if that is the case, then you need to get a View using LayoutInflater. After that, in this View, look for the id button and assign it a listner.

 Button backButton = (Button) myltInflater.inflate(R.layout.other_layout, null, false).findViewById(R.id.btn); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // }}); 

Further work with this View