App schließt nach Start.

brilzi89

Bekanntes Mitglied
Hallo zusammen,

ich (neuling) hab mit Hilfe von Youtube videos versucht, eine Quiz App zu schreiben.
Jedesmal wenn ich versuche die App auf meinem Smartphone zu öffnen, schließt diese sofort wieder. Android studio zeigt keine Fehler in der App und ich selber sehe auch keine. Könnt Ihr mir helfen.

Hier der Script:
Java:
[SIZE=2]import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    Button antwort1, antwort2, antwort3, antwort4;
    TextView Score, Frage;

    private Frage mFrage = new Frage();

    private String mrichtigeAntwort;
    private int mScore = 0;
    private int mFrageLenght = mFrage.mFrage.length;

    Random r;


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


        antwort1 = (Button) findViewById(R.id.antwort1);
        antwort2 = (Button) findViewById(R.id.antwort2);
        antwort3 = (Button) findViewById(R.id.antwort3);
        antwort4 = (Button) findViewById(R.id.antwort4);

        Score = (TextView) findViewById(R.id.Score);
        Frage = (TextView) findViewById(R.id.Frage);

        Score.setText("Score:" + mScore);

        updateFrage(r.nextInt(mFrageLenght));


        antwort1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
if (antwort1.getText() == mrichtigeAntwort){
    mScore ++;
    Score.setText("Score:" + mScore);
    updateFrage(r.nextInt(mFrageLenght));
}else {
    gameOver();
}
            }
        });
        antwort2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (antwort2.getText() == mrichtigeAntwort){
                    mScore ++;
                    Score.setText("Score:" + mScore);
                    updateFrage(r.nextInt(mFrageLenght));
                }else {
                    gameOver();
                }
            }
        });
        antwort3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    if (antwort3.getText() == mrichtigeAntwort){
                        mScore ++;
                        Score.setText("Score:" + mScore);
                        updateFrage(r.nextInt(mFrageLenght));
                    }else {
                        gameOver();
                    }
            }
        });
        antwort4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (antwort4.getText() == mrichtigeAntwort) {
                    mScore++;
                    Score.setText("Score:" + mScore);
                    updateFrage(r.nextInt(mFrageLenght));
                } else {
                    gameOver();
                }
            }

        });
    }

    private void updateFrage(int num) {
        Frage.setText(mFrage.getFrage(num));
antwort1.setText(mFrage.getAuswahl1(num));
        antwort2.setText(mFrage.getAuswahl2(num));

        mrichtigeAntwort =mFrage.getrichtigeAntwort(num);
    }

private void gameOver(){
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
    alertDialogBuilder
            .setMessage("Game over du hast  " + mScore + "Punkte")
            .setCancelable(false)
            .setPositiveButton("New Game",
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(getApplicationContext(), MainActivity.class));
                        }

})

            .setNegativeButton("Exit",
                                       new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
                            finish();
        }

});

}
}


Java:
public class Frage {


    public String mFrage[] = {
            "Welches Tier ist das Beste",
            "Wie alt bin ich",

    };

    public String mAuswahl[][] = {
            {"Katze", "Hund", "Affe", "Tiger"},
            {"18", "28", "17", "30"},
    };

    public String mrichtigeAntwort[] = {"Katze", "28"};

    public String getFrage(int a) {
        String Frage = mFrage[a];
        return Frage;

    }

    public String getAuswahl1(int a) {
        String auswahl = mAuswahl[a][0];
        return auswahl;


    }

    public String getAuswahl2(int a) {
        String auswahl = mAuswahl[a][1];
        return auswahl;

    }

    public String getAuswahl3(int a) {
        String auswahl = mAuswahl[a][2];
        return auswahl;
    }

    public String getAuswahl4(int a) {
        String auswahl = mAuswahl[a][3];
        return auswahl;

    }

public String getrichtigeAntwort (int a){
    String antwort = mrichtigeAntwort[a];
return antwort;
}
}

danke schon mal im vorraus[/SIZE]
 

brilzi89

Bekanntes Mitglied
Hallo Robat,
im LogCat wird auch kein Fehler angezeigt :/
im Manifest ist meine Activity als Launcher Activity eingetragen :/
weis nich mehr weiter....
 

brilzi89

Bekanntes Mitglied
hier aber der code vom Manifest
Java:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="knowpo.knowpo.spas.de.knowpo">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity

            android:name="MainActivity">

        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
 

Robat

Top Contributor
Benutzt du irgendwelche externen Frameworks die das Abstürzen der App erklären könnten?
Hast du den Jack-Compiler aktiviert?
Mach mal im Logcat alle Filter raus und schau noch mal nach auffälligen Warnungen / Errors. (Wenn die App abstürzt den Dialog nicht wegdrücken sondern erst nach Fehlern schauen).
Gibt es sonst noch relevante Dateien die deine App beinhaltet? Eventuell die Layout-XML Datei, fehlerhafte Value-Dateien?
 

walex

Mitglied
Ich würde sagen, vor "MainActivity" gehört ein Punkt... Dann findet er auch die activity

Java:
        <activity

            android:name="MainActivity"> <-- Hier

        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
walex
 

brilzi89

Bekanntes Mitglied
Benutzt du irgendwelche externen Frameworks die das Abstürzen der App erklären könnten?
Hast du den Jack-Compiler aktiviert?
Mach mal im Logcat alle Filter raus und schau noch mal nach auffälligen Warnungen / Errors. (Wenn die App abstürzt den Dialog nicht wegdrücken sondern erst nach Fehlern schauen).
Gibt es sonst noch relevante Dateien die deine App beinhaltet? Eventuell die Layout-XML Datei, fehlerhafte Value-Dateien?
Da ich neu in der Welt von Java und Android Studio bin , sagt mir das mit dem Frameworks und dem Jack Compiler nichts XD. Vll kannst du mich aufklären? :)
 

