What does: "Binary XML file line #47: Binary XML file line #47: Error inflating class EditText" mean?

huangapple 未分类评论51阅读模式
英文:

What does: "Binary XML file line #47: Binary XML file line #47: Error inflating class EditText" mean?

问题

I have seen multiple questions like this on this forum, but nothing I found helped me.

So what's basically happening is that I have an App, which works perfectly fine on my device.
I wrote that app for my mother, who has an older phone (Samsung S5neo - Android 6.0.1(API 23)) and for some reason it doesn't work on there.

It shows this error message in the LogCat:

04-10 13:32:51.376 18800-18800/com.gevi.berstunden E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.gevi.berstunden, PID: 18800
    android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class EditText
        ...
     Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class EditText
        ...
     Caused by: android.content.res.Resources$NotFoundException: Resource "com.gevi.berstunden:drawable/popupedittext_round" (7f070081) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070081 a=-1 r=0x7f070081}
        ...

On YouTube I found people saying I should add a dependency to my build.gradle (implementation 'com.android.support:design:28.0.0'), but this didn't help either. I also tried using older versions of this.

My main code is:

package com.gevi.berstunden;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import ...
...

and the corresponding XML file is:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    android:background="@color/colorPrimary">

   <TextView
       android:layout_width="match_parent"
       ...
       android:gravity="center"/>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        ...
        tools:listitem="@layout/row"/>

    <TextView
        android:layout_width="wrap_content"
        ...
        android:textColor="@color/near_white"
        android:textSize="30dip"
        android:background="@drawable/textview_round"
        android:padding="5dip"/>

</LinearLayout>

However, I followed the error log of the LogCat, pinpointing the issue to the Dialogs XML file:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    android:background="@color/colorPrimary">

    <TextView
        android:layout_width="wrap_content"
        ...
        android:background="@drawable/popuptextview_round"
        android:padding="5dip"
        android:layout_marginBottom="15dip"/>

    <TextView
        android:layout_width="wrap_content"
        ...
        android:background="@drawable/popuptextview_round"
        android:padding="5dip"
        android:layout_marginBottom="15dip"/>

    <TextView
        android:layout_width="wrap_content"
        ...
        android:background="@drawable/popuptextview_round"
        android:padding="5dip"
        android:layout_marginBottom="15dip"/>

    <EditText
        android:layout_width="wrap_content"
        ...
        android:background="@drawable/popupedittext_round"
        android:padding="5dip"
        android:layout_marginBottom="20dip"/>

    <TextView
        android:layout_width="wrap_content"
        ...
        android:background="@drawable/popuptextview_round"
        android:padding="5dip"/>

</LinearLayout>

