Android Studio运行时异常

时间:2015-12-18 19:18:14

标签: java android-studio

当我尝试使用android studio v1.5编译我的android项目时,我得到一个运行时异常。显示下面的日志...

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nullmag.connect3, PID: 1723 java.lang.RuntimeException: 
Unable to start activity ComponentInfo{com.nullmag.connect3/com.nullmag.connect3.MainActivity}: 
android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.GridLayout
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2371)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2433)
    at android.app.ActivityThread.access$900(ActivityThread.java:153)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5372)
    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:911)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.GridLayout
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
    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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
    at com.nullmag.connect3.MainActivity.onCreate(MainActivity.java:24)
    at android.app.Activity.performCreate(Activity.java:6865)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2433) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5372) 
    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:911) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
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:607)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
    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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
    at com.nullmag.connect3.MainActivity.onCreate(MainActivity.java:24) 
    at android.app.Activity.performCreate(Activity.java:6865) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2433) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5372) 
    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:911) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 109077084 byte allocation with 5424842 free bytes and 88MB until OOM
    at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
    at android.content.res.Resources.loadDrawableForCookie(Resources.java:2638)
    at android.content.res.Resources.loadDrawable(Resources.java:2545)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
    at android.view.View.<init>(View.java:3754)
    at android.view.ViewGroup.<init>(ViewGroup.java:498)
    at android.widget.GridLayout.<init>(GridLayout.java:285)
    at android.widget.GridLayout.<init>(GridLayout.java:281)
    at android.widget.GridLayout.<init>(GridLayout.java:277)
    at java.lang.reflect.Constructor.newInstance(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
    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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
    at com.nullmag.connect3.MainActivity.onCreate(MainActivity.java:24) 
    at android.app.Activity.performCreate(Activity.java:6865) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2433) 
    at android.app.ActivityThread.access$900(ActivityThread.java:153) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5372) 
    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:911) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    12-19 00:12:56.867 1723-1723/com.nullmag.connect3 I/Process: Sending signal. PID: 1723 SIG: 9

我尝试了一些类似帖子中提到的方法,但似乎没有帮助。

2 个答案:

答案 0 :(得分:1)

您收到的异常是GridLayout

Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.GridLayout

因为你试图加载一个如此大的图像以便在内存中分配

 Caused by: java.lang.OutOfMemoryError: Failed to allocate a 109077084 byte allocation with 5424842 free bytes and 88MB until OOM

尝试将较小尺寸的图片加载到GridLayout

查看官方文档以获取有关如何处理大图片的更多信息,并避免OutOfMemoryError

Loading Large Bitmaps Efficiently

答案 1 :(得分:0)

感谢您的回复!降低图像大小似乎可以解决问题!