J'utilise une instruction if-else avec une préférence partagée, mais elle se bloque. Mon code:instruction ifelse de préférence partagée
button = (Button) findViewById(R.id.Ferdig1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences skuule = getSharedPreferences("skule", Context.MODE_PRIVATE);
String skuleString = skuule.getString("skule", "");
if (skuleString == "Vel eit alternativ..") {
Toast.makeText(MainActivity.this, "Vel eit alternativ...", Toast.LENGTH_SHORT).show();
}
else if (skuleString != "Vel eit alternativ..") {
Intent myIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(myIntent);
}
}
});
Quand "skulestring" est pas égal à "Vel eit Alternativ .." il fonctionne et il commence la nouvelle activité. Mais quand il est égal à "Vel eit alternativ ..", l'application se bloque.
Mon journal d'erreur:
10-09 16:31:53.543 15146-15146/com.heli.minvekeplan E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.heli.minvekeplan, PID: 15146
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.heli.minvekeplan/com.heli.minvekeplan.SecondActivity}: com.google.firebase.database.DatabaseException: Invalid Firebase Database path: Vel eit alternativ.... Firebase Database paths must not contain '.', '#', '$', '[', or ']'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by: com.google.firebase.database.DatabaseException: Invalid Firebase Database path: Vel eit alternativ.... Firebase Database paths must not contain '.', '#', '$', '[', or ']'
at com.google.android.gms.internal.zzbqh.zzjm(Unknown Source)
at com.google.firebase.database.DatabaseReference.child(Unknown Source)
at com.heli.minvekeplan.SecondActivity.onCreate(SecondActivity.java:82)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Merci pour aider! :)
Lire vous LogCat il indique clairement que ** * Les chemins de base de données Firebase ne doivent pas contenir '.', '#', '$', '[' Ou ']' *** –
Voir 'Les chemins de base de données Firebase ne doivent pas contenir'. ',' # ',' $ ' , '[', or ']' –
http://stackoverflow.com/questions/513832 En outre, l'exception se produit dans 'SecondActivity', pas' MainActivity'. –