(Note: The code you provided contains XML layout references and Java code which I've presented here. If you need any specific explanations or further assistance, feel free to ask.)

英文:

I have seen multiple questions like this on this forum, but nothing I found helped me.

So what's basically happening is that I have an App, which works perfectly fine on my device.
I wrote that app for my mother, who has an older phone (Samsung S5neo - Android 6.0.1(API 23)) and for some reason it doesn't work on there.

It show's this error message in the LogCat:

    Process: com.gevi.berstunden, PID: 18800
    android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class EditText
        at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)
        at android.app.Dialog.setContentView(Dialog.java:837)
        at com.gevi.berstunden.MainActivity.onAddHourClick(MainActivity.java:81)
        at com.gevi.berstunden.MainActivity.lambda$initViews$0$MainActivity(MainActivity.java:64)
        at com.gevi.berstunden.-$$Lambda$MainActivity$Koi270rAtPv4jlW335vCcd1sR2Y.onClick(lambda)
        at android.view.View.performClick(View.java:5698)
        at android.widget.TextView.performClick(TextView.java:10846)
        at android.view.View$PerformClick.run(View.java:22565)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7230)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
     Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class EditText
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:429)&#160;
        at android.view.LayoutInflater.inflate(LayoutInflater.java:380)&#160;
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)&#160;
        at android.app.Dialog.setContentView(Dialog.java:837)&#160;
        at com.gevi.berstunden.MainActivity.onAddHourClick(MainActivity.java:81)&#160;
        at com.gevi.berstunden.MainActivity.lambda$initViews$0$MainActivity(MainActivity.java:64)&#160;
        at com.gevi.berstunden.-$$Lambda$MainActivity$Koi270rAtPv4jlW335vCcd1sR2Y.onClick(lambda)&#160;
        at android.view.View.performClick(View.java:5698)&#160;
        at android.widget.TextView.performClick(TextView.java:10846)&#160;
        at android.view.View$PerformClick.run(View.java:22565)&#160;
        at android.os.Handler.handleCallback(Handler.java:739)&#160;
        at android.os.Handler.dispatchMessage(Handler.java:95)&#160;
        at android.os.Looper.loop(Looper.java:158)&#160;
        at android.app.ActivityThread.main(ActivityThread.java:7230)&#160;
        at java.lang.reflect.Method.invoke(Native Method)&#160;
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)&#160;
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)&#160;
     Caused by: android.content.res.Resources$NotFoundException: Resource &quot;com.gevi.berstunden:drawable/popupedittext_round&quot; (7f070081) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070081 a=-1 r=0x7f070081}
        at android.content.res.Resources.loadDrawableForCookie(Resources.java:4178)
        at android.content.res.Resources.loadDrawable(Resources.java:4085)
        at android.content.res.Resources.loadDrawable(Resources.java:3935)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:886)
        at android.view.View.&lt;init&gt;(View.java:4226)
        at android.widget.TextView.&lt;init&gt;(TextView.java:948)
        at android.widget.EditText.&lt;init&gt;(EditText.java:90)
        at android.widget.EditText.&lt;init&gt;(EditText.java:86)
        at androidx.appcompat.widget.AppCompatEditText.&lt;init&gt;(AppCompatEditText.java:73)
        at androidx.appcompat.widget.AppCompatEditText.&lt;init&gt;(AppCompatEditText.java:69)
        at androidx.appcompat.app.AppCompatViewInflater.createEditText(AppCompatViewInflater.java:197)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:115)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:758)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)&#160;
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)&#160;
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)&#160;
        at android.view.LayoutInflater.inflate(LayoutInflater.java:527)&#160;
        at android.view.LayoutInflater.inflate(LayoutInflater.java:429)&#160;
        at android.view.LayoutInflater.inflate(LayoutInflater.java:380)&#160;
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:474)&#160;
        at android.app.Dialog.setContentView(Dialog.java:837)&#160;
        at com.gevi.berstunden.MainActivity.onAddHourClick(MainActivity.java:81)&#160;
        at com.gevi.berstunden.MainActivity.lambda$initViews$0$MainActivity(MainActivity.java:64)&#160;
        at com.gevi.berstunden.-$$Lambda$MainActivity$Koi270rAtPv4jlW335vCcd1sR2Y.onClick(lambda)&#160;
        at android.view.View.performClick(View.java:5698)&#160;
        at android.widget.TextView.performClick(TextView.java:10846)&#160;
        at android.view.View$PerformClick.run(View.java:22565)&#160;
        at android.os.Handler.handleCallback(Handler.java:739)&#160;
        at android.os.Handler.dispatchMessage(Handler.java:95)&#160;
        at android.os.Looper.loop(Looper.java:158)&#160;
        at android.app.ActivityThread.main(ActivityThread.java:7230)&#160;
        at java.lang.reflect.Method.invoke(Native Method)&#160;
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)&#160;
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

On YouTube I found people saying I should add a dependency to my buil.gradle (implementation 'com.android.support:design:28.0.0'), but this didn't help either. I also tried using older versions of this.

My main code is:

