Android eclipse debugging reports java. lang. ClassCastException exception, androidexception

Source: Internet
Author: User

Android eclipse debugging reports java. lang. ClassCastException exception, androidexception

In the layout file, place the ImageView position before the Button for the first time.

Code compilation Error

 

Then adjust the positions of the two

The following error is reported during re-compilation.

 

 

The error message "Why is this error reported when the Button type cannot be converted to the ImageView type? I did not explicitly set the conversion between them.

It turns out that eclipse compilation is based on the timestamp-based judgment mechanism.
So when you press build all, some classes that eclipse considers that the timestamp has not changed will not be compiled.
Therefore, you can first clean and then compile. At this time, eclipse will clear all previous compilation information and then compile it.

After the two controls are re-compiled, you can clear the. class file generated by compilation from project-> clean.

Then compile again. No error is reported.


I used eclipse to debug the android program. It was okay to run it for the first time. After the change, I ran eclipse for the second time. I didn't respond at all.

Increase eclipse configuration. All are in eclipse. ini. Try it.

What happens to a javalangClassCastException?

Type conversion error ..

For example, if you have A class A and B class, there is no relationship between the two classes ..

Then you A a = new ();
B B = (B);
In this way, this exception will be reported during the runtime ..

But if your class B inherits from Class A, it won't ..

If you want to avoid this error ..

You can check whether the. a object is of type B before transformation... use the instanceof keyword ..

For example, if (a instanceof B) {B B = (B) ..

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.