如何解决android.view.InflateException

DEFSKIDROW

我已经做了一些尝试来纠正错误。由于我不了解它,因此我没有其他解决方法。

这是我的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/bgLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:layout_marginEnd="20dp"
            android:layout_marginBottom="20dp"
            android:clickable="true"
            app:backgroundTint="@color/black"
            app:srcCompat="@drawable/ic_coins2" />

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

            <!--<include layout="@layout/toolbar" />-->

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/SwipeRefreshLayout">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/bg_black"
                android:scrollbars="vertical" />

        </android.support.v4.widget.SwipeRefreshLayout>

    </RelativeLayout>

    <!--bottom sheet container-->
    <FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/bottom_sheet_behavior" />

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

这是我的代码

public class BottomSheetBasic extends AppCompatActivity {
    private BottomSheetBehavior mBehavior;
    private BottomSheetDialog mBottomSheetDialog;
    private View bottom_sheet;
    private RecyclerView recyclerView;
    private GridLayoutManager gridLayoutManager;
    private CustomAdapter adapter;
    private List<MyData> data_list;
    private SwipeRefreshLayout mSwipeRefreshLayout;
    ProgressDialog dialog;
    String currentUid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_sheet_basic);
        bottom_sheet = findViewById(R.id.bottom_sheet);
        mBehavior = BottomSheetBehavior.from(bottom_sheet);
        //showBottomSheetDialog();
        dialog = new ProgressDialog(this);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showBottomSheetDialog();
            }
        });

        //BackButton
        if(getSupportActionBar()!=null){
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }

        sum_gold_auszahlen sum_gold = new sum_gold_auszahlen(BottomSheetBasic.this);
        sum_gold.execute();

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.SwipeRefreshLayout);

        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                load_data_from_server(0);
                mSwipeRefreshLayout.setRefreshing(false);
            }
        });



        FirebaseUser user  = FirebaseAuth.getInstance().getCurrentUser();
        currentUid = user.getUid();

        recyclerView = (RecyclerView) findViewById(R.id.recycler_view2);
        data_list  = new ArrayList<>();
        load_data_from_server(0);

        gridLayoutManager = new GridLayoutManager(this,1);
        recyclerView.setLayoutManager(gridLayoutManager);

        adapter = new CustomAdapter(this,data_list);
        recyclerView.setAdapter(adapter);

        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

                if(gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size()-1){
                    load_data_from_server(data_list.size()-1);
                }
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        } else {
            Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
        }
        return super.onOptionsItemSelected(item);
    }


    private void showBottomSheetDialog() {
        SharedPreferences sharedPrefs = getSharedPreferences("preferences", 0);
        Float gold = sharedPrefs.getFloat("gold2",0f);
        String next_payout = sharedPrefs.getString("next_payout","");
        final String playername =sharedPrefs.getString("nickname","");

        if (mBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
            mBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        }

        final View view = getLayoutInflater().inflate(R.layout.sheet_auszahlung, null);
        //((TextView) view.findViewById(R.id.tv_gold)).setText("aa");
        //sum_gold_auszahlen sum_gold_auszahlen = new sum_gold_auszahlen();
        //sum_gold_auszahlen.execute();
        final RadioButton rb_1000 = (RadioButton) view.findViewById(R.id.rb_1000);
        final RadioButton rb_2500 = (RadioButton) view.findViewById(R.id.rb_2500);
        final RadioButton rb_5500 = (RadioButton) view.findViewById(R.id.rb_5500);
        final TextView tv_gold = (TextView) view.findViewById(R.id.tv_gold);
        final TextView tv_next_payout = (TextView) view.findViewById(R.id.tv_next_payout);

        tv_gold.setText(gold.toString());
        tv_next_payout.setText(next_payout);
        (view.findViewById(R.id.bt_close)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mBottomSheetDialog.dismiss();
            }
        });

        (view.findViewById(R.id.btn_payment)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Float val = Float.parseFloat( tv_gold.getText().toString() );

                if (rb_1000.isChecked()) {
                    if (val >= 1000) {
                        Auszahlung backgroundTask = new Auszahlung(BottomSheetBasic.this);
                        backgroundTask.execute("loot", playername, "1000");
                        val = val -1000f;
                        String s = String.format(Locale.US, "%.2f",val);
                        tv_gold.setText(s);
                    } else {
                        Toast toast = Toast.makeText(BottomSheetBasic.this,getString(R.string.not_enough_gold),Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                    }
                } else if (rb_2500.isChecked()) {
                    if (val >= 2400) {
                        Auszahlung backgroundTask = new Auszahlung(BottomSheetBasic.this);
                        backgroundTask.execute("loot", playername, "2400");
                        val = val -2400f;
                        String s = String.format(Locale.US, "%.2f",val);
                        tv_gold.setText(s);
                    } else {
                        Toast toast = Toast.makeText(BottomSheetBasic.this,getString(R.string.not_enough_gold),Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                    }
                } else if (rb_5500.isChecked()) {
                    if (val >= 5200) {
                        Auszahlung backgroundTask = new Auszahlung(BottomSheetBasic.this);
                        backgroundTask.execute("loot", playername, "5200");
                        val = val -5200f;
                        String s = String.format(Locale.US, "%.2f",val);
                        tv_gold.setText(s);
                    } else {
                        Toast toast = Toast.makeText(BottomSheetBasic.this,getString(R.string.not_enough_gold),Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                    }
                }
            }
        });

        mBottomSheetDialog = new BottomSheetDialog(this);
        mBottomSheetDialog.setContentView(view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Objects.requireNonNull(mBottomSheetDialog.getWindow()).addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        mBottomSheetDialog.show();
        mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                mBottomSheetDialog = null;
            }
        });
    }