Robat

Top Contributor
Das die Wahrscheinlichkeit recht gering ist das der Fehler daher kommt.
Hast du meine Hinweise / Fragen aus den anderen Post
...
Mach mal im Logcat alle Filter raus und schau noch mal nach auffälligen Warnungen / Errors. (Wenn die App abstürzt den Dialog nicht wegdrücken sondern erst nach Fehlern schauen).
Gibt es sonst noch relevante Dateien die deine App beinhaltet? Eventuell die Layout-XML Datei, fehlerhafte Value-Dateien?

mal angeschaut?
 

brilzi89

Bekanntes Mitglied
ja hab im Logcat alle Filter raus und hab die App mal gestartet, aber konnte mit den Hinweisen nix anfangen, google hat auch nicht wirklich weitergeholfen :/
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
AGW App schließt nach 2 Sekunden Android & Cross-Platform Mobile Apps 2
S Android App schließt Android & Cross-Platform Mobile Apps 4
X Was passiert wenn man die App (gewaltsam) schließt Android & Cross-Platform Mobile Apps 2
Kidao Wie schließt man ein Midlet über Tasten? Android & Cross-Platform Mobile Apps 3
AllBlack Auf der Suche nach einem App-Entwickler Android & Cross-Platform Mobile Apps 1
J Android zugrif auf Thread nach Handy drehen. Android & Cross-Platform Mobile Apps 10
ruutaiokwu Android Daten von "Activity A" nach "Activity B" umleiten? Android & Cross-Platform Mobile Apps 13
A Android-Studio: 2. Layout nach kurzer Zeit aufzeigen Android & Cross-Platform Mobile Apps 2
B Profilpic wird nach anmeldung nicht angezeigt. Android & Cross-Platform Mobile Apps 2
J BLOB nach dem Download unbrauchbar Android & Cross-Platform Mobile Apps 0
J Android Nach Appsprachenänderung die Systemsprache ermitteln Android & Cross-Platform Mobile Apps 2
G App wird nach Installation auf Smartphone beendet Android & Cross-Platform Mobile Apps 1
B Android wie kann ich in einer xml nach bestimme item suchen (DOM) Android & Cross-Platform Mobile Apps 7
Fischkralle Android Nach Textdateien in Ordner suchen Android & Cross-Platform Mobile Apps 5
V Android Fehlermeldung beim Öffnen von Eclipse nach Installation der Android Erweiterung Android & Cross-Platform Mobile Apps 4
T Android Nach Buttonclick neu laden Android & Cross-Platform Mobile Apps 3
B Android Activity nach gedrückte Returntaste weiterlaufen lassen Android & Cross-Platform Mobile Apps 2
B Android ringProgressDialog nach Erfolg Button einfärben Android & Cross-Platform Mobile Apps 2
N PriceScannerApp: warum wird nach dem Scannen Display gleich schwarz? Android & Cross-Platform Mobile Apps 4
L Android Bildschirm bleibt dunkel nach neustarten der App nach betätigen des Home-Buttons Android & Cross-Platform Mobile Apps 3
N Android EditText.setError() funktioniert nicht nach Rotation Android & Cross-Platform Mobile Apps 1
B Android Button erstellen nach Vorlage Android & Cross-Platform Mobile Apps 4
L Android Button mit Pfeil nach rechts Android & Cross-Platform Mobile Apps 1
M Android App startet nach Tastensperre neu Android & Cross-Platform Mobile Apps 3
P Android Nach Animation Layout auf alten Platz Android & Cross-Platform Mobile Apps 3
G Werteübergabe nach unbestimmter Zeit Android & Cross-Platform Mobile Apps 28
A Fehlermeldung nach Neuinstallation von Eclipse/bestehenden Projekten... Android & Cross-Platform Mobile Apps 2
E Android App stürzt nach Modifizierung ab Android & Cross-Platform Mobile Apps 2
N Textview macht immer nach einem Beistrich einen Abstand Android & Cross-Platform Mobile Apps 6
K Apps durchsuchen nach verwendeter Methode Android & Cross-Platform Mobile Apps 4
M Android MediaRecorder - Crash nach 2. Start Android & Cross-Platform Mobile Apps 2
S rms recordstore bleibt nach schießen der anwengung nicht erhalten Android & Cross-Platform Mobile Apps 4
M Text in txt-Datei schreiben und nach ABC sortieren? Android & Cross-Platform Mobile Apps 2
H FileConnection: Frage nach Dateisystem-Zugriff unterdrücken Android & Cross-Platform Mobile Apps 5
K suche nach der richtigen dokumentationh Android & Cross-Platform Mobile Apps 2
S ein String nach vorgegebenen Zeichen teilen Android & Cross-Platform Mobile Apps 3
L Ungültiges Java-Archiv (jar) nach Programmentwicklung Android & Cross-Platform Mobile Apps 4
M Unable to start Gauge Intellij plugin Android & Cross-Platform Mobile Apps 3
J error: <identifier> expected error: illegal start of type "Wo ist der Fehler?" Android & Cross-Platform Mobile Apps 5
M Android Start von mehreren Activitys Android & Cross-Platform Mobile Apps 3
P Android Android-App Crash - Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 2
K MediaPlayer Soundklasse Start und Stop (stop funktioniert nicht) Android & Cross-Platform Mobile Apps 1
A App wird bei start des Timers beendet Android & Cross-Platform Mobile Apps 1
M Fehler ohne Sinn? java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 11
B java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 2
B Android GameLoopThread stürzt beim 2ten start der App ab? Android & Cross-Platform Mobile Apps 4
D Start/Stop Bit per Bluetooth von PC zu PC, oder PCtoHandy Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben