我试图为Android制作应用程序。经过对我自己的设备的一些测试后,我在手机和模拟器上做得很好,它的效果非常好。
但现在奇怪的东西开始了!我做了一个调试APK发送给我的一个朋友,所以他可以安装它并测试它。但是在此特定按钮上单击应用程序崩溃。我们认为可能是它的手机,并与其他2部手机(所有不同的型号或品牌)进行了另一次测试。同样的事情发生了。
我们认为让我们尝试使用Android Studio在我的朋友手机上安装应用程序(与我的初始测试相同),此时应用程序工作在他的手机上完美。
所以我制作了另一张APK,并在一些手机上测试了它,希望它可行。但不,从调试/发布APK安装后它仍然崩溃。
这里我有按钮点击后触发的代码。
stopButton = (Button) findViewById(R.id.stopButton);
stopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (stopButton.getText().equals("Next")) {
Intent startIntent = new Intent(Timer.this, MyActivity.class);
Timer.this.startActivity(startIntent);
} else if (stopButton.getText().equals("Show income")) {
//
HashMap<String, String> shitList = dbTool.getWageInfo();
if (shitList.get("type").equals("0")) {
stringWageHour = shitList.get("hourWage");
amountPayed = Double.parseDouble(stringWageHour);
setAmountPayed(amountPayed);
} else {
stringHours = shitList.get("hourMonth");
stringMonthPay = shitList.get("wageMonth");
doubleHours = Double.parseDouble(stringHours);
doubleMonthPay = Double.parseDouble(stringMonthPay);
calculateHours = doubleMonthPay / doubleHours;
setAmountPayed(calculateHours);
}
getText = textTimer.getText().toString();
amountMinuts = Double.parseDouble(getText);
minutWage = amountMinuts / 60;
FinalAmount = amountPayed * minutWage;
formatter = NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
output = formatter.format(FinalAmount);
finalAmountString = String.valueOf(output);
textTimer.setText(finalAmountString);
HashMap<String, String> queryValuesMap = new HashMap<String, String>();
queryValuesMap.put("time", getText);
queryValuesMap.put("earned", finalAmountString);
dbTool.insertShit(queryValuesMap);
stopButton.setText("Next");
} else {
timeSwap += timeInMillies;
myHandler.removeCallbacks(updateTimerMethod);
string = textTimer.getText().toString();
tmp = string.split(":");
amountSeconds = Double.parseDouble(tmp[1]);
amountMinuts = Double.parseDouble(tmp[0]);
minutsSec = amountSeconds / 60;
formatter = NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
output = formatter.format(minutsSec);
minutsSecFinal = Double.parseDouble(output);
minuts = minutsSecFinal + amountMinuts;
Final = String.valueOf(minuts);
textTimer.setText(Final);
stopButton.setText("Show income");
}
}
});
}
private Runnable updateTimerMethod = new Runnable() {
public void run() {
timeInMillies = SystemClock.uptimeMillis() - startTime;
finalTime = timeSwap + timeInMillies;
seconds = (int) (finalTime / 1000);
minutes = seconds / 60;
seconds = seconds % 60;
textTimer.setText("" + minutes + ":"
+ String.format("%02d", seconds));
myHandler.postDelayed(this, 0);
}
};
当文字是&#34;停止&#34>时按钮失败并将使用else语句。 因为我不能在正常调试时重新创建问题我没有日志(如果有人有想法创建一个我也会有帮助)
编辑: 来自google play dev的错误代码:
java.lang.NumberFormatException: Invalid double: "0,12"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:269)
at java.lang.Double.parseDouble(Double.java:295)
at jmsbrk.crappapp.Timer$1.onClick(Timer.java:190)
at android.view.View.performClick(View.java:4445)
at android.view.View$PerformClick.run(View.java:18429)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5088)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
工资信息&#34;
public HashMap<String,String> getWageInfo(){
HashMap<String,String> wageMap = new HashMap<String,String>();
SQLiteDatabase database = this.getWritableDatabase();
String selectQuery = "SELECT * FROM wage ";
Cursor cursor = database.rawQuery(selectQuery,null);
if(cursor.moveToFirst()){
do{
wageMap.put("wageId",cursor.getString(0));
wageMap.put("type",cursor.getString(1));
wageMap.put("hourWage",cursor.getString(2));
wageMap.put("wageMonth",cursor.getString(3));
wageMap.put("hourMonth",cursor.getString(4));
}while (cursor.moveToNext());
}
return wageMap;
}
答案 0 :(得分:1)
为每个按钮调用相同的功能
<Button
android:id="@+id/stopButton"
android:layout_width="50dp"
android:layout_height="47dp"
android:layout_alignBottom="@+id/mainlayout1"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/mainlayout1"
android:layout_marginRight="10dp"
android:onClick="CallMe"
android:background="@drawable/btnround"
android:text="@string/go"
android:textColor="@android:color/white" />
调用该函数并按此操作
public void ClickMe(查看视图) {
switch (view.getId()) {
case R.id.stopbutton:
//dosomething
break;
default:
break;
}
}