Reputation: 121
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);
}
Upvotes: 0
Views: 637
Reputation: 54722
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.
Upvotes: 0
Reputation: 40218
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
.
Upvotes: 5
Reputation: 18978
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;
check this ans: https://stackoverflow.com/a/6593822/1168654
Toast.makeText(this, ""+currentVersion, Toast.LENGTH_LONG).show();
Upvotes: 1