0

わからない問題があります。次のコード スニペットに到達したとき

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>
4

3 に答える 3

0

背景画像には .png 画像の代わりに .jpeg/.jpg 形式を使用してください。これは、Android でリソースを再作成する際に .png が .jpeg/.jpg 画像と比較してより多くのヒープ メモリを消費するためです。

于 2016-03-28T10:47:34.583 に答える