Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 :)

share|improve this question
Please post the LogCat as well. – Sam Oct 4 '12 at 17:57
Hi, first try to do a try/catch and log the exception trace. You can see how in [Android's docs][1]: . You can also try to create an Android Virtual Machine with the configurations of your specific device. Remeber to include the permissions in the manifest to open intents. [1]: developer.android.com/tools/debugging/debugging-log.html – Christian Vielma Oct 4 '12 at 18:01
@Sam sorry i dont got the logcat at the moment but i hope i can debug it in a few days and then i'll instantly post it. – WannaBeAHero Oct 4 '12 at 18:11
@ChristianVielma i also posted the manifest.xml but i've got some problems with the permissions(theres also an sqlite database but it doesnt require any permissions right?) Please tell me if theres an error in the manifest.xml. – WannaBeAHero Oct 4 '12 at 18:15
@WannaBeAHero Hi which intent are you trying to execute? Also, in the first code I see prefs.savePrefs(i_budget); but I can't see prefs declared. Have you tried to debug in which branch does it fail? Also you can try to determine if the intent will resolve first. Maybe is an app that is not available in one of the devices? – Christian Vielma Oct 4 '12 at 19:53
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.