Solution: threadid = 1: thread exiting with uncaught exception (group = 0x4001d800)

Source: Internet
Author: User
Tags button type

W/dalvikvm (285): threadid = 1: thread exiting with uncaught exception (group = 0x4001d800)
E/AndroidRuntime (285): fatal exception: main
E/AndroidRuntime (0, 285): java. lang. runtimeException: Unable to instantiate activity ComponentInfo {com. example. service/com. example. service. firstService}: java. lang. classCastException: com. example. service. firstService
Www.111cn. Net E/AndroidRuntime (285): at android. app. ActivityThread. Initialize mlaunchactivity (ActivityThread. java: 2585)
E/AndroidRuntime (285): at android. app. ActivityThread. handleLaunchActivity (ActivityThread. java: 2679)
E/AndroidRuntime (285): at android. app. ActivityThread. access $2300 (ActivityThread. java: 125)
E/AndroidRuntime (285): at android. app. ActivityThread $ H. handleMessage (ActivityThread. java: 2033)

---------------------

I accidentally met this evening. I am listening to a control. an error occurred when OnClickListener clicked the event. At that time, I did not study it carefully. Then, Baidu and Google searched a bunch of it and found that many people also encountered it, but there was no solution in the end, then calm down and study it! I found the problem and proposed two solutions!

The reason is::( Button) findViewById (R. id. xxx); an error occurred while forcing the conversion type. You converted the button type of the control that does not support click events to implement the View. onClickListener event click listening, and then an error occurs. This is the root cause! Generally, you convert TextView or non-button controls!

Solution: 1In the layout file, change the <TextView/> and other styles to <Button/>;
2. Use View to cancel the forced conversion of the button. You can also convert the type to View, and this method is different from Method 1. Method 2 does not affect the shape of the control;

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.