Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: errors in H...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 16046 of 16269
Post > Topic >>

Re: errors in Hashtable to HashMap

by bH <bherbst65@[EMAIL PROTECTED] > May 2, 2008 at 04:38 PM

On May 2, 12:58=A0pm, "Matt Humphrey" <ma...@[EMAIL PROTECTED]
> wrote:
> "bH" <bherbs...@[EMAIL PROTECTED]
> wrote in message
>
>
news:2a2e1dbf-fcdc-49ed-88c0-ec7025e07ca4@[EMAIL PROTECTED]
> On May 2, 10:33 am, Roedy Green <see_webs...@[EMAIL PROTECTED]
>
> wrote:
>
> > On Fri, 2 May 2008 05:34:40 -0700 (PDT), bH <bherbs...@[EMAIL PROTECTED]
>
> > wrote, quoted or indirectly quoted someone who said :
>
> > >Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
> > > at TestPhneDialer.action(TestPhneDialer.java:30)
>
> > Since the listing you post has no line numbers, we can't easily tell
> > what that is pointing to. Add a comment to point it out.
> > --
>
> > Roedy Green Canadian Mind Products
> > The Java Glossaryhttp://mindprod.com
> > Hi Matt,
> > The suggestions that you made do not fix the situation :(
>
> Perhaps you have more than one error. =A0Exactly what did you do and
what
> error is it producing? =A0Are you sure the browser isn't caching your
appl=
et?
> You are definately declaring the variable twice.
>
> > This is the line 30 that is in error:
> > String name =3D new
> > String((String)buttonSoundNames.get((Button)e.target));
>
> > P.S. I think that this error happens because the buttonSoundNames is
> > .not
> > available at this line(not readable at this point in the program).
> > But that is just my dumb guess.
>
> You know (and can test) that buttonSoundNames is null at this point.
=A0No=
w
> work backwards and ask yourself what conditions are needed in order for
it=

> to be null. Perhaps init() is not called, the initialization is
shadowed,
> the applet has been cached, etc. =A0Then test each of these hypotheses.
>
> Also, it's not meaningful for the HashMap loadfactor to be > 1.
> Essentially, you're saying that when a table of size 3 contains more
than =
9
> elements it should be resized.
>
> Matt Humphreyhttp://www.iviz.com/

Hi Matt,

Thanks for your response. Your suggestions are really
appreciated. I have corrected the code so that errors
re****ted earlier no longer exist.

The major correction happened in the declaration
early in the program.

The following is offered as a solution.

im****t java.applet.*;
im****t java.awt.*;
im****t java.util.HashMap;

@[EMAIL PROTECTED]
( "unchecked" )

public class HMapTestPhneDialer extends Applet {

  boolean DEBUG =3D false;
  HashMap buttonSoundNames;
  KeyPad keyPad;

  public void init() {
    keyPad =3D new KeyPad();
    buttonSoundNames =3D new HashMap<Button,String>();
    // changed this

    buttonSoundNames.put(keyPad.b1, "1.au");
    buttonSoundNames.put(keyPad.b2, "2.au");
    buttonSoundNames.put(keyPad.b3, "3.au");
    setLayout(new FlowLayout());
    add(keyPad);
    validate();
    System.out.println(keyPad.b3);
  }

  public boolean action(Event e, Object arg) {
            //System.out.println("Here");
        if (e.target instanceof Button) {
            String name =3D
new String((String)buttonSoundNames.get((Button)e.target));
            System.out.println(name);
            //results should show "1.au" or"2.au" or "3.au"
            //depending which button press
      return true;
    }
    return false;
  }
}
class KeyPad extends Panel {
  Button b1,b2,b3;
  KeyPad() {
    b1 =3D new Button("1");
    b2 =3D new Button("2");
    b3 =3D new Button("3");
    setLayout(new GridLayout(4,3,10,10));
    add(b1);
    add(b2);
    add(b3);
  }
}
Thanks again,

bH
 




 6 Posts in Topic:
errors in Hashtable to HashMap
bH <bherbst65@[EMAIL P  2008-05-02 05:34:40 
Re: errors in Hashtable to HashMap
"Matt Humphrey"  2008-05-02 09:24:27 
Re: errors in Hashtable to HashMap
Roedy Green <see_websi  2008-05-02 14:33:09 
Re: errors in Hashtable to HashMap
bH <bherbst65@[EMAIL P  2008-05-02 08:13:11 
Re: errors in Hashtable to HashMap
"Matt Humphrey"  2008-05-02 12:58:05 
Re: errors in Hashtable to HashMap
bH <bherbst65@[EMAIL P  2008-05-02 16:38:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 4:57:29 CDT 2008.