Crash on button create

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Crash on button create

Postby lostgame » Mon Nov 16, 2009 9:34 pm

No matter what I do, anytime I create a new android project (I'm using the 1.5 SDK) and create just one button, imagebutton, or the like, and then try to reference it in code, I get a crash. I've worked the last 4 hours on trying to just create one button. Coming from iPhone development, where I could create an entire simple application in 4 hours, this is ridiculous. >.<

I've included all the needed imports, android.widget.button, etc.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3. setContentView(R.layout.main);
  4.  
  5.         Button loginButton;
  6.  
  7.         loginButton = (Button) this.findViewById(R.id.HomeLogoutButton);
  8.  
  9.         loginButton.setOnClickListener((OnClickListener) this);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Results no matter what in:

11-16 15:28:23.217: ERROR/AndroidRuntime(827): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.avidlifemedia.hotornot/com.avidlifemedia.hotornot.mainscreen}: java.lang.ClassCastException: com.avidlifemedia.hotornot.mainscreen


Followed by about 20 more errors, many of which LogCat won't even let me see, simply stating "...11 more."

What on earth? 11 more? How do I see those 11 more! They could be the solution to this 4-hour problem!

Never in my ten years of professional programming experience have I been so frustrated.
lostgame
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Apr 02, 2009 8:59 pm

Top

Postby qlimax » Tue Nov 17, 2009 1:23 am

i think class cast error is because your class is not implementing OnClickListener interface...

when you implement this interface, this casting is not required

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. (OnClickListener) this
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


just set this as clicklistener, because
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
object is of the type onclicklistener (you must implements OnClickListener at the class level).

-----------------------BUT-------------

you can do the click stuff ,also without implemeting the clicklistener interface ->>declaring it "on the fly"

try

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. loginButton.setOnClickListener(new OnClickListener() {
  2.                        
  3.                         public void onClick(View v) {
  4.                                 // do click stuff
  5.                                
  6.                         }
  7.                 });
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


and if this does not work, can you post the full logcat error?

bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby Kur1310 » Tue Nov 17, 2009 5:25 am

Hi lostgame,,
U might be getting the classcast exception because u might have taken an imagebutton in ur layout file and in java code u r trying to cast it in a button....
That might be ur problem.. Just check it out.... :shock:
-Kur
Kur1310
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Oct 28, 2009 10:50 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 7 guests