Я создаю приложение, пытаясь установить результат серии нажатий на кнопки как текст TextView в макете. Моя проблема в том, что приложение вылетает, когда я нажимаю последнюю кнопку в последнем действии, где должен быть показан этот результат. Я размещаю код здесь, желаю, чтобы вы мне помогли. Спасибо.
XML:
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:background = "@drawable/a"
android:orientation = "vertical"
tools:context = ".Riepilogo">
<TextView
android:id = "@+id/textView6"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true"
android:text = "Riepilogo"
android:textColor = "@android:color/holo_red_dark"
android:textSize = "24sp"
android:textStyle = "italic" />
<Button
android:id = "@+id/button"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/textView6"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT1"
android:text = "TAV. 1"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button2"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT2"
android:text = "TAV. 2"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button16"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button2"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT3"
android:text = "TAV. 3"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button17"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button16"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT4"
android:text = "TAV. 4"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button19"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button17"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT5"
android:text = "TAV. 5"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button20"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button19"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT6"
android:text = "TAV. 6"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button22"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button20"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT7"
android:text = "TAV. 7"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button23"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button22"
android:layout_alignParentStart = "true"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT8"
android:text = "TAV. 8"
android:textStyle = "bold"
android:layout_alignParentLeft = "true" />
<Button
android:id = "@+id/button24"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button23"
android:layout_alignParentStart = "true"
android:layout_alignParentLeft = "true"
android:layout_marginStart = "0dp"
android:layout_marginLeft = "0dp"
android:layout_marginTop = "-2dp"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT9"
android:text = "TAV. 9"
android:textStyle = "bold" />
<Button
android:id = "@+id/button26"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button24"
android:layout_alignParentStart = "true"
android:layout_alignParentLeft = "true"
android:layout_marginStart = "0dp"
android:layout_marginLeft = "0dp"
android:layout_marginTop = "2dp"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT10"
android:text = "TAV. 10"
android:textStyle = "bold" />
<Button
android:id = "@+id/button27"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button26"
android:layout_alignParentStart = "true"
android:layout_alignParentLeft = "true"
android:layout_marginStart = "0dp"
android:layout_marginLeft = "0dp"
android:layout_marginTop = "-2dp"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT11"
android:text = "TAV. 11"
android:textStyle = "bold" />
<Button
android:id = "@+id/button28"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_below = "@+id/button27"
android:layout_alignParentStart = "true"
android:layout_alignParentLeft = "true"
android:layout_marginStart = "0dp"
android:layout_marginLeft = "0dp"
android:layout_marginTop = "4dp"
android:layout_marginBottom = "-11dp"
android:onClick = "OnButtonClickT12"
android:text = "TAV. 12"
android:textStyle = "bold" />
<TextView
android:id = "@+id/ttvv"
android:layout_width = "228dp"
android:layout_height = "455dp"
android:layout_below = "@+id/textView6"
android:layout_alignStart = "@+id/textView6"
android:layout_alignLeft = "@+id/textView6"
android:autoText = "false"
android:clickable = "false"
android:cursorVisible = "false"
android:numeric = "decimal"
android:text = "@string/rpg" />
</RelativeLayout>
ДЖАВА:
public class Riepilogo extends Tavolo {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_riepilogo);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
String t=String.valueOf(R.string.rpg); //rpg is the id of text in TextView
public void OnButtonClickT1(View v){
if (riep1.isEmpty() || tav1==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 1: "+riep1+" TOTALE: "+tav1+" EURO");
}
}
public void OnButtonClickT2(View v){
if (riep2.isEmpty() || tav2==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 2: "+riep2+" TOTALE: "+tav2+" EURO");}
}
public void OnButtonClickT3(View v){
if (riep3.isEmpty() || tav3==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 3: "+riep3+" TOTALE: "+tav3+" EURO");}
}
public void OnButtonClickT4(View v){
if (riep4.isEmpty() || tav4==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 4: "+riep4+" TOTALE: "+tav4+" EURO");}
}
public void OnButtonClickT5(View v){
if (riep5.isEmpty() || tav5==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 5: "+riep5+" TOTALE: "+tav5+" EURO");}
}
public void OnButtonClickT6(View v){
if (riep6.isEmpty() || tav6==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 6: "+riep6+" TOTALE: "+tav6+" EURO");}
}
public void OnButtonClickT7(View v){
if (riep7.isEmpty() || tav7==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 7: "+riep7+" TOTALE: "+tav7+" EURO");}
}
public void OnButtonClickT8(View v){
if (riep8.isEmpty() || tav8==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 8: "+riep8+" TOTALE: "+tav8+" EURO");}
}
public void OnButtonClickT9(View v){
if (riep9.isEmpty() || tav9==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 9: "+riep9+" TOTALE: "+tav9+" EURO");}
}
public void OnButtonClickT10(View v){
if (riep10.isEmpty() || tav10==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 10: "+riep10+" TOTALE: "+tav10+" EURO");}
}
public void OnButtonClickT11(View v){
if (riep11.isEmpty() || tav11==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 11: "+riep11+" TOTALE: "+tav11+" EURO");}
}
public void OnButtonClickT12(View v){
if (riep12.isEmpty() || tav12==0){
Toast.makeText(getBaseContext(), "Niente da mostrare qui" ,
Toast.LENGTH_LONG).show();
}
else{
t=("TAVOLO 12: "+riep12+" TOTALE: "+tav12+" EURO");}
}
}
вы должны использовать this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); до вашего setContentView()
спасибо за интерес но это не проблема ... все действия "код ориентации" после и работают ...




Добро пожаловать в StackOverflow! Не могли бы вы также опубликовать трассировку стека ошибки при сбое вашего приложения? Это можно увидеть в logcat