Hallo, Ich habe folgendes Problem. Jedes mal wenn ich eine bestimmte Activity starten möchte Crasht meine App.
Hier die MainActivity womit ich eine andere Activity aufrufen möchte, welche dann Crasht:
Java
package com.bekunse.konterbierdastrinkspiel;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.widget.CheckBox;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
ImageButton ImageSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageSubmit=findViewById(R.id.WeiterButton);
final CheckBox KapitoCheck =findViewById(R.id.KapitoBox);
KapitoCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (KapitoCheck.isChecked()){
ImageSubmit.setVisibility(View.VISIBLE);
}
else{
ImageSubmit.setVisibility(View.INVISIBLE);
}
}
});
ImageSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MainMenu.class));
}
});
}
}
Alles anzeigen
Die Activity, die Crasht:
Java
package com.bekunse.konterbierdastrinkspiel;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.SeekBar;
public class MainMenu extends AppCompatActivity {
//get Seekbar Maximum, Element and Progress
SeekBar seekBarPlayer1 = findViewById(R.id.seekBarPlayer);
//int maxPlayer = seekBarPlayer.getMax();
int CurrentPlayerNumber = seekBarPlayer1.getProgress();
//get the Names of the players
final EditText player1 = findViewById(R.id.player1);
final EditText player2 = findViewById(R.id.player2);
final EditText player3 = findViewById(R.id.player3);
final EditText player4 = findViewById(R.id.player4);
final EditText player5 = findViewById(R.id.player5);
final EditText player6 = findViewById(R.id.player6);
final EditText player7 = findViewById(R.id.player7);
final EditText player8 = findViewById(R.id.player8);
final EditText player9 = findViewById(R.id.player9);
final EditText player10 = findViewById(R.id.player10);
//put the player Names in Strings
String playerName1 = player1.getText().toString();
String playerName2 = player2.getText().toString();
String playerName3 = player3.getText().toString();
String playerName4 = player4.getText().toString();
String playerName5 = player5.getText().toString();
String playerName6 = player6.getText().toString();
String playerName7 = player7.getText().toString();
String playerName8 = player8.getText().toString();
String playerName9 = player9.getText().toString();
String playerName10 = player10.getText().toString()
ImageButton NextBTN = findViewById(R.id.WeiterButton);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
if (CurrentPlayerNumber == 2) {
player3.setVisibility(View.GONE);
player3.setText("");
player4.setVisibility(View.GONE);
player4.setText("");
player5.setVisibility(View.GONE);
player5.setText("");
player6.setVisibility(View.GONE);
player6.setText("");
player7.setVisibility(View.GONE);
player7.setText("");
player8.setVisibility(View.GONE);
player8.setText("");
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 3) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.GONE);
player4.setText("");
player5.setVisibility(View.GONE);
player5.setText("");
player6.setVisibility(View.GONE);
player6.setText("");
player7.setVisibility(View.GONE);
player7.setText("");
player8.setVisibility(View.GONE);
player8.setText("");
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 4) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.GONE);
player5.setText("");
player6.setVisibility(View.GONE);
player6.setText("");
player7.setVisibility(View.GONE);
player7.setText("");
player8.setVisibility(View.GONE);
player8.setText("");
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 5) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.VISIBLE);
player6.setVisibility(View.GONE);
player6.setText("");
player7.setVisibility(View.GONE);
player7.setText("");
player8.setVisibility(View.GONE);
player8.setText("");
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 6) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.VISIBLE);
player6.setVisibility(View.VISIBLE);
player7.setVisibility(View.GONE);
player7.setText("");
player8.setVisibility(View.GONE);
player8.setText("");
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 7) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.VISIBLE);
player6.setVisibility(View.VISIBLE);
player7.setVisibility(View.VISIBLE);
player8.setVisibility(View.GONE);
player8.setText("");
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 8) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.VISIBLE);
player6.setVisibility(View.VISIBLE);
player7.setVisibility(View.VISIBLE);
player8.setVisibility(View.VISIBLE);
player9.setVisibility(View.GONE);
player9.setText("");
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 9) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.VISIBLE);
player6.setVisibility(View.VISIBLE);
player7.setVisibility(View.VISIBLE);
player8.setVisibility(View.VISIBLE);
player9.setVisibility(View.VISIBLE);
player10.setVisibility(View.GONE);
player10.setText("");
}
if (CurrentPlayerNumber == 10) {
player3.setVisibility(View.VISIBLE);
player4.setVisibility(View.VISIBLE);
player5.setVisibility(View.VISIBLE);
player6.setVisibility(View.VISIBLE);
player7.setVisibility(View.VISIBLE);
player8.setVisibility(View.VISIBLE);
player9.setVisibility(View.VISIBLE);
player10.setVisibility(View.VISIBLE);
}
}
}
Alles anzeigen
Wenn mir jemand helfen kann wäre das echt super, vielen Dank. Dei XML Datein machen diesen Beitrag zu lang. Wenn doch noch benötigt gerne nachfragen