0

can someone please help, I have been struggling with this piece of android code. It keeps throwing exceptions.

    try
    {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());//getPreferences(Context.MODE_PRIVATE);
        String str = sharedPref.getString(MainActivity.APP_DATA_KEY, "");
        _appData = FemChoiceAppData.deserialize(str);

        if (_appData == null)
            throw new Exception();
    } catch (Exception e)
    {
        Calendar cl = Calendar.getInstance(TimeZone.getDefault());
        int year = cl.get(Calendar.YEAR);
        int month = cl.get(Calendar.MONTH);
        int day = cl.get(Calendar.DAY_OF_MONTH);
        cl.set(year, month, day, 0, 0, 0);

        _appData = new FemChoiceAppData();
        _appData.CurrentMonth = Calendar.getInstance(TimeZone.getDefault());
        _appData.CurrentMonth.set(year, month, 1, 0, 0, 0);

        _appData.CurrentSettings = new FemChoiceSettings(cl.getTime(), 26, 6);
    }

    yearTV.setText(_appData.CurrentSettings.getStartDate().getYear());
    monthTV.setText(_appData.CurrentSettings.getStartDate().getMonth());
    dayTV.setText(_appData.CurrentSettings.getStartDate().getDay());

THIS IS THE EXCEPTION IT THROWS

  04-16 22:54:19.251: E/AndroidRuntime(2063): FATAL EXCEPTION: main
    04-16 22:54:19.251: E/AndroidRuntime(2063): java.lang.RuntimeException: Unable to start activity ComponentInfo{com../com...Settings}: android.content.res.Resources$NotFoundException: String resource ID #0x71
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.os.Handler.dispatchMessage(Handler.java:99)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.os.Looper.loop(Looper.java:130)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.ActivityThread.main(ActivityThread.java:3687)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at java.lang.reflect.Method.invokeNative(Native Method)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at java.lang.reflect.Method.invoke(Method.java:507)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at dalvik.system.NativeStart.main(Native Method)
    04-16 22:54:19.251: E/AndroidRuntime(2063): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x71
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.content.res.Resources.getText(Resources.java:201)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.widget.TextView.setText(TextView.java:2923)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at com...Settings.loadAppData(Settings.java:92)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at com...Settings.setup(Settings.java:64)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at com...Settings.onStart(Settings.java:49)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.Activity.performStart(Activity.java:3791)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
    04-16 22:54:19.251: E/AndroidRuntime(2063):     ... 11 more
1
  • I think the problem is while loading the resources not with Shared Preferences. Can you post the code for Settings.java(line 92)? Commented Apr 17, 2013 at 6:07

1 Answer 1

2

You're setting the text to integers. That makes it think you're passing it resources ids in your strings.xml file. You want to call yearTV.setText(String.valueOf(_appData.CurrentSettings.getStartDate().getYear())); so you pass the function a string and it interprets it as a literal. Do that for all of your setText calls.e

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.