这是我的LogCat

这就是Google控制台给我的。不幸的是我没有更多。我也没有设法模仿这个错误

android.view.InflateException: 
  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 de.bluestarfish.wotgold_digger.activity.BottomSheetBasic.showBottomSheetDialog (BottomSheetBasic.java:144)
  at de.bluestarfish.wotgold_digger.activity.BottomSheetBasic.access$000 (BottomSheetBasic.java:49)
  at de.bluestarfish.wotgold_digger.activity.BottomSheetBasic$1.onClick (BottomSheetBasic.java:74)
  at android.view.View.performClick (View.java:5265)
  at android.view.View$PerformClick.run (View.java:21534)
  at android.os.Handler.handleCallback (Handler.java:815)
  at android.os.Handler.dispatchMessage (Handler.java:104)
  at android.os.Looper.loop (Looper.java:207)
  at android.app.ActivityThread.main (ActivityThread.java:5728)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:789)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679)
Caused by: android.view.InflateException: 
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:782)
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:835)
  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:838)
  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:515)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.Resources.loadDrawableForCookie (Resources.java:2834)
  at android.content.res.Resources.loadDrawable (Resources.java:2756)
  at android.content.res.TypedArray.getDrawable (TypedArray.java:870)
  at android.view.View.<init> (View.java:4001)
  at android.widget.TextView.<init> (TextView.java:700)
  at android.widget.Button.<init> (Button.java:109)
  at android.widget.Button.<init> (Button.java:105)
  at android.support.v7.widget.AppCompatButton.<init> (AppCompatButton.java:71)
  at android.support.v7.widget.AppCompatButton.<init> (AppCompatButton.java:67)
  at android.support.v7.app.AppCompatViewInflater.createButton (AppCompatViewInflater.java:187)
  at android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:110)
  at android.support.v7.app.AppCompatDelegateImpl.createView (AppCompatDelegateImpl.java:1266)
  at android.support.v7.app.AppCompatDelegateImpl.onCreateView (AppCompatDelegateImpl.java:1316)
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:746)

我不能给你更多细节。

我是

这看起来像stacktrace的重要部分:

Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.Resources.loadDrawableForCookie (Resources.java:2834)
  at android.content.res.Resources.loadDrawable (Resources.java:2756)
  ...
  at android.support.v7.widget.AppCompatButton.<init> (AppCompatButton.java:67)
  at android.support.v7.app.AppCompatViewInflater.createButton (AppCompatViewInflater.java:187)

这对我说的是,您在<Button>某处使用了无法找到的可绘制对象标签。通常,如果您使用的android:drawableLeft属性是带有<vector>资源的drawable,则通常会发生这种情况

我没有<Button>在发布的XML中看到任何标签(FloatingActionButton是ImageView / ImageButton的子类,而不是Button的子类),这意味着它可能是sheet_auszahlung.xml布局文件中的标签

至于如何解决...

如果您使用androidx,则该androidx.appcompat 1.1.0-alpha01发行版包含对app:drawableLeftCompat矢量可绘制对象“正常工作”属性的支持

如果您没有使用androidx,那么您将不得不使用Java创建Drawable对象并将其手动设置为视图:

Drawable d = AppCompatResources.getDrawable(context, R.drawable.whatever_you_need);
button.setCompoundDrawables(d, null, null, null);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我该如何解决此错误?android.view.InflateException:二进制XML文件行#300

我该如何解决这个错误?android.view.InflateException:二进制 XML 文件第 11 行

android.view.InflateException错误

android.view.InflateException 扩展 AppCompatSpinner 时

android.view.InflateException:总是错误

MainActivity上的android.view.InflateException错误

引起:android.view.InflateException:在 NavigationView

某些设备的 android.view.InflateException(主要是 Android 4.4)

具有Android Studio android.view.InflateException的Roboelectric 3.0

使用selectableItemBackground时出现android.view.InflateException

android.view.InflateException,通过Fabric插件整数

android.view.InflateException:编写自定义imageView时

某些设备上的“致命异常:android.view.InflateException”

java.lang.RuntimeException: android.view.InflateException

java.lang.RuntimeException,Caused by: android.view.InflateException

android.view.InflateException 切换到横向模式时

包含布局时,如何解决inflateException问题?

如何处理android.view.inflateexception二进制XML文件第5行

如何解决Android中已弃用的View方法?

Android KitKat:android.view.InflateException:错误膨胀类android.support.design.widget.NavigationView

android.view.InflateException:错误夸大类android.widget.EditText华硕Android 5

android.view.InflateException错误充气类android.webkit.WebView

android.view.InflateException:膨胀类android.support.v7.widget.CardView时出错

Android自定义视图-java.lang.RuntimeException android.view.InflateException

android.view.InflateException: Binary XML file line #49: Error inflating class android.widget.ImageView

Android InflateException FloatingActionButton

Android-片段:InflateException

android.view.InflateException:二进制 XML 文件行(不存在)

android.view.inflateexception 二进制 xml 文件行 #306:错误膨胀类指南