Java.lang.ClassCastException:android.widget.ImageButton problems

Source: Internet
Author: User

The problem with the development of the last Wednesday is that my XML is fine, but every time I add a click event to the control, it crashes. Because the development is going on the line, so the exception processing all write to a file sent to the server, debugging will not print log. I was really ignorant, I think it can not be a code problem, has been looking for logic problems, but also to see the log (Khan .... Found this is the error, check the exception is because of the type inconsistency, that is, type conversion error, remember to write Java code before the time will also encounter such as an integer variable with string type to get the error.

Then I took a look at the error code line, which was wrong when I findbyid.

That's what I'm defining in XML is a ImageButton,

But when I call this ID in the code, I think of it as a button call.

The code is like this

Comebackbutton = (Button) Findviewbyid (R.ID.COMEBACK_BTN)//This comeback_btn is my definition of the ImageButton, that is, the conversion is wrong.

Because I this cloth interface and I write data interface is separated for a long time, forget reason.

Summary: 1, write code to be careful

2, do not take for granted that which is which, to be realistic.

This article is from the "unity of Knowledge" blog, please be sure to keep this source http://poarry.blog.51cto.com/5970996/1560412

Java.lang.ClassCastException:android.widget.ImageButton problems

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.