My First Android App crashes on some random devices independent from android version or device model when i try to start an intent or clicking a button and setting SharedPreferences**. I really can't find the error and i don't understand why it works on most devices.
Example : device 1 : Galaxy Nexus, Android 4.1.1 --> works device 2 : Galaxy Nexus, Android 4.1.1 --> doesn't work
I found out that it throws a TargetInvocationException when it crashes. But i can't debug it serously because it works perfectly on my device.
Is this a know error or am i doing something wrong? Please help me..
Here's one of the methods that are called when it crashes...
public void saveBudget(View view){
double i_budget = 0;
if ((budget_input.getText().toString().trim().equals("")) && budget.getMax()== 0){
budget.setMax(0);
Toast toast = Toast.makeText(this, "Bitte Budget definieren!", Toast.LENGTH_SHORT); //Message ausgeben
toast.show();
}else if((budget_input.getText().toString().trim().equals("")) && (budget.getMax() != 0)){
//Nothing
}else if(round(Double.parseDouble(budget_input.getText().toString().trim())) < budget.calcBudget() && !budget.getEreignisse().isEmpty()){
i_budget = budget.getMax();
budget.setMax(i_budget);
Toast toast = Toast.makeText(this, "Bitte zuerst alle Ereignisse löschen!", Toast.LENGTH_SHORT); //Message ausgeben
toast.show();
}else{
InputMethodManager inputManager = (InputMethodManager) this. getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow( this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
i_budget = round(Double.parseDouble(budget_input.getText().toString().trim())); //Max setzen
budget.setMax(i_budget);
Toast toast = Toast.makeText(this, "Budget auf " + budget.getMax() + " Fr. gesetzt!", Toast.LENGTH_SHORT); //Message ausgeben
toast.show();
prefs.savePrefs(i_budget);
setInput();
}
and here's the preferences class...
public class Preferences extends BaseActivity {
public static final String PREFS_NAME = "prefs";
public static final String MAXBUDGET = "maxBudget";
private SharedPreferences settings;
private Editor editor;
public Preferences(Context context){
this.settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_WORLD_READABLE);
this.editor = settings.edit();
}
public double getPrefs() {
String prefString = "";
prefString = Float.toString(settings.getFloat(MAXBUDGET, 0));
return Double.parseDouble(prefString);
}
public void savePrefs(Double max) {
editor.putFloat(MAXBUDGET, (float)round(max)); //Shared Prefs Max setzen
editor.commit();
}
public void resetPrefs(){
editor.putFloat(MAXBUDGET, 0); //Shared Prefs auf 0 setzen
editor.commit();
}
And the Manifest.xml...
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.bbw.modul226.buchhaltung"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<supports-screens android:xlargeScreens="true" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomTheme" >
<activity
android:name="ch.bbw.activities.AndroidBuchhaltungActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="ch.bbw.activities.BudgetActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ch.bbw.activities.SchuldenverwaltungActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ch.bbw.activities.KreditorenListeActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ch.bbw.activities.DebitorenListeActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ch.bbw.activities.PropertiesActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ch.bbw.activities.InfoActivity"
android:screenOrientation="portrait" >
</activity>
</application>
</manifest>
10-05 13:42:40.447: E/AndroidRuntime(20813): FATAL EXCEPTION: main
10-05 13:42:40.447: E/AndroidRuntime(20813): java.lang.IllegalStateException: Could not execute method of the activity 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.view.View$1.onClick(View.java:3591) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.view.View.performClick(View.java:4084) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.view.View$PerformClick.run(View.java:16966) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.os.Handler.handleCallback(Handler.java:615) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.os.Handler.dispatchMessage(Handler.java:92) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.os.Looper.loop(Looper.java:137) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.app.ActivityThread.main(ActivityThread.java:4745) 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.reflect.Method.invokeNative(Native Method) 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.reflect.Method.invoke(Method.java:511) 10-05 13:42:40.447: E/AndroidRuntime(20813): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-05 13:42:40.447: E/AndroidRuntime(20813): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-05 13:42:40.447: E/AndroidRuntime(20813): at dalvik.system.NativeStart.main(Native Method) 10-05 13:42:40.447: E/AndroidRuntime(20813): Caused by: java.lang.reflect.InvocationTargetException 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.reflect.Method.invokeNative(Native Method) 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.reflect.Method.invoke(Method.java:511) 10-05 13:42:40.447: E/AndroidRuntime(20813): at android.view.View$1.onClick(View.java:3586) 10-05 13:42:40.447: E/AndroidRuntime(20813): ... 11 more 10-05 13:42:40.447: E/AndroidRuntime(20813): Caused by: java.lang.NumberFormatException: Invalid double: "58,00" 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.StringToReal.invalidReal(StringToReal.java:63) 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.StringToReal.parseDouble(StringToReal.java:269) 10-05 13:42:40.447: E/AndroidRuntime(20813): at java.lang.Double.parseDouble(Double.java:295) 10-05 13:42:40.447: E/AndroidRuntime(20813): at ch.bbw.activities.BaseActivity.round(BaseActivity.java:48) 10-05 13:42:40.447: E/AndroidRuntime(20813): at ch.bbw.activities.PropertiesActivity.saveBudget(PropertiesActivity.java:57) 10-05 13:42:40.447: E/AndroidRuntime(20813): ... 14 more
If you need more code samples just ask for them ;)
Hope you can help me :)