Ich bin neu hier. Ich baue eine App, aber immer wenn es um den AlertDialog .show() geht, stürzt es ab. Ich habe überall im Internet recherchiert, konnte aber keine Lösung finden. Die meisten Fälle, die ich gefunden habe, haben ihr Problem behoben, indem sie 'Context' auf änderten. AlertDialog.Builder Beispiel = neu AlertDialog.Builder (Kontext) zu AlertDialog.Builder Beispiel = neu AlertDialog.Builder (MyActivity.this);App stürzt ab bei AlertDialog .show() - Ich habe eine Lösung gefunden
Aber das ist nicht mein Fall, ich benutze MyActivity.this alle lang und stürzt immer noch ab.
Hier ist mein Code:
eschallungssysteme Klasse MainActivity erweitert AppCompatActivity {
Button btMudaTela;
final Funcoes funcao = new Funcoes();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btMudaTela = (Button) findViewById(R.id.btMudaTela);
//Ao clicar no botão outra activity será aberta (ActivityCadastro)
btMudaTela.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
adb.setTitle("teste");
adb.setMessage("ok");
adb.create().show();
funcao.mudaActivity(MainActivity.this, ActivityCadastro.class);
finish();
}
});
}
}
Und hier ist log von Logcat auf meinem Gerät:
06-23 07:41:42.113 3303 3303 E AndroidRuntime: Process: com.example.teste.projetofinal, PID: 3303
06-23 07:41:42.113 3303 3303 E AndroidRuntime: at com.example.teste.projetofinal.MainActivity$1.onClick(MainActivity.java:46)
06-23 07:41:42.123 954 1367 W ActivityManager: Force finishing activity com.example.teste.projetofinal/.MainActivity
06-23 07:41:43.334 954 1602 I ActivityManager: Process com.example.teste.projetofinal (pid 3303) (adj 9) has died.
06-23 07:41:43.334 954 1454 I WindowState: WIN DEATH: Window{444ca450 u0 com.example.teste.projetofinal/com.example.teste.projetofinal.MainActivity}
06-23 07:50:39.406 6806 6806 W InstallAppProgress: Replacing package:com.example.teste.projetofinal
06-23 07:50:42.219 5389 5389 I Finsky : [1] com.google.android.finsky.verifier.impl.br.c(104): Verification complete: id=0, package_name=com.example.teste.projetofinal
06-23 07:50:42.960 954 1046 I PackageManager: Package com.example.teste.projetofinal codePath changed from /data/app/com.example.teste.projetofinal-19.apk to /data/app/com.example.teste.projetofinal-20.apk; Retaining data and using new
06-23 07:50:43.921 954 1046 W PackageManager: Code path for pkg : com.example.teste.projetofinal changing from /data/app/com.example.teste.projetofinal-19.apk to /data/app/com.example.teste.projetofinal-20.apk
06-23 07:50:43.921 954 1046 W PackageManager: Resource path for pkg : com.example.teste.projetofinal changing from /data/app/com.example.teste.projetofinal-19.apk to /data/app/com.example.teste.projetofinal-20.apk
06-23 07:50:45.592 954 1036 I CrashAnrDetector: onPackageUpdateFinished : com.example.teste.projetofinal
06-23 07:50:46.073 6987 6987 E dalvikvm: >>>>> com.example.teste.projetofinal [ userId:0 | appId:10200 ]
06-23 07:50:47.444 6987 6987 E AndroidRuntime: Process: com.example.teste.projetofinal, PID: 6987
06-23 07:50:47.444 6987 6987 E AndroidRuntime: at com.example.teste.projetofinal.MainActivity$1.onClick(MainActivity.java:40)
06-23 07:50:47.444 954 1602 W ActivityManager: Force finishing activity com.example.teste.projetofinal/.MainActivity
06-23 07:50:48.806 954 1602 I WindowState: WIN DEATH: Window{433e3670 u0 com.example.teste.projetofinal/com.example.teste.projetofinal.MainActivity}
06-23 07:50:48.836 954 1545 I ActivityManager: Process com.example.teste.projetofinal (pid 6987) (adj 9) has died.
06-23 07:50:51.188 3939 3939 E SPPClientService: [PackageInfoChangeReceiver] [handlePkgRemovedEvent] PackageName : com.example.teste.projetofinal, true, false
06-23 07:50:54.531 5389 5389 I Finsky : [1] com.google.android.finsky.externalreferrer.d.run(9): Package state data is missing for com.example.teste.projetofinal
06-23 07:50:55.792 3498 7271 I FontsPackageChangeOp: Package com.example.teste.projetofinal has no metadata
Ja !!! ! Schließlich fand ich Lösung hier nach 2 Tagen im Internet zu graben: Crash in AlertDialog builder when android suport library updated to 24
Sie importieren müssen diese für Ihre Alertdialog:
import android.app.AlertDialog;
statt dessen:
import android.support.v7.app.AlertDialog;
Bitte geben Sie die Ausnahme hinzufügen und Stack-Trace Sie empfangen. – ventiseis
Ich habe meinen Code in meine MainActivity (dasselbe Projekt) geändert, weil es leichter zu lesen ist und auch, weil das Problem das gleiche ist. Zeile 40 ist Zeile adb.create(). Show(); Das gleiche passiert, wenn es adb.show() ist; Ich habe auch Logcat hinzugefügt, das auf meinem Gerät läuft. –
hast du mich gerettet, danke! – luidgi27