我有问题我不明白。当我到达以下代码片段时
public class MatchViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("OnCreate in MatchViewActivity","1");
setContentView(R.layout.activity_match_view); <--- Crash occurrs here
Log.d("","2");
Intent intent = getIntent();
我总是在模拟器中收到以下错误:
10-07 18:41:39.012: E/dalvikvm-heap(1099): Out of memory on a 3686416-byte allocation.
我可以在 logcat 中找到一些行:
10-07 18:41:39.452: E/AndroidRuntime(1099): FATAL EXCEPTION: main
10-07 18:41:39.452: E/AndroidRuntime(1099): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.matchView.MatchViewActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.os.Looper.loop(Looper.java:137)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-07 18:41:39.452: E/AndroidRuntime(1099): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 18:41:39.452: E/AndroidRuntime(1099): at java.lang.reflect.Method.invoke(Method.java:511)
10-07 18:41:39.452: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-07 18:41:39.452: E/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-07 18:41:39.452: E/AndroidRuntime(1099): at dalvik.system.NativeStart.main(Native Method)
10-07 18:41:39.452: E/AndroidRuntime(1099): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
10-07 18:41:39.452: E/AndroidRuntime(1099): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-07 18:41:39.452: E/AndroidRuntime(1099): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.Activity.setContentView(Activity.java:1881)
10-07 18:41:39.452: E/AndroidRuntime(1099): at com.example.matchView.MatchViewActivity.onCreate(MatchViewActivity.java:25)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.Activity.performCreate(Activity.java:5104)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-07 18:41:39.452: E/AndroidRuntime(1099): ... 11 more
10-07 18:41:39.452: E/AndroidRuntime(1099): Caused by: java.lang.reflect.InvocationTargetException
10-07 18:41:39.452: E/AndroidRuntime(1099): at java.lang.reflect.Constructor.constructNative(Native Method)
10-07 18:41:39.452: E/AndroidRuntime(1099): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
10-07 18:41:39.452: E/AndroidRuntime(1099): ... 23 more
10-07 18:41:39.452: E/AndroidRuntime(1099): Caused by: java.lang.OutOfMemoryError
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.content.res.Resources.loadDrawable(Resources.java:1965)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.View.<init>(View.java:3330)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.view.ViewGroup.<init>(ViewGroup.java:431)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.widget.FrameLayout.<init>(FrameLayout.java:101)
10-07 18:41:39.452: E/AndroidRuntime(1099): at android.widget.FrameLayout.<init>(FrameLayout.java:97)
10-07 18:41:39.452: E/AndroidRuntime(1099): ... 26 more
10-07 18:46:39.632: I/Process(1099): Sending signal. PID: 1099 SIG: 9
我检查了“activity_match_view”确实存在。这里发生了什么?
对应的布局文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_background" >
<ListView
android:id="@+id/matchView_ListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000">
</ListView>
</FrameLayout>