aspose file tools*
The moose likes Android and the fly likes Using reflection for button listeners, throwing ClassNotFound exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Using reflection for button listeners, throwing ClassNotFound exception" Watch "Using reflection for button listeners, throwing ClassNotFound exception" New topic
Author

Using reflection for button listeners, throwing ClassNotFound exception

Ben Alex Barreto
Greenhorn

Joined: May 10, 2011
Posts: 15

Me and my team are trying to use reflection to implement the listeners for the buttons in this simple calculator. We are doing this for an engineering class. We added a break point at line 35 "Class aListenerClass = Class.forName(splitString[0]);" because it keeps throwing a ClassNotFound exception, and it's being thrown after we split the string to identify the right listener. The "Controller" you see there, well, we are implementing the Application Controller pattern for the back-end of this calculator...

Why in the world is it throwing ClassNotFound? When we run this on debug mode in eclipse, we can check the value of the split elements, right? Well... it shows "CalculateListener" for the first element of the split string, yet when we expand the element it lists [C,a,l,c,u,l,a,t,e,L,i,s,t,e,n,e,r,_,e,q,u,a,l,s] as it's value--as if the string never got split, but it is being split! Check our code below. I'm also including the R file, so you guys can check all the ids and see how we are implementing reflection here. Please give us some light We would be eternally grateful!

In advance, thank you so much!

Sincerely,

Ben, Diego (0x783czar), Trevor, David, and Steve.





-ben
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Make sure the resulted class name is qualified with its package name. For example: com.yourdomain.CalculateListener
Ben Alex Barreto
Greenhorn

Joined: May 10, 2011
Posts: 15

Hussein Baghdadi wrote:Make sure the resulted class name is qualified with its package name. For example: com.yourdomain.CalculateListener


That was exactly right! Thank you o much! We are going past that exception now :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using reflection for button listeners, throwing ClassNotFound exception