升级Android Studio 新建项目,默认Hello World 运行没有问题,删掉TextView,换成ImageView,只加载一个图,编译运行,程序闪退,下变为源码。
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.happybirthday.MainActivity">
android:src="@drawable/androidplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
图片为1.19MB,2880*1800分辨率,放在drawable目录下,图片没有问题,在另一个同学的那里相同代码可以编译并顺利运行,相同代码和图片放在eclipse没有问题。
闪退后错误信息
04-10 22:46:38.733 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.733 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.733 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.733 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:38.833 2393-2393/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 22:46:39.283 2393-2393/com.example.android.happybirthday E/dalvikvm-heap: Out of memory on a 46656012-byte allocation.
04-10 22:46:39.303 2393-2393/com.example.android.happybirthday E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.happybirthday, PID: 2393
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.happybirthday/com.example.android.happybirthday.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.widget.ImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:621)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.android.happybirthday.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:595)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.android.happybirthday.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2115)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.(ImageView.java:129)
at android.widget.ImageView.(ImageView.java:119)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:595)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:670)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.android.happybirthday.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
换一张小图,1254*1254分辨率的就能够顺利运行,仅仅换了张图,将那张大图放在mipmap目录下,使用@mipmap就能运行。
想着是编译器出问题了,重装了整个AS,但还是不行,并且有时候错误信息是内存泄漏或者OOM
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:32.881 10358-10358/com.example.android.happybirthday E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.android.happybirthday.MainActivity.access$super
04-10 23:05:33.791 10358-10358/com.example.android.happybirthday E/dalvikvm-heap: Out of memory on a 118160652-byte allocation.
04-10 23:05:33.811 10358-10358/com.example.android.happybirthday E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.happybirthday, PID: 10358
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2115)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.(ImageView.java:129)
at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1030)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.example.android.happybirthday.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
请各路大神帮忙!感激不尽。