我正在为我的女儿构建数学应用程序 一切都很好-加,乘,除,间,升等
但是在第一次加载时减去它,第二次将应用程序挂起-我必须直接退出它,从ram中清除它,然后每次重新启动
日志猫未显示任何错误或夜间警告, 请指导我-我是初学者(实际上是第一个应用)
我的代码
@Bean(name = "GemfireClientProperties")
Properties gemfireClientProperties() {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("mcast-port", "0");
gemfireProperties.setProperty("log-level", "config");
return gemfireProperties;
}
@Bean(name = "GemfireClientPool")
PoolFactoryBean gemfireClientPool() {
PoolFactoryBean gemfirePool = new PoolFactoryBean();
gemfirePool.setRetryAttempts(1);
gemfirePool.setLocators(Collections.singletonList(new ConnectionEndpoint("localhost", 17202)));
return gemfirePool;
}
@Bean(name = "clientCache")
ClientCache clientCache(@Qualifier("GemfireClientProperties") Properties gemfireClientProperties) {
ClientCacheFactory clientCacheFactory = new ClientCacheFactory(gemfireClientProperties);
return clientCacheFactory.create();
}
GlobalOverride类。
package youtube.computers.mohammedi.kidsmath;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest.Builder;
import com.google.android.gms.ads.AdView;
import java.util.Random;
public class Subtract extends GlobalOverride implements OnClickListener {
int ans;
Button btn1;
Button btn2;
Button btn3;
Button btn4;
int max;
int n1;
int n2;
Random f16r;
int temp;
TextView txt_add;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView((int) R.layout.activity_subtract);
setTitle("Subtraction");
this.btn1 = findViewById(R.id.btn1);
this.btn2 = findViewById(R.id.btn2);
this.btn3 = findViewById(R.id.btn3);
this.btn4 = findViewById(R.id.btn4);
this.txt_add = (TextView) findViewById(R.id.txt_ascen);
this.btn1.setOnClickListener(this);
this.btn2.setOnClickListener(this);
this.btn3.setOnClickListener(this);
this.btn4.setOnClickListener(this);
this.max = getSharedPreferences("Math", 0).getInt("add", 10);
((AdView) findViewById(R.id.adView)).loadAd(new Builder().build());
generate();
}
public void onClick(View v) {
this.ans = Integer.parseInt((String) ((Button) v).getText());
if (this.ans == this.temp) {
generate();
} else {
Toast.makeText(this, "Incorrect", Toast.LENGTH_SHORT).show();
}
}
public void generate() {
this.n1 = GlobalOverride.getRand(1, this.max);
this.n2 = GlobalOverride.getRand(1, this.max);
if(n2>n1 && max<=20){
generate();
}
this.temp = this.n1 - this.n2;
this.txt_add.setText(this.n1 + " - " + this.n2 + " = ?");
int[] answer = new int[4];
int count = 0;
while (count <= 3) {
int random_integer = GlobalOverride.getRand(this.temp - 2, this.temp + 2);
if (!exists(random_integer, answer)) {
answer[count] = random_integer;
count++;
}
}
if (!exists(this.temp, answer)) {
answer[GlobalOverride.getRand(0, 3)] = this.temp;
}
this.btn1.setText(String.valueOf(answer[0]));
this.btn2.setText(String.valueOf(answer[1]));
this.btn3.setText(String.valueOf(answer[2]));
this.btn4.setText(String.valueOf(answer[3]));
}
public boolean exists(int number, int[] array) {
if (number == -1) {
return true;
}
for (int i : array) {
if (number == i) {
return true;
}
}
return false;
}
}
布局输出
答案 0 :(得分:1)
我不明白为什么您要在第一个if语句中递归调用generate()。我的怀疑是,这不是您想要的。您可能最终需要进行几层递归。 您可能想要在代码中添加一些注释,这将使理解变得更加容易。
如果您不想要负数,只需交换两个整数即可,而不用调用generate():
if(n2>n1 && max<=20){
int swap = n1;
n1 = n2;
n2 = swap;
}