gpt4 book ai didi

java - 膨胀 ListView 二进制 XML 行 0 时出错#

转载 作者:行者123 更新时间:2023-12-02 11:41:35 25 4
gpt4 key购买 nike

01-29 21:55:22.330 30653-30653/com.example.mickeyt.onyxbrowser E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mickeyt.onyxbrowser, PID: 30653
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mickeyt.onyxbrowser/com.example.mickeyt.onyxbrowser.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.widget.ListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1504)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.widget.ListView
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.widget.ListView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.mickeyt.onyxbrowser.MainActivity.onCreate(MainActivity.java:55)
at android.app.Activity.performCreate(Activity.java:6757)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1504)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: android.content.res.Resources$NotFoundException: Can't find ColorStateList from drawable resource ID #0x7f070059
at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:980)
at android.content.res.Resources.loadColorStateList(Resources.java:1007)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:531)
at android.view.View.<init>(View.java:4501)
at android.view.ViewGroup.<init>(ViewGroup.java:578)
at android.widget.AdapterView.<init>(AdapterView.java:246)
at android.widget.AbsListView.<init>(AbsListView.java:842)
01-29 21:55:22.330 30653-30653/com.example.mickeyt.onyxbrowser E/AndroidRuntime: at android.widget.ListView.<init>(ListView.java:163)
at android.widget.ListView.<init>(ListView.java:159)
at android.widget.ListView.<init>(ListView.java:155)
... 30 more

XML 文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_history_layout"
android:layout_width="275dp"
android:layout_height="500dp"
android:elevation="10dp"
android:layout_margin="10dp"
android:layout_gravity="center_horizontal|center"
android:background="@drawable/history_layout">

<android.support.constraint.ConstraintLayout
android:id="@+id/b_Toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/history_toolbar"
app:layout_constraintBottom_toTopOf="@+id/b_HistoryList"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView"
android:layout_width="79dp"
android:layout_height="wrap_content"
android:text="History"
android:textColor="#000"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imageButton2"
app:layout_constraintStart_toEndOf="@+id/b_HistoryClose"
app:layout_constraintTop_toTopOf="parent" />

<ImageButton
android:id="@+id/b_HistoryClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="66dp"
android:layout_marginStart="8dp"
android:background="@android:color/transparent"
android:onClick="onHistoryClose"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/close" />

<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="66dp"
android:background="@android:color/transparent"
android:onClick="onHistoryDelete"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/delete" />


</android.support.constraint.ConstraintLayout>

<ListView
android:id="@+id/b_HistoryList"
android:layout_width="275dp"
android:layout_height="443dp"
android:backgroundTint="@drawable/history_listview"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/b_Toolbar"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>

MainActivity.java

UrlHistoryAdapter adapter = new UrlHistoryAdapter(this);
b_HistoryList.setAdapter(adapter);
url = w_SearchBar.getText().toString();

/*
Webview
*/
m_WebView.setWebViewClient(new WebViewClient(){

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
UrlHistoryAdapter.add(url);
UrlHistoryAdapter.notifyDataSetChanged();
return super.shouldOverrideUrlLoading(view, request);

}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);

}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});

我不知道该怎么解决这个问题,它是在我向 ListView 添加 CustomArrayAdapter 和 ArrayList 以填充它之后开始的。我的成功率为零,如果没有填充 ListView,该功能就毫无用处。我想知道这是否与 XML 文件或 Java 文件有关。除了对于 CustomArrayAdapter 来说相当基本的文件之外,适配器没有太多内容。它的所有用途就是输入一个字符串并将其显示到 ListView 。

我四处寻找答案并发现了一些类似的问题,但有些方法不起作用,我不得不发布我自己的问题。

最佳答案

这是因为ListView中的android:backgroundTint="@drawable/history_listview"ListView

没有附加背景

android:backgroundTint applies the color filter to the resource of android:background when used together with android:backgroundTintMode.

尝试设置背景,然后对其应用滤色器。

关于java - 膨胀 ListView 二进制 XML 行 0 时出错#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48513406/

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