Android应用程序在启动后崩溃

时间:2013-06-30 10:15:03

标签: android out-of-memory android-xml

我正在尝试创建一个包含大量高分辨率图像的应用,以便它们也适用于高端设备和低端设备。现在有些设备现在都是1080p分辨率的手机。

我使用的是具有756MB RAM,720p屏幕和My VM堆大小为64MB的AVD。 我的操作系统是Windows 8。

这是我的活动档案。我暂时没有添加任何东西

public class MainActivity extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

这是xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
tools:context=".MainActivity" >

 <ImageView
     android:id="@+id/head"
     android:layout_width="match_parent"
     android:layout_height="100dp"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:scaleType="fitXY"
     android:src="@drawable/head1" />

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:weightSum="6" >

<ImageView
    android:id="@+id/logo"
    android:layout_width="0dp"
    android:layout_height="100dp"
    android:src="@drawable/logo21"
    android:layout_weight="3" />

<ImageView
    android:id="@+id/knob1"
    android:layout_width="0dp"
    android:layout_height="100dp"
    android:src="@drawable/knob1"
    android:layout_weight="1" />

<ImageView
    android:id="@+id/knob2"
    android:layout_width="0dp"
    android:layout_height="100dp"
    android:src="@drawable/knob2"
    android:layout_weight="1" />

<ImageView
    android:id="@+id/knob3"
    android:layout_width="0dp"
    android:layout_height="100dp"
    android:src="@drawable/knob3"
    android:layout_weight="1" />   

    </LinearLayout>

<ImageView
    android:id="@+id/bottom"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:paddingTop="10dp"
    android:src="@drawable/button" />

在运行应用程序时,我收到此消息:

“不幸的是德国洗衣店停止了”

请帮助我!!

**更新 我的logcat按要求* *


06-30 10:49:42.524: E/Trace(830): error opening trace file: No such file or directory (2)
06-30 10:49:43.063: D/dalvikvm(830): GC_FOR_ALLOC freed 41K, 7% free 2498K/2660K, paused 88ms, total 102ms
06-30 10:49:43.163: I/dalvikvm-heap(830): Grow heap (frag case) to 7.018MB for 4680016-byte allocation
06-30 10:49:43.264: D/dalvikvm(830): GC_FOR_ALLOC freed 2K, 3% free 7066K/7232K, paused 98ms, total 98ms
06-30 10:49:43.393: D/dalvikvm(830): GC_CONCURRENT freed (ImageView.java:120)
06-30 10:49:45.953: I/dalvikvm(830):   at android.widget.ImageView.(ImageView.java:110)
06-30 10:49:45.953: I/dalvikvm(830):   at java.lang.reflect.Constructor.constructNative(Native Method)
06-30 10:49:45.953: I/dalvikvm(830):   at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-30 10:49:45.963: I/dalvikvm(830):   at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)

06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.inflate(LayoutInflater.java:489)

06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-30 10:49:45.963: I/dalvikvm(830):   at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-30 10:49:45.963: I/dalvikvm(830):   at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.Activity.setContentView(Activity.java:1881)
06-30 10:49:45.963: I/dalvikvm(830):   at com.example.germanlaundryfinal.MainActivity.onCreate(MainActivity.java:12)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.Activity.performCreate(Activity.java:5104)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-30 10:49:45.963: I/dalvikvm(830):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-30 10:49:45.973: I/dalvikvm(830):   at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 10:49:45.973: I/dalvikvm(830):   at android.os.Looper.loop(Looper.java:137)
06-30 10:49:45.973: I/dalvikvm(830):   at android.app.ActivityThread.main(ActivityThread.java:5041)
06-30 10:49:45.973: I/dalvikvm(830):   at java.lang.reflect.Method.invokeNative(Native Method)
06-30 10:49:45.973: I/dalvikvm(830):   at java.lang.reflect.Method.invoke(Method.java:511)
06-30 10:49:45.973: I/dalvikvm(830):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-30 10:49:45.973: I/dalvikvm(830):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-30 10:49:45.973: I/dalvikvm(830):   at dalvik.system.NativeStart.main(Native Method)
06-30 10:49:45.973: D/skia(830): --- allocation failed for scaled bitmap
06-30 10:49:45.983: D/AndroidRuntime(830): Shutting down VM
06-30 10:49:45.983: W/dalvikvm(830): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-30 10:49:46.043: E/AndroidRuntime(830): FATAL EXCEPTION: main
06-30 10:49:46.043: E/AndroidRuntime(830): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.germanlaundryfinal/com.example.germanlaundryfinal.MainActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class 
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.os.Looper.loop(Looper.java:137)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.ActivityThread.main(ActivityThread.java:5041)
06-30 10:49:46.043: E/AndroidRuntime(830):  at java.lang.reflect.Method.invokeNative(Native Method)
06-30 10:49:46.043: E/AndroidRuntime(830):  at java.lang.reflect.Method.invoke(Method.java:511)
06-30 10:49:46.043: E/AndroidRuntime(830):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-30 10:49:46.043: E/AndroidRuntime(830):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-30 10:49:46.043: E/AndroidRuntime(830):  at dalvik.system.NativeStart.main(Native Method)
06-30 10:49:46.043: E/AndroidRuntime(830): Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class 
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-30 10:49:46.043: E/AndroidRuntime(830):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-30 10:49:46.043: E/AndroidRuntime(830):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.Activity.setContentView(Activity.java:1881)
06-30 10:49:46.043: E/AndroidRuntime(830):  at com.example.germanlaundryfinal.MainActivity.onCreate(MainActivity.java:12)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.Activity.performCreate(Activity.java:5104)
06-30 10:49:46.043: E/AndroidRuntime(830):  at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-30 10:49:46.043: E/AndroidRuntime(830):  ... 11 more
06-30 10:49:46.043: E/AndroidRuntime(830): Caused by: java.lang.reflect.InvocationTargetException
06-30 10:49:46.043: E/AndroidRuntime(830):  at java.lang.reflect.Constructor.constructNative(Native Method)
06-30 10:49:46.043: E/AndroidRuntime(830):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-30 10:49:46.043: E/AndroidRuntime(830):  ... 25 more
06-30 10:49:46.043: E/AndroidRuntime(830): Caused by: java.lang.OutOfMemoryError
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.widget.ImageView.(ImageView.java:120)
06-30 10:49:46.043: E/AndroidRuntime(830):  at android.widget.ImageView.(ImageView.java:110)
06-30 10:49:46.043: E/AndroidRuntime(830):  ... 28 more

1 个答案:

答案 0 :(得分:0)

您必须缩放位图才能使其在设备中正常工作。请参阅this answer