package com.gevi.berstunden;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends AppCompatActivity {

   Dialog dialog;
   Dialog dateDialog;
   Dialog fromTimeDialog;
   Dialog toTimeDialog;

   String date;
   String fromTime;
   String toTime;
   String reason;

   RecyclerView recyclerView;
   TextView textView;
   TextView totalHoursTextViews;
   RecyclerViewListManager manager;
   RecyclerViewListAdapter adapter;

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

       initManager();
       initViews();

   }

   protected void initManager() {
       manager = new RecyclerViewListManager(this);
       adapter = new RecyclerViewListAdapter(manager);
   }

   protected void initViews() {
       recyclerView = findViewById(R.id.RecyclerView);
       recyclerView.setLayoutManager(new LinearLayoutManager(this));
       recyclerView.setAdapter(adapter);
       adapter.setOnItemClickListener(new RecyclerViewListAdapter.onItemClickListener() {
           @Override
           public void onItemClick(int position) {

           }
       });
       ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new HourListTouchCallback(manager, recyclerView));
       itemTouchHelper.attachToRecyclerView(recyclerView);
       textView = findViewById(R.id.addTextView);
       textView.setOnClickListener(view -&gt; onAddHourClick());
       totalHoursTextViews = findViewById(R.id.totalHoursTextView);
       totalHoursTextViews.setText(String.valueOf(manager.getTotalHours()));
       dialog = new Dialog(this);
       dateDialog = new Dialog(this);
       fromTimeDialog = new Dialog(this);
       toTimeDialog = new Dialog(this);
   }

   protected void onAddHourClick() {

       TextView setDate;
       TextView setFromTime;
       TextView setToTime;
       EditText setReason;
       TextView close;

       dialog.setContentView(R.layout.popup);
       setDate = dialog.findViewById(R.id.setDateTextView);
       setDate.setOnClickListener(view -&gt; onSetDateClick());
       setFromTime = dialog.findViewById(R.id.setFromTimeTextView);
       setFromTime.setOnClickListener(view -&gt; onFromTimeClick());
       setToTime = dialog.findViewById(R.id.setToTimeTextView);
       setToTime.setOnClickListener(view -&gt; onToTimeClick());
       setReason = dialog.findViewById(R.id.reasonEditText);
       close = dialog.findViewById(R.id.enterTextView);
       close.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Hour hour = new Hour();
               hour.setDate(date);
               hour.setFromTime(fromTime);
               hour.setToTime(toTime);
               int hours = Integer.parseInt(toTime.substring(0,2)) - Integer.parseInt(fromTime.substring(0, 2));
               int minutes = Integer.parseInt(toTime.substring(3)) - Integer.parseInt(fromTime.substring(3));
               reason = setReason.getText().toString();
               hour.setReason(reason);
               hour.setHours(hours);
               hour.setMinutes(minutes);
               manager.addHour(hour);
               adapter.notifyItemInserted(manager.getHourCount() - 1);
               totalHoursTextViews.setText(String.valueOf(manager.getTotalHours()));
               dialog.dismiss();
           }
       });

       dialog.show();
   }

   protected void onSetDateClick() {

       DatePicker datePicker;
       TextView enter_date;

       dateDialog.setContentView(R.layout.date_popup);

       datePicker = dateDialog.findViewById(R.id.datepicker);
       enter_date = dateDialog.findViewById(R.id.enter_date);
       enter_date.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               date = String.valueOf(datePicker.getDayOfMonth()) + &quot;.&quot; + String.valueOf(datePicker.getMonth()) + &quot;.&quot; + String.valueOf(datePicker.getYear());
               dateDialog.dismiss();
           }
       });

       dateDialog.show();
   }

   protected void onFromTimeClick() {

       TimePicker timePicker;
       TextView enter_fromTime;

       fromTimeDialog.setContentView(R.layout.fromtime_popup);

       timePicker = fromTimeDialog.findViewById(R.id.fromTime_timepicker);
       timePicker.setIs24HourView(true);
       enter_fromTime = fromTimeDialog.findViewById(R.id.enter_fromTime);
       enter_fromTime.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               int hourlenght = String.valueOf(timePicker.getHour()).length();
               int minutelenght = String.valueOf(timePicker.getMinute()).length();

               if(hourlenght == 1) {
                   if(minutelenght == 1) {
                       fromTime = &quot;0&quot; + String.valueOf(timePicker.getHour()) + &quot;:0&quot; + String.valueOf(timePicker.getMinute());
                   }
                   if(minutelenght == 2) {
                       fromTime = &quot;0&quot; + String.valueOf(timePicker.getHour()) + &quot;:&quot; + String.valueOf(timePicker.getMinute());
                   }
               }
               if(hourlenght == 2) {
                   if(minutelenght == 1) {
                       fromTime = String.valueOf(timePicker.getHour()) + &quot;:0&quot; + String.valueOf(timePicker.getMinute());
                   }
                   if(minutelenght == 2) {
                       fromTime = String.valueOf(timePicker.getHour()) + &quot;:&quot; + String.valueOf(timePicker.getMinute());
                   }
               }

               fromTimeDialog.dismiss();
           }
       });

       fromTimeDialog.show();
   }

   protected void onToTimeClick() {

       TimePicker timePicker;
       TextView enter_toTime;

       toTimeDialog.setContentView(R.layout.totime_popup);

       timePicker = toTimeDialog.findViewById(R.id.toTime_timepicker);
       timePicker.setIs24HourView(true);
       enter_toTime = toTimeDialog.findViewById(R.id.enter_toTime);
       enter_toTime.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               int hourlenght = String.valueOf(timePicker.getHour()).length();
               int minutelenght = String.valueOf(timePicker.getMinute()).length();

               if(hourlenght == 1) {
                   if(minutelenght == 1) {
                       toTime = &quot;0&quot; + String.valueOf(timePicker.getHour()) + &quot;:0&quot; + String.valueOf(timePicker.getMinute());
                   }
                   if(minutelenght == 2) {
                       toTime = &quot;0&quot; + String.valueOf(timePicker.getHour()) + &quot;:&quot; + String.valueOf(timePicker.getMinute());
                   }
               }
               if(hourlenght == 2) {
                   if(minutelenght == 1) {
                       toTime = String.valueOf(timePicker.getHour()) + &quot;:0&quot; + String.valueOf(timePicker.getMinute());
                   }
                   if(minutelenght == 2) {
                       toTime = String.valueOf(timePicker.getHour()) + &quot;:&quot; + String.valueOf(timePicker.getMinute());
                   }
               }

               toTimeDialog.dismiss();
           }
       });

       toTimeDialog.show();
   }
}

