2016-03-28 5 views
0

Ich habe eine neue Activity zu meinem Android Studio hinzugefügt. Diese Aktivität hat ein Bild. Hier ist der Code meines xml.fileAndroid Studio - Aktivität mit Bild stürzt Emulator aber funktioniert in Telefon

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:showIn="@layout/auxguide1" 
tools:context=".AuxGuide1"> 

<ImageView 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    android:id="@+id/imageView2" 
    android:src="@drawable/logoauxguide" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

und hier ist mein Code des Java-Klasse Paket com.example.gonalo.meu;

import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
import android.support.v7.app.AppCompatActivity; 

public class AuxGuide1 extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.auxguide1); 
     int secondsDelayed = 1; 
     new Handler().postDelayed(new Runnable() { 
      public void run() { 
       startActivity(new Intent(AuxGuide1.this, MainActivity.class)); 

       finish(); 
      } 
     }, secondsDelayed * 4000); 
    } 

} 

Es funktioniert perfekt in meinem Handy, aber wenn ich es auf dem Emulator laufen, sagt es

Das ist mein logcat

03-28 08:01:20.513 29031-29031/com.example.gonalo.meu W/art: Throwing OutOfMemoryError "Failed to allocate a 79051908 byte allocation with 1048576 free bytes and 63MB until OOM" 
03-28 08:01:20.514 29031-29031/com.example.gonalo.meu D/skia: --- allocation failed for scaled bitmap 
03-28 08:01:20.514 29031-29031/com.example.gonalo.meu D/AndroidRuntime: Shutting down VM 
03-28 08:01:20.515 29031-29031/com.example.gonalo.meu E/AndroidRuntime: FATAL EXCEPTION: main 
                       Process: com.example.gonalo.meu, PID: 29031 
                    java.lang.OutOfMemoryError: Failed to allocate a 79051908 byte allocation with 1048576 free bytes and 63MB until OOM 
                     at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
                     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
                     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 
                     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 
                     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080) 
                     at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635) 
                     at android.content.res.Resources.loadDrawable(Resources.java:2540) 
                     at android.content.res.TypedArray.getDrawable(TypedArray.java:870) 
                     at android.widget.ImageView.<init>(ImageView.java:152) 
                     at android.widget.ImageView.<init>(ImageView.java:140) 
                     at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57) 
                     at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53) 
                     at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106) 
                     at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972) 
                     at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1031) 
                     at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) 
                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746) 
                     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
                     at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
                     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                     at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                     at com.example.gonalo.meu.AuxGuide1.onCreate(AuxGuide1.java:13) 
                     at android.app.Activity.performCreate(Activity.java:6237) 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                     at android.os.Looper.loop(Looper.java:148) 
                     at android.app.ActivityThread.main(ActivityThread.java:5417) 
                     at java.lang.reflect.Method.invoke(Native Method) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
03-28 08:01:25.402 29031-29031/? I/Process: Sending signal. PID: 29031 SIG: 9 

Es ist nicht „sorry die Anwendung gestoppt hat“ wird Stoppen Sie meine Arbeit an dem Projekt, aber es ist nützlich für mich zu wissen, warum dies passiert. Würde mich über Hilfe freuen. My application has stopped (emulator only)

+0

was ist die Dimension des Bildes 'logoauxguide' in' AuxGuide1' xml? –

+0

@FabinPaul Wie suche ich nach der Dimension des Bildes? Ich wusste, wo es war, kann mich aber nicht erinnern, wo es ist. –

+0

Versuchen Sie, die Zeile 'android: src =" @ drawable/logoauxguide "' aus Ihrem xml –

Antwort

2

Wenn ein Android-Gerät ein Bild anzeigen muss, muss es das gesamte Bild in den Speicher laden. In Ihrem Fall logoauxguide ist Bild mit hoher Auflösung, so dass das gesamte Bild nicht in den Gerätespeicher passt. Daher wird OutOfMemoryError auftreten.

Aber ein Gerät mit größerem Speicher, in diesem Fall wird Ihr Telefon in der Lage sein, das Bild in den Speicher zu laden.

Wenn Sie das Bild anzeigen möchten, müssen Sie die Auflösung in jedem Bildbearbeitungstool reduzieren (640x480 ist in Ordnung). Außerdem möchtest du kein höheres Speicherbild haben, das deine apk Größe vergrößert :)

+0

Gibt es eine Option, um den Speicher größer zu machen? –

+0

Speicher ist Hardwarebeschränkung und kann nicht geändert werden. (Abhängig vom Gerät alten Nexus hatte man nur 512 MB RAM, während nexus 6p 3 GB RAM haben) –

Verwandte Themen