App schliesst sich, wenn Sound und Vibration genutzt werden

  • Antworten:1
  • OffenNicht stickyBentwortet
  • Forum-Beiträge: 6

17.07.2019, 12:27:32 via Website

Hallo,
wie schon in der Überschrift gelesen habe ich das Problem, dass meine App sich sofort nach der Öffnung schliesst.
Ich vermute , dass es etwas mit der Vibration oder dem Sound zu tun hat, denn als ich diese noch nicht in meinem Programm hatte lief es ohne Probleme.

Hier der Code`public class MainActivity extends AppCompatActivity {

public int MinPoints = 0;
public int MaxPointsSSJ = 10;
public int MaxPointsSSJ2 = 20;
public int MaxPointsSSJ3 = 50;
public int Progress;

private Vibrator v;
private MediaPlayer Effekt;

private void checker(int currentPoints, int maxPoints, int newmaxPoints, ImageView anzeige, int bild, ProgressBar pb){
    if (currentPoints == maxPoints)
        maxPoints = newmaxPoints;
    pb.setMax(newmaxPoints);
    anzeige.setImageResource(bild);
    v.vibrate(100);
    Effekt.start();
    pb.setProgress(currentPoints );
    if (maxPoints == newmaxPoints){
        currentPoints = pb.getProgress();
        pb.setProgress(currentPoints);
    }
}

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

final ImageView Anzeige = (ImageView) findViewById(R.id.imageView);
    final ProgressBar KiAnzeige = (ProgressBar) findViewById(R.id.progressBar);
    Button MehrEnergie = (Button) findViewById(R.id.button);

    KiAnzeige.setMax(MaxPointsSSJ);
    KiAnzeige.setMin(MinPoints);
    KiAnzeige.setProgress(0);
    Progress = KiAnzeige.getProgress();
    v = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    Effekt = MediaPlayer.create(this, R.raw.aura_burst);

    MehrEnergie.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Progress++;
            KiAnzeige.setProgress(Progress);
            if (Progress == MaxPointsSSJ){
                checker(Progress, MaxPointsSSJ, MaxPointsSSJ2, Anzeige, R.drawable.goku_ssj1, KiAnzeige);
            }
            if (Progress == MaxPointsSSJ2){
                checker(Progress, MaxPointsSSJ2, MaxPointsSSJ3, Anzeige, R.drawable.goku_ssj2, KiAnzeige);
            }
        }
    });
}

}
`
Edit: Habe fehlende Teile meines Codes ergänzt.
Hier der ErrorLog:

2019-07-17 12:52:21.572 12454-12454/com.example.ssjclicker E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ssjclicker, PID: 12454
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ssjclicker/com.example.ssjclicker.MainActivity}: android.content.res.Resources$NotFoundException: File res/raw/aura_burst.MP3 from drawable resource ID #0x7f0b0000
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3037)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: android.content.res.Resources$NotFoundException: File res/raw/aura_burst.MP3 from drawable resource ID #0x7f0b0000
    at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:318)
    at android.content.res.Resources.openRawResourceFd(Resources.java:1320)
    at android.media.MediaPlayer.create(MediaPlayer.java:995)
    at android.media.MediaPlayer.create(MediaPlayer.java:978)
    at com.example.ssjclicker.MainActivity.onCreate(MainActivity.java:56)
    at android.app.Activity.performCreate(Activity.java:7149)
    at android.app.Activity.performCreate(Activity.java:7140)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:6863) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
 Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
    at android.content.res.AssetManager.nativeOpenNonAssetFd(Native Method)
    at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:908)
    at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:315)
    at android.content.res.Resources.openRawResourceFd(Resources.java:1320) 
    at android.media.MediaPlayer.create(MediaPlayer.java:995) 
    at android.media.MediaPlayer.create(MediaPlayer.java:978) 
    at com.example.ssjclicker.MainActivity.onCreate(MainActivity.java:56) 
    at android.app.Activity.performCreate(Activity.java:7149) 
    at android.app.Activity.performCreate(Activity.java:7140) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3017) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3172) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:6863) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

2019-07-17 12:52:21.579 12454-12483/com.example.ssjclicker D/OSTracker: OS Event: crash
2019-07-17 12:52:21.588 12454-12454/com.example.ssjclicker I/Process: Sending signal. PID: 12454 SIG: 9

— geändert am 17.07.2019, 12:57:13

Diskutiere mit!
Beste Antwort
  • Forum-Beiträge: 3.642

17.07.2019, 12:48:46 via Website

Hallo Draz,

bitte liefere uns deinen ErrorLog mit , dann können wir auch Dir eine Antwort geben.
Alles Andere wäre ein Fall für die Kristallkugel.

Und auf Anhieb :

KiAnzeige.setProgress(Progress);

Es gibt keine gültige Instanz zu KiAnzeige.
Dein obiger Code konnte so niemals compliliert werden

Danke

NACHTRAG :

Caused by: android.content.res.Resources$NotFoundException: File res/raw/aura_burst.MP3 from drawable resource
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

Du hast Problem mir deiner mp3 (gibt es anscheinend nicht und hat im übrigen die falsche extension / compression)

— geändert am 17.07.2019, 13:16:35

Liebe Grüße - Stefan
[ App - Entwicklung ]

Hilfreich?
Diskutiere mit!