Hallo Community Ich bin Hamza und ich bin neu in Android-Entwicklung Ich folgte zu viele Tutorials und das Beste ist Herr Rob percival eins in UDEMY, und ich erschaffe jetzt einfach Gehirn-Spiel-App, die berechnen, wie viele Operationen können Sie in einer Minute lösen und nach der Codierung der App wird nicht einmal Mittagessen es stapelt bei der Nachricht leider App hat aufgehört, danke für die Hilfe bei der Fehlersuche den Code, weil ich nicht will schauen Sie sich keinen Code dank des von Ihnen sehr viel ichleider App hat Bug in Gehirn Spiel App gestoppt
JAVA MAIN CODE schätzen:
package com.example.hfpro.braintrainer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// Layouts Pointers
final TextView counter = (TextView)findViewById(R.id.counter) ;
final TextView operation = (TextView)findViewById(R.id.operation) ;
final TextView button1 = (TextView) findViewById(R.id.choice1) ;
final TextView button2 = (TextView) findViewById(R.id.choice2) ;
final TextView button3 = (TextView) findViewById(R.id.choice3) ;
final TextView button4 = (TextView) findViewById(R.id.choice4) ;
final TextView total = (TextView) findViewById(R.id.total) ;
final TextView result = (TextView) findViewById(R.id.result) ;
final Button start = (Button) findViewById(R.id.start) ;
int counterNumber ;
int correctResult ;
int score = 0 ;
int levels = 1 ;
Random random = new Random() ;
public void operation(View view)
{
String temp = String.valueOf(score)+"/" + String.valueOf(levels) ;
total.setText(temp);
int num1 = Math.abs(random.nextInt()%50) ;
int num2 = Math.abs(random.nextInt()%50) ;
correctResult = num1 + num2 ;
temp = String.valueOf(num1) + " + " +String.valueOf(num2) + " = ? " ;
operation.setText(temp);
// set the correct result in a result suggetoin
int correctResultPosition = Math.abs(random.nextInt()%4) ;
switch (correctResultPosition)
{
case 0 :
button1.setText(String.valueOf(correctResult));
break;
case 1 :
button2.setText(String.valueOf(correctResult));
break;
case 2 :
button3.setText(String.valueOf(correctResult));
break;
case 3 :
button4.setText(String.valueOf(correctResult));
break;
default:
}
}
public void start(final View view)
{
// quetions() ;
counter.setText("60");
start.animate().alpha(0).setDuration(500) ;
// timer
final Handler handler = new Handler() ;
Runnable runnable = new Runnable() {
@Override
public void run() {
counterNumber = Integer.valueOf((String)counter.getText()) ;
counterNumber -- ;
if(counterNumber == 0)
{
//timeFinished
String res = "Time is up your score is :"+ String.valueOf(score) + " :::";
result.setText(res);
}
counter.setText(String.valueOf(counterNumber));
handler.postDelayed(this , 1000) ;
}
} ;
handler.post(runnable) ;
}
public void checkResult(View view)
{
switch (view.getId())
{
case R.id.choice1 :
if(correctResult == Integer.valueOf((String)button1.getText()))
{
score++ ;
String str = String.valueOf(score) + "/" + String.valueOf(levels) ;
total.setText(str);
}
levels++ ;
break;
case R.id.choice2 :
if(correctResult == Integer.valueOf((String)button2.getText()))
{
score++ ;
String str = String.valueOf(score) + "/" + String.valueOf(levels) ;
total.setText(str);
}
levels++ ;
break;
case R.id.choice3 :
if(correctResult == Integer.valueOf((String)button3.getText()))
{
score++ ;
String str = String.valueOf(score) + "/" + String.valueOf(levels) ;
total.setText(str);
}
levels++ ;
break;
case R.id.choice4:
if(correctResult == Integer.valueOf((String)button4.getText()))
{
score++ ;
String str = String.valueOf(score) + "/" + String.valueOf(levels) ;
total.setText(str);
}
levels++ ;
break;
default:
}
this.operation(view);
}
}
und dies ist der XML-Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.hfpro.braintrainer.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="150dp"
android:layout_height="100dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/RES1"
android:id="@+id/choice1"
android:layout_gravity="left|center_vertical"
android:background="#e1e2b7" />
<TextView
android:layout_width="150dp"
android:layout_height="100dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/RES2"
android:id="@+id/choice2"
android:layout_gravity="right|center_vertical"
android:background="#6b4ec8" />
<TextView
android:layout_width="150dp"
android:layout_height="100dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/RES3"
android:id="@+id/choice3"
android:layout_gravity="left|bottom"
android:background="#65ba8c" />
<TextView
android:layout_width="150dp"
android:layout_height="100dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/RES4"
android:id="@+id/choice4"
android:layout_gravity="right|bottom"
android:background="#dcb27e" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start"
android:id="@+id/start"
android:layout_gravity="center"
android:onClick="start" />
<TextView
android:layout_width="wrap_content"
android:layout_height="43dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/operation"
android:id="@+id/operation"
android:layout_gravity="center_horizontal|top"
android:onClick="operation" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/result"
android:id="@+id/counter"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/counter"
android:id="@+id/total"
android:layout_gravity="right|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/result"
android:id="@+id/result"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
</RelativeLayout>
und ich verwende string.xml und da ist er:
<resources>
<string name="app_name">BrainTrainer</string>
<string name="RES1">RES1</string>
<string name="RES2">RES2</string>
<string name="RES3">RES3</string>
<string name="RES4">RES4</string>
<string name="operation">operation</string>
<string name="counter">60</string>
<string name="level">0/1</string>
<string name="start">Start</string>
<string name="result">result</string>
</resources>
Veröffentlichen Sie Ihre Stack-Ablaufverfolgung. Es wird dir sagen, wo das Problem ist und was es ist. –