🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7489

Re: ClassCastException

#7489
From: John McGrath TeamB
Date: Fri, 15 Jun 2001 10:55
44 lines
2402 bytes
On 12 Jun 2001 14:15:44 -0700, ct wrote:

> StateHandler handler = null;
> try {
>    Class c1 = Class.forName(handlerName);
>    Object o = c1.newInstance();
>    System.out.println("StateMachine: o = " + (SigninHandler)o);
>    handler = (StateHandler)o;  // exception throws
> } catch(Exception) {}

I am not sure if I missed something here:

First, I cannot see anywhere that you have said or shown what the value 
of "handlerName" is.  This would seem to be a somewhat critical piece 
of information.

Second, how can you tell that an exception is being thrown from the 
line indicated in the code above.  Your catch block for Exception does 
not do anything, so it would seem to be pretty hard to tell.

I also note that your catch block is not syntactically correct, but I 
presume that this was just in your message.

Could you change the code to the following and post the output?

   StateHandler handler = null;
   try {
      System.out.println( "handlerName = \"" + handlerName + "\"" );
      Class c1 = Class.forName(handlerName);
      Object o = c1.newInstance();
      System.out.println("StateMachine: o = " + (SigninHandler)o);
      handler = (StateHandler)o;  // exception throws
   } catch(Exception ex) {
      System.out.println( "Exception: " + ex );
   }

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.1593a9b3b9ce251298a2a8@forums.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews
References: <3b214690$1_1@dnews> <3b2345b6$1_1@dnews> <3b24c313$1_1@dnews> <3b266e7e_2@dnews> <3b268680$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,8a0377b4254bc1e1
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-15 04:11:13 PST
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: ClassCastException
Date: Fri, 15 Jun 2001 06:55:45 -0400
Message-ID: <MPG.1593a9b3b9ce251298a2a8@forums.borland.com>
References: <3b214690$1_1@dnews> <3b2345b6$1_1@dnews> <3b24c313$1_1@dnews> <3b266e7e_2@dnews> <3b268680$1_2@dnews>
X-Newsreader: MicroPlanet Gravity v2.30
NNTP-Posting-Host: 209.92.40.60
X-Trace: dnews 992602544 209.92.40.60 (15 Jun 2001 03:55:44 -0700)
Lines: 44
X-Authenticated-User: jpmcgrath
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews