我的移动设备(Android)和PC模拟器(来自Android Stdio)使用相同的代码并同时显示不同的结果。
实际上,我认为仿真器正在根据我的代码运行,但我的手机却没有运行。
实际上,“ toast”类使它们之间有所不同.....
这里给出了一小部分代码
public void onClick(View v) {
if(v.getId()==R.id.imageTest)
{
Toast.makeText(this,"Thanks for clicking Image",Toast.LENGTH_SHORT).show();
//this portion not working properly
//emulator run this portion properly but mobile is not....
}
try {
String str1 = text1.getText().toString();
String str2 = text2.getText().toString();
double num1 = Double.parseDouble(str1);
double num2 = Double.parseDouble(str2);
if (v.getId() == R.id.plus) {
result.setText("Result: " + (num1 + num2));
}
else if (v.getId() == R.id.minus) {
result.setText("Result: " + (num1 - num2));
}
else if (v.getId() == R.id.multiple) {
result.setText("Result: " + (num1 * num2));
}
else if (v.getId() == R.id.divider) {
result.setText("Result: " + (num1 / num2));
}
} catch (NumberFormatException e) {
Toast.makeText(this, "Please enter number", Toast.LENGTH_SHORT).show();
}
在这种情况下,我该怎么办.. ?? 以及背后的原因是什么......
我的手机是三星A20。 我的android studio模拟器手机是Google Pixel2