I want to use a string resource as defined in Strings.xml as follows:
<string name="game_name_nassau2">Nassau2</string>
when I instantiate an object that is epecting a String argument. Using a literal, I say:
private Game lGame = new Game(null,"Nassau2", lpl, 100, true, false, false, false);
and this works fine. Trying to use the string resource, I say:
private Game lGame = new Game(null, getResources().getString(R.string.game_name_nassau2), lpl, 100, true, false, false, false);
and this crashes the app. (Crashes, meaning I get a "Source Not Found" error I think at the instantiation). I'm trying to be a good guy and not embed strings into code. Here's the LogCat errors...
11-20 12:31:18.105: E/AndroidRuntime(7158): FATAL EXCEPTION: main
11-20 12:31:18.105: E/AndroidRuntime(7158): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.IllegalStateException: Unable to get package info for com.aci.golfgames; is package not installed?
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4417)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.ActivityThread.access$1300(ActivityThread.java:141)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.os.Looper.loop(Looper.java:137)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-20 12:31:18.105: E/AndroidRuntime(7158): at java.lang.reflect.Method.invokeNative(Native Method)
11-20 12:31:18.105: E/AndroidRuntime(7158): at java.lang.reflect.Method.invoke(Method.java:525)
11-20 12:31:18.105: E/AndroidRuntime(7158): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-20 12:31:18.105: E/AndroidRuntime(7158): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-20 12:31:18.105: E/AndroidRuntime(7158): at dalvik.system.NativeStart.main(Native Method)
11-20 12:31:18.105: E/AndroidRuntime(7158): Caused by: java.lang.IllegalStateException: Unable to get package info for com.aci.golfgames; is package not installed?
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:369)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.LoadedApk.getClassLoader(LoadedApk.java:322)
11-20 12:31:18.105: E/AndroidRuntime(7158): at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
11-20 12:31:18.105: E/AndroidRuntime(7158): ... 11 more
All I changed was the line
private Game lGame = new Game(null,"Nassau2", lpl, 100, true, false, false, false);
to
private Game lGame = new Game(null, getResources().getString(R.string.game_name_nassau2), lpl, 100, true, false, false, false);
iow, all I changed was "Nassau2"
to getResources().getString(R.string.game_name_nassau2)
. I set a breakpoint on the first executable line in the activity and it never gets there.
What am I doing wrong?
Thanks