View.settag (Key,object) Exception: The key must is an application-specific resource ID.

Source: Internet
Author: User

07-11 13:43:26.184:e/androidruntime (10229): FATAL exception:main
07-11 13:43:26.184:e/androidruntime (10229): java.lang.RuntimeException:Unable to start activity componentinfo{ Com.txrj.sms/com.txrj.sms.activity.createmessageactivity}: Java.lang.IllegalArgumentException:The key must is an Application-specific resource ID.
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.ActivityThread.performLaunchActivity ( activitythread.java:1970)
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.ActivityThread.handleLaunchActivity ( activitythread.java:1995)
07-11 13:43:26.184:e/androidruntime (10229): at android.app.activitythread.access$600 (ActivityThread.java:128)
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.activitythread$h.handlemessage (ActivityThread.java : 1161)
07-11 13:43:26.184:e/androidruntime (10229): at Android.os.Handler.dispatchMessage (handler.java:99)
07-11 13:43:26.184:e/androidruntime (10229): at Android.os.Looper.loop (looper.java:137)
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.ActivityThread.main (activitythread.java:4517)
07-11 13:43:26.184:e/androidruntime (10229): at Java.lang.reflect.Method.invokeNative (Native Method)
07-11 13:43:26.184:e/androidruntime (10229): at Java.lang.reflect.Method.invoke (method.java:511)
07-11 13:43:26.184:e/androidruntime (10229): at Com.android.internal.os.zygoteinit$methodandargscaller.run ( zygoteinit.java:993)
07-11 13:43:26.184:e/androidruntime (10229): at Com.android.internal.os.ZygoteInit.main (zygoteinit.java:760)
07-11 13:43:26.184:e/androidruntime (10229): at Dalvik.system.NativeStart.main (Native Method)
07-11 13:43:26.184:e/androidruntime (10229):caused By:java.lang.IllegalArgumentException:The key must is an application-specific resource ID.
07-11 13:43:26.184:e/androidruntime (10229): at Android.view.View.setTag (view.java:12585)
07-11 13:43:26.184:e/androidruntime (10229): at Com.txrj.sms.activity.CreateMessageActivity.getRecipientItem ( CREATEMESSAGEACTIVITY.JAVA:47)
07-11 13:43:26.184:e/androidruntime (10229): at Com.txrj.sms.activity.CreateMessageActivity.onCreate ( CREATEMESSAGEACTIVITY.JAVA:41)
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.Activity.performCreate (activity.java:4470)
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.Instrumentation.callActivityOnCreate ( instrumentation.java:1053)
07-11 13:43:26.184:e/androidruntime (10229): at Android.app.ActivityThread.performLaunchActivity ( activitythread.java:1934)
07-11 13:43:26.184:e/androidruntime (10229): ... One more

Cause Analysis:

Settag is a useful method in the view class of Android, which can be used to attach some information to space and to use it in many situations.

The Settag (Object tag) method is relatively simple, here we mainly talk about the Settag method with two parameters.

The official API documentation mentions:

"The specified key should is a ID declared in the resources of the application to ensure it's unique (see the ID RESOURC E type). The Keys identified as belonging to the Android-framework or not-associated with any package would cause an to be IllegalArgumentException thrown. "

So the reason to throw illegalargumentexception is that key is not unique, so how to guarantee the uniqueness of it? It is not possible to define an int variable of the final type and hard-code a value.

If you only need to set a tag, then the direct call Settag (Object tag) method can be easily done, if you need to use more than one tag binding, you need to first add in Res/values/ids.xml

<resources>
<item type= "id" name= "tag_first" ></item>
<item type= "id" name= "tag_second" ></item>
</resources>

Write when you use it.
imageView.setTag(R.id.tag_first, "Hello");imageView.setTag(R.id.tag_second, "Success");
You can do it.
Reference: http://blog.csdn.net/furongkang/article/details/7267317

View.settag (Key,object) Exception: The key must is an application-specific resource ID.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.