Android Simple Inflate Fix

时间:2014-09-08 22:51:07

标签: java android xml android-layout android-fragments

我试图从ListFragment启动并运行我的Android应用程序,但是我抛出了InflatException。我的XML在下面,问题在于创建片段,但我不确定问题是什么。我试图转换本教程:http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/以使用片段,并在教程下方发表评论,建议如何简要地做到这一点。我不确定为什么会出现错误,因为一切似乎都是正确的。如果您需要我提供更多信息,请告诉我,我们乐意为您提供帮助。

机器人:

@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.list_fragment, container, false);
        setListAdapter(adapter);

        listView = (ListView) getActivity().findViewById(R.id.list);
        adapter = new CustomListAdapter(getActivity(), movieList);
        listView.setAdapter(adapter);

        ...

XML:

<relativelayout xmlns:android="http://schemas.android.com/apk..."
    xmlns:tools="http://schemas.android.com/too..."
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <listview
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@color/list_divider"
        android:dividerheight="1dp"
        android:listselector="@drawable/list_row_selector" />

</relativelayout>   

logcat的:

09-08 18:45:25.572: E/AndroidRuntime(9167): FATAL EXCEPTION: main
09-08 18:45:25.572: E/AndroidRuntime(9167): Process: com.rynovation.kline, PID: 9167
09-08 18:45:25.572: E/AndroidRuntime(9167): android.view.InflateException: Binary XML file line #1: Error inflating class relativelayout
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at com.rynovation.kline.mainViewController2.onCreateView(mainViewController2.java:40)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.Fragment.performCreateView(Fragment.java:1700)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.BackStackRecord.run(BackStackRecord.java:684)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1453)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.os.Handler.handleCallback(Handler.java:733)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.os.Handler.dispatchMessage(Handler.java:95)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.os.Looper.loop(Looper.java:146)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.app.ActivityThread.main(ActivityThread.java:5487)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at java.lang.reflect.Method.invokeNative(Native Method)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at java.lang.reflect.Method.invoke(Method.java:515)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at dalvik.system.NativeStart.main(Native Method)
09-08 18:45:25.572: E/AndroidRuntime(9167): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.relativelayout" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.rynovation.kline-176.apk"],nativeLibraryDirectories=[/data/app-lib/com.rynovation.kline-176, /vendor/lib, /system/lib]]
09-08 18:45:25.572: E/AndroidRuntime(9167):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.createView(LayoutInflater.java:565)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:658)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
09-08 18:45:25.572: E/AndroidRuntime(9167):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
09-08 18:45:25.572: E/AndroidRuntime(9167):     ... 18 more

1 个答案:

答案 0 :(得分:2)

带有<RelativeLayout ... />

R