膨胀类 android.support.v7.app.AlertController.RecycleListView 时出错
Posted
技术标签:
【中文标题】膨胀类 android.support.v7.app.AlertController.RecycleListView 时出错【英文标题】:Error inflating class android.support.v7.app.AlertController.RecycleListView 【发布时间】:2017-07-06 03:26:44 【问题描述】:我的应用程序无法启动它在我安装后立即崩溃,我无法理解错误!
我为两个片段创建了两个recylcerView,它们附加在主活动xml文件中
错误:
E/androidRuntime: FATAL EXCEPTION: main
Process: com.invincible.fragfrag, PID: 14384
java.lang.RuntimeException: Unable to start activity ComponentInfocom.invincible.fragfrag/com.invincible.fragfrag.MainActivity: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.support.v7.app.AlertController.RecycleListView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path: DexPathList[[zip file "/data/app/com.invincible.fragfrag-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:571)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
at com.invincible.fragfrag.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AlertController.RecycleListView" on path:
主活动:
package com.invincible.fragfrag;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager.findFragmentById(R.id.table_number_list) == null)
TableNumber tableNumber=TableNumber.getTableNumber("number");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_number_list,tableNumber);
transaction.commit();
if (fragmentManager.findFragmentById(R.id.table_values) == null)
TableValue tableValue=TableValue.getTableValue("value");
FragmentTransaction transaction =fragmentManager.beginTransaction();
transaction.add(R.id.table_values,tableValue);
transaction.commit();
@Override
protected void onSaveInstanceState(Bundle outState)
super.onSaveInstanceState(outState);
主xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_
android:layout_
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.invincible.fragfrag.MainActivity">
<android.support.v7.app.AlertController.RecycleListView
android:id="@+id/recycler_view_one"
android:layout_weight="1"
android:layout_
android:layout_>
</android.support.v7.app.AlertController.RecycleListView>
<android.support.v7.app.AlertController.RecycleListView
android:layout_marginTop="5dp"
android:id="@+id/recycler_view_two"
android:layout_weight="1"
android:layout_
android:layout_>
</android.support.v7.app.AlertController.RecycleListView>
</LinearLayout>
请帮我找出错误是什么以及如何在一个活动中处理两个带有两个 recyclerview 的片段。
感谢您的关心!
【问题讨论】:
这是android.support.v7.app.AlertController.RecycleListView
的错误,你的意思是android.support.v7.widget.RecyclerView
你可以在上面看到我的错误日志
但您没有使用RecylerView
,请尝试将您的android.support.v7.app.AlertController.RecycleListView
替换为android.support.v7.widget.RecyclerView
【参考方案1】:
android.support.v7.widget.RecyclerView
在您的 xml 文件中使用此代码来创建列表视图。简单!
【讨论】:
【参考方案2】:您可能想使用android.support.v7.widget.RecyclerView
。
您不需要需要知道的其他信息
RecycleListView
是android.support.v7.app.AlertController
的嵌套类。人们会将其称为android.support.v7.app.AlertController$RecycleListView
(美元符号)。这就是它在此时崩溃的原因。
RecycleListView
扩展 ListView
不是 RecyclerView
。这就是为什么当您尝试在 Java 中使用它时,它会与 ClassCastException
一起崩溃。
RecycleListView
是 appcompat-v7 的内部类,不能在您的项目中使用。
【讨论】:
【参考方案3】:我犯了同样的错误。尝试替换
android.support.v7.app.AlertController.RecycleListView
与
android.support.v7.widget.RecyclerView
【讨论】:
以上是关于膨胀类 android.support.v7.app.AlertController.RecycleListView 时出错的主要内容,如果未能解决你的问题,请参考以下文章
膨胀类 CollapsingToolbarLayout 时出错
如何为android修复“错误膨胀类GeckoEngineView”