Android应用程序崩溃:渲染过程中出现异常

时间:2013-12-10 08:26:54

标签: android xml performance android-layout

 FATAL EXCEPTION: main
 E/AndroidRuntime(5553): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appkraft.parallax_sample/com.appkraft.parallax_sample.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class com.appkraft.parallax_sample
 E/AndroidRuntime(5553):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
 E/AndroidRuntime(5553):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
 E/AndroidRuntime(5553):    at android.app.ActivityThread.access$600(ActivityThread.java:162)
 E/AndroidRuntime(5553):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
 E/AndroidRuntime(5553):    at android.os.Handler.dispatchMessage(Handler.java:107)
 E/AndroidRuntime(5553):    at android.os.Looper.loop(Looper.java:194)
 E/AndroidRuntime(5553):    at android.app.ActivityThread.main(ActivityThread.java:5371)
 E/AndroidRuntime(5553):    at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(5553):    at java.lang.reflect.Method.invoke(Method.java:525)
 E/AndroidRuntime(5553):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
 E/AndroidRuntime(5553):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
 E/AndroidRuntime(5553):    at dalvik.system.NativeStart.main(Native Method)
 E/AndroidRuntime(5553): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class com.appkraft.parallax_sample
 E/AndroidRuntime(5553):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
 E/AndroidRuntime(5553):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
 E/AndroidRuntime(5553):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
 E/AndroidRuntime(5553):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
 E/AndroidRuntime(5553):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
 E/AndroidRuntime(5553):    at android.app.Activity.setContentView(Activity.java:1881)
 E/AndroidRuntime(5553):    at com.appkraft.parallax_sample.MainActivity.onCreate(MainActivity.java:18)
 E/AndroidRuntime(5553):    at android.app.Activity.performCreate(Activity.java:5122)
 E/AndroidRuntime(5553):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
 E/AndroidRuntime(5553):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
 E/AndroidRuntime(5553): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.appkraft.parallax_sample" on path: DexPathList[[zip file "/data/app/com.appkraft.parallax_sample-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.appkraft.parallax_sample-1, /vendor/lib, /system/lib]]
 E/AndroidRuntime(5553):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
 E/AndroidRuntime(5553):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
 E/AndroidRuntime(5553):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
 E/AndroidRuntime(5553):    at android.view.LayoutInflater.createView(LayoutInflater.java:552)
 E/AndroidRuntime(5553):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)

logcat所引用的类在它们各自的路径中存在。为什么我仍然会收到此错误,是否与main.xml有关?

感谢任何帮助。

以下是onCreate()方法。

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        parallax = (ParallaxScrollView) findViewById(R.id.scrollView1);
        image = (ImageView) findViewById(R.id.imageView1);

        parallax.setImageViewToParallax(image);

    }

这是main.xml

<com.appkraft.parallax_sample xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/com.appkraft.parallax_sample"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="1000dp"
        tools:context=".MainActivity" >

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:context=".MainActivity" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:src="@drawable/teste" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:text="Bottom"
                android:textColor="#ffffff"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:text="Top"
                android:textColor="#ffffff"
                android:textSize="18sp" />
        </RelativeLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/relativeLayout1"
            android:text="@string/hello_world" />
    </RelativeLayout>

</com.appkraft.parallax_sample>

在切换到图形布局时,它说:

渲染期间引发异常:com.android.layoutlib.bridge.MockView无法强制转换为android.view.ViewGroup Window&gt;中记录了异常详细信息。显示视图&gt;错误日志 找不到以下类: - com.appkraft.parallax_sample(修复构建路径,编辑XML,创建类)

2 个答案:

答案 0 :(得分:0)

<com.appkraft.parallax_sample` xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.appkraft.parallax_sample"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never">

您只是将包放在第一行,您必须调用该类

<com.appkraft.parallax_sample.YOUR_CUSTOM_VIEW

答案 1 :(得分:0)

@ pedro Bernando 最有可能是正确的尝试这个 com.appkraft.parallax_sample.ParallaxScrollView。