2017-12-14 4 views
0

タイトルに記載されているように、私の問題はエラーに関連しています。 同じ背景を使用する3つのレイアウトを設定しましたが、このエラーが発生するレイアウトは1つだけです。バックグラウンドを設定するとエラーが発生しました。バックグラウンドがなければ、問題なく実行できます。しかし、私が解決したいのは、メモリ不足のエラーを修正する方法と、このレイアウトがエラーを生成する理由は、他の2つはエラーではありません。コードはほとんど同じです。Java.Lang.OutOfMemoryError:1つのレイアウトでのみ発生しますが、他のレイアウトでは発生しません

これはエラーを生成するレイアウトです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/seabg"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    app:srcCompat="@drawable/f1" 
    android:id="@+id/imageView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<Button 
    android:text="CLICK" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="177dp" 
    android:id="@+id/btnf" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" /> 
<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    app:srcCompat="@drawable/ferry" 
    android:id="@+id/imageView1" 
    android:layout_marginBottom="36dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 
</RelativeLayout> 

一方、これはエラーなしで正常に実行できるものです。 (これは、コードは最初ImageViewが異なるまったく同じに見えますので、いくつかのスペースを節約し、2つのレイアウトにする必要があります。)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/seabg"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    app:srcCompat="@drawable/y1" 
    android:id="@+id/imageView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<Button 
    android:text="CLICK" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="177dp" 
    android:id="@+id/btny" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" /> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    app:srcCompat="@drawable/yacht" 
    android:id="@+id/imageView1" 
    android:layout_marginBottom="36dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 
</RelativeLayout> 

編集:これはエラーを生成する1つのための私の活動です。

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.layout_f); 

    final MediaPlayer fSound = MediaPlayer.create(this, R.raw.ferry); 
    btnf = (Button) findViewById(R.id.btnf); 
    btnf.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
      fSound.start(); 
     } 
    }); 

} 

これは問題なく実行できるものです。

+1

あなたのアクティビティで 'ImageView'を使用していますか?関連する活動のコードを投稿できますか? 2つのイメージを含めることは可能ですか? –

+0

Nicolasと合意した、私は非常に大きな画像を持ついくつかのOutOfMemoryErrorに遭遇しました。画像そのものを指していないため、追跡が非常に難しいです。 –

+0

この問題も発生しました。私はより良い理解のためのドキュメントをお勧めします。 https://developer.android.com/topic/performance/graphics/load-bitmap.html –

答えて

0

イメージを削除してみてください。イメージを表示するか、イメージsrcを低解像度に変更してください。これはあなたの問題を解決するかもしれません!

+0

答えをありがとう!それは確かに解像度に関連していますが、私はイメージビューを削除する必要はありません。御時間ありがとうございます! –

関連する問題