我的应用无法启动它在安装后立即崩溃,我无法理解错误!
我为两个片段创建了两个recylcerView,它们附加在主活动xml文件
中
错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.invincible.fragfrag, PID: 14384
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.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:
MainActivity:
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_width="match_parent"
android:layout_height="match_parent"
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_width="match_parent"
android:layout_height="0dp">
</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_width="match_parent"
android:layout_height="0dp">
</android.support.v7.app.AlertController.RecycleListView>
</LinearLayout>
PLZ帮助我解决错误以及如何在一个活动中使用两个recyclerview处理两个片段。
感谢您的关注!
答案 0 :(得分:5)
您可能想要使用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的内部类,不能在您的项目中使用。
答案 1 :(得分:2)
android.support.v7.app.AlertController.RecycleListView
带
android.support.v7.widget.RecyclerView