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);
}
});
我不知道该怎么办这个问题,它是在我将ListArrayAdapter和一个ArrayList添加到我的ListView以填充它之后开始的。我没有成功,没有填充ListView功能是没用的。我想知道它是否与XML文件或Java文件有关。除了CustomArrayAdapter相当基本的文件之外,适配器并不多。它用于输入一个字符串并将其显示在列表视图中。
我四处寻找答案,发现了一些类似的问题,但是方法没有奏效,我不得不发表自己的问题。 ë
答案 0 :(得分:1)
这是因为 android:backgroundTint="@drawable/history_listview"
中的ListView
。 ListView
android:backgroundTint
将颜色过滤器应用于资源android:background
与...一起使用时android:backgroundTintMode.
尝试设置背景,然后对其应用滤色镜。