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;