The key must be an application-specific resource id

Why do I get this Exception?

05-18 20:29:38.044: ERROR/AndroidRuntime(5453): java.lang.IllegalArgumentException: The key must be an application-specific resource id.
05-18 20:29:38.044: ERROR/AndroidRuntime(5453):     at android.view.View.setTag(View.java:7704)
05-18 20:29:38.044: ERROR/AndroidRuntime(5453):     at com.mypkg.viewP.inflateRow(viewP.java:518)

the line in question is:

((Button) row.findViewById(R.id.btnPickContact)).setTag(TAG_ONLINE_ID,objContact.onlineid);

and I have it defined as:

private static final int TAG_ONLINE_ID = 1;

The reason you're not able to use setTag(int, Object) is because android require a pre-compiled unique id in the 'int' argument.

Try creating two unique entry in String.xml xml say, "firstname" & "secondname" & use them as below

imageView.setTag(R.string.firstname, "Abhishek");
imageView.setTag(R.string.lastname, "Gondalia");

I'm a little late to the party but I stumbled on this problem myself today and thought I'd give an answer as well. This answer will be a bit of a compilation of the other answers, but with a twist. First of all, the id, as has been pointed out by others, can NOT be a constant defined in your code (such as private static final int MYID = 123) or any other int that you define as a field somewhere.

The id has to be a precompiled unique id, just like the ones you get for strings that you put in values/strings.xml (ie R.string.mystring). Refer to http://developer.android.com/guide/topics/resources/available-resources.html and http://developer.android.com/guide/topics/resources/more-resources.html for more information.

My suggestion is that you create a new file called values/tags.xml and write:

    <resources xmlns:android="http://schemas.android.com/apk/res/android">
      <item name="TAG_ONLINE_ID" type="id"/>
    </resources>

I think it's better to create a separate file instead of putting it in strings.xml as EtienneSky suggested.