gpt4 book ai didi

android - 如何解决android.view.InflateException

转载 作者:行者123 更新时间:2023-11-29 23:22:15 25 4
gpt4 key购买 nike

我已经做了一些尝试来修复这个错误。由于我不明白,所以我没有其他解决方法。

这是我的 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)

我不能给你更多的细节。

最佳答案

这看起来像是堆栈跟踪的重要部分:

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>资源。

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

至于如何修复...

如果您使用 androidx , androidx.appcompat 1.1.0-alpha01版本包括对 app:drawableLeftCompat 等属性的支持与矢量可绘制对象“正常工作”。

如果你没有使用 androidx , 那么你将不得不使用 Java 创建一个 Drawable对象并手动将其设置为 View :

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

关于android - 如何解决android.view.InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54111008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com