更新了Android Studio,现在是Error Inflating Class

时间:2015-07-03 16:59:15

标签: android android-layout android-studio inflate-exception

我的应用工作正常。我更新了Android Studio。然后我再次构建我的应用程序进行测试,现在它立即崩溃了!就像Android Studio移动资源一样。我不确定导致此错误的原因。我经历了从头开始构建应用程序的麻烦,复制并粘贴代码,我得到了同样的错误。欢迎来自社区的帮助。

07-03 12:02:25.134    6167-6167/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mystuff.test, PID: 6167
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mystuff.test/com.mystuff.test.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class com.mystuff.test.BattleView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.access$900(ActivityThread.java:177)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5942)
        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:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.mystuff.test.BattleView
        at android.view.LayoutInflater.createView(LayoutInflater.java:640)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
        at android.app.Activity.setContentView(Activity.java:2267)
        at com.mystuff.test.MainActivity.onCreate(MainActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:6289)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.access$900(ActivityThread.java:177)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5942)
        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:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        at android.view.LayoutInflater.createView(LayoutInflater.java:614)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
        at android.app.Activity.setContentView(Activity.java:2267)
        at com.mystuff.test.MainActivity.onCreate(MainActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:6289)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.access$900(ActivityThread.java:177)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5942)
        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:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 Caused by: java.lang.VerifyError: com.mystuff.test.BattleView$BattleThread
        at com.mystuff.test.BattleView.<init>(BattleView.java:1312)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        at android.view.LayoutInflater.createView(LayoutInflater.java:614)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:435)
        at android.app.Activity.setContentView(Activity.java:2267)
        at com.mystuff.test.MainActivity.onCreate(MainActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:6289)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.access$900(ActivityThread.java:177)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5942)
        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:1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

这里是引用的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mystuff.test.BattleView
    android:id="@+id/pea"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

</LinearLayout>

这里是视图和线程的引用构造函数:

//constructor gets the surface holder, assigns a callback and creates an instance of the thread
public BattleView (Context context, AttributeSet attrs) {
    super(context, attrs);
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    thread = new BattleThread(holder, context, new Handler() {
        @Override
        public void handleMessage(Message m) {
        }
    });
    setFocusable(true);
}
//method to return the thread in case you need to control it from the activity
public BattleThread getThread() {
    return thread;
}

class BattleThread extends Thread {
    public BattleThread(SurfaceHolder surfaceHolder, Context context, Handler handler) {
        mySurfaceHolder = surfaceHolder;
        myContext = context;
        backgroundImg = BitmapFactory.decodeResource(context.getResources(), R.drawable.nopeastitlecrackedstart);
        backgroundOrigW = backgroundImg.getWidth();
        backgroundOrigH = backgroundImg.getHeight();
    }

//the rest of the thread.  Code I haven't changed before it broke.
}

1 个答案:

答案 0 :(得分:0)

感谢所有花时间阅读代码并给我一些建议的人。经过多次试验和错误,结果证明我在战斗线程中的画布绘制方法已经变得太大而且没有正确编译。它没有超过方法限制大小,所以我不知道它为什么拒绝它,但通过消除过程,结果证明是解决方案。令人沮丧的是,我没有在任何日志中得到那个特定的错误而且必须自己去找它。