0

anyone who knows what is going wrong? I am repeatedly getting this error when trying to retrieve the version code out of my manifest:

04-19 15:09:34.778: W/ResourceType(29293): No package identifier when getting value for           resource number 0x00000001
04-19 15:09:36.833: W/System.err(29293): android.content.res.Resources$NotFoundException: String resource ID #0x1
04-19 15:09:36.843: W/System.err(29293):    at android.content.res.Resources.getText(Resources.java:242)
04-19 15:09:36.848: W/System.err(29293):    at android.widget.Toast.makeText(Toast.java:304)
04-19 15:09:36.853: W/System.err(29293):    at com.koeriers.standaard.actUpdate.onCreate(actUpdate.java:71)
04-19 15:09:36.863: W/System.err(29293):    at android.app.Activity.performCreate(Activity.java:5206)
04-19 15:09:36.863: W/System.err(29293):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-19 15:09:36.868: W/System.err(29293):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
04-19 15:09:36.873: W/System.err(29293):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
04-19 15:09:36.878: W/System.err(29293):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
04-19 15:09:36.883: W/System.err(29293):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
04-19 15:09:36.888: W/System.err(29293):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 15:09:36.893: W/System.err(29293):    at android.os.Looper.loop(Looper.java:137)
04-19 15:09:36.898: W/System.err(29293):    at android.app.ActivityThread.main(ActivityThread.java:4921)
04-19 15:09:36.898: W/System.err(29293):    at java.lang.reflect.Method.invokeNative(Native Method)
04-19 15:09:36.903: W/System.err(29293):    at java.lang.reflect.Method.invoke(Method.java:511)
04-19 15:09:36.908: W/System.err(29293):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
04-19 15:09:36.913: W/System.err(29293):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
04-19 15:09:36.918: W/System.err(29293):    at dalvik.system.NativeStart.main(Native Method)
04-19 15:09:37.043: D/dalvikvm(29293): GC_CONCURRENT freed 211K, 14% free 9864K/11399K, paused 13ms+13ms, total 77ms
04-19 15:09:37.093: W/ResourceType(29293): Failure getting entry for 0x010802c0 (t=7 e=704) in package 0 (error -75)

and this is the code I use to retrieve the versionCode out of my manifest file:

int currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;

and ofcourse my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.default"
android:versionCode="1"
android:versionName="1.0" >

I hope you guys can help me out.

my onCreate method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    TLogFile.appendLog("i", "UPDATER", "Updaten");

    // setting some display
    setContentView(R.layout.frmupdate);
    TextView tv = new TextView(this);
    tv.setText("Loading...");

    // making sure the download directory exists
    checkAndCreateDirectory("/downloads");

    try {
        int currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
        Toast.makeText(this, currentVersion, Toast.LENGTH_LONG).show();
    } catch (NameNotFoundException n) {
        n.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    // executing the asynctask
    new DownloadFileAsync().execute(fileURL);
}
4
  • 1
    Are you setting the currentVersion to textView..? Commented Apr 19, 2013 at 13:22
  • Can you please post the onCreate method ? Commented Apr 19, 2013 at 13:23
  • Looks like you are trying to put the currentVersion into a Toast. When you do so you need to convert it to a String or else it assumes you are refering to a String resource. Try something like this instead of what you have: Toast.makeText(ctx, ""+ currentVersion, Toast.LENGTH_SHORT).show() Commented Apr 19, 2013 at 13:24
  • check my edited ans: stackoverflow.com/a/16105743/1168654 Commented Apr 19, 2013 at 13:31

3 Answers 3

5

As the logcat states, you're getting a NotFoundException for a resource when trying to call Toast.makeText(). While I can't see any code connected to Toast in the question description, I will try to make a guess. There are two overloaded makeText() methods in Toast:

makeText(Context context, int resId, int duration)

and

makeText(Context context, CharSequence text, int duration)

Probably you're passing your versionCode, which is an int, as the second parameter, and while you want the second version of makeText() to be called, what gets called is the first one, where the versionCode is treated as the resId. There is probably no resource with this id and the error proves it. So what you need to do is to pass String.valueOf(versionCode) as the second argument, then the Toast will display the value of the versionCode.

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

3 Comments

I am using the first one, with the 'int resID'
You should use the second as Egor mentioned it, using String.value ( versionCode )
@user, When using this version of method, you should pass a resource id of a string that's defined in XML. If you want to display an int, you should "cast" it to String as described above.
1
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;

check this ans: https://stackoverflow.com/a/6593822/1168654

edited: change this line

Toast.makeText(this, ""+currentVersion, Toast.LENGTH_LONG).show();

Comments

0

It seems you are using this vesionCode in any Toast. For Example If you want to show it in a textview tv

tv.setetext(versionCode);

so this is trigerring tv.setText(int resID);

But in your R.java there is no resource id with versionCode.

So to see the version code first convert it to String. then show it.

1 Comment

I gave example with settext, in your case it is toast

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.