and the corresponding xml file is the following:

&lt;LinearLayout
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:orientation=&quot;vertical&quot;
    android:weightSum=&quot;100&quot;
    tools:context=&quot;.MainActivity&quot;
    android:background=&quot;@color/colorPrimary&quot;&gt;

   &lt;TextView
       android:layout_width=&quot;match_parent&quot;
       android:layout_height=&quot;wrap_content&quot;
       android:padding=&quot;30dip&quot;
       android:text=&quot;@string/topTextView&quot;
       android:textSize=&quot;100px&quot;
       android:textColor=&quot;@color/text_color&quot;
       android:layout_gravity=&quot;center&quot;
       android:gravity=&quot;center&quot;/&gt;

    &lt;androidx.recyclerview.widget.RecyclerView
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;0dip&quot;
        android:layout_weight=&quot;100&quot;
        android:id=&quot;@+id/RecyclerView&quot;
        tools:listitem=&quot;@layout/row&quot;/&gt;

    &lt;TextView
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:id=&quot;@+id/totalHoursTextView&quot;
        android:text=&quot;Stunden: 23.5&quot;
        android:textSize=&quot;80px&quot;
        android:textColor=&quot;@color/text_color&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:layout_marginTop=&quot;20dip&quot;/&gt;

    &lt;TextView
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:id=&quot;@+id/addTextView&quot;
        android:layout_margin=&quot;20dip&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:text=&quot;@string/addHoursTextView&quot;
        android:textColor=&quot;@color/near_white&quot;
        android:textSize=&quot;30dip&quot;
        android:background=&quot;@drawable/textview_round&quot;
        android:padding=&quot;5dip&quot;/&gt;

&lt;/LinearLayout&gt;

however I followed the error log of the LogCat, pinpointing the issue to the Dialogs xml-file:

&lt;LinearLayout
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_gravity=&quot;center&quot;
    android:orientation=&quot;vertical&quot;
    android:padding=&quot;20dip&quot;
    android:background=&quot;@color/colorPrimary&quot;&gt;

    &lt;TextView
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;30dip&quot;
        android:id=&quot;@+id/setDateTextView&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:text=&quot;@string/setDate&quot;
        android:textColor=&quot;@color/near_white&quot;
        android:background=&quot;@drawable/popuptextview_round&quot;
        android:padding=&quot;5dip&quot;
        android:layout_marginBottom=&quot;15dip&quot;/&gt;

    &lt;TextView
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;30dip&quot;
        android:id=&quot;@+id/setFromTimeTextView&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:text=&quot;@string/setFromTime&quot;
        android:textColor=&quot;@color/near_white&quot;
        android:background=&quot;@drawable/popuptextview_round&quot;
        android:padding=&quot;5dip&quot;
        android:layout_marginBottom=&quot;15dip&quot;/&gt;

    &lt;TextView
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;30dip&quot;
        android:id=&quot;@+id/setToTimeTextView&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:text=&quot;@string/setToTime&quot;
        android:textColor=&quot;@color/near_white&quot;
        android:background=&quot;@drawable/popuptextview_round&quot;
        android:padding=&quot;5dip&quot;
        android:layout_marginBottom=&quot;15dip&quot;/&gt;

    &lt;EditText
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;30dip&quot;
        android:id=&quot;@+id/reasonEditText&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:hint=&quot;@string/addReasonEditTextHint&quot;
        android:textColorHint=&quot;@color/hint_color&quot;
        android:textColor=&quot;@color/text_color&quot;
        android:background=&quot;@drawable/popupedittext_round&quot;
        android:padding=&quot;5dip&quot;
        android:layout_marginBottom=&quot;20dip&quot;/&gt;

    &lt;TextView
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;30dip&quot;
        android:id=&quot;@+id/enterTextView&quot;
        android:layout_gravity=&quot;center&quot;
        android:gravity=&quot;center&quot;
        android:text=&quot;@string/popup_enter&quot;
        android:textColor=&quot;@color/near_white&quot;
        android:background=&quot;@drawable/popuptextview_round&quot;
        android:padding=&quot;5dip&quot;/&gt;

&lt;/LinearLayout&gt;

huangapple
  • 本文由 发表于 2020年4月10日 19:50:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/61139672.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定