two problems

Discussion in 'Java' started by pageV, Apr 12, 2004.

  1. pageV

    pageV Guest

    In this code bit:
    void saveData()
    {
    String out;
    try
    {
    //output = new BufferedWriter (file ) ;

    try
    {
    out = Double.toString(index);
    output.write( out + " ") ;
    out = Double.toString(twoDig.format(total));
    output.write( out + "\n");
    }


    }
    catch( IOException ioe )
    {
    JOptionPane.showMessageDialog( null, "Err: " + ioe );
    }
    }
    I commented out "output = new BufferedWriter (file ) ;" to move it outside
    the method so I could write more than one line to the file. Also
    moved the close statement outside the method so I could write more than one
    line.
    But it writes only the last line before I close it. That's the first
    problem.
    Then I added a line elsewhere in the program to change the look and feel
    and the compiler started complaining about try without catch. So I commented
    out one of the try's and a pair of brackets. Now I get

    Coffee.java:188: cannot resolve symbol
    symbol : method toString (java.lang.String)
    location: class java.lang.Double
    out = Double.toString(twoDig.format(total));
    ^
    Put the try back in and get both errors.
    Commented out the look and feel statement and still
    get the errors. I can fix the try error but I can't
    get back to where I was when the compiler accepted
    the Double.toString.

    Any solutions?
    Ralph
     
    pageV, Apr 12, 2004
    #1
    1. Advertising

  2. pageV wrote:

    > In this code bit:
    > void saveData()
    > {
    > String out;
    > try
    > {
    > //output = new BufferedWriter (file ) ;
    >
    > try
    > {
    > out = Double.toString(index);
    > output.write( out + " ") ;
    > out = Double.toString(twoDig.format(total));
    > output.write( out + "\n");
    > }
    >
    >
    > }
    > catch( IOException ioe )
    > {
    > JOptionPane.showMessageDialog( null, "Err: " + ioe );
    > }
    > }
    > I commented out "output = new BufferedWriter (file ) ;" to move it
    > outside the method so I could write more than one line to the file. Also
    > moved the close statement outside the method so I could write more than
    > one line.
    > But it writes only the last line before I close it. That's the first
    > problem.
    > Then I added a line elsewhere in the program to change the look and feel
    > and the compiler started complaining about try without catch. So I
    > commented
    > out one of the try's and a pair of brackets. Now I get
    >
    > Coffee.java:188: cannot resolve symbol
    > symbol : method toString (java.lang.String)
    > location: class java.lang.Double
    > out = Double.toString(twoDig.format(total));
    > ^
    > Put the try back in and get both errors.
    > Commented out the look and feel statement and still
    > get the errors. I can fix the try error but I can't
    > get back to where I was when the compiler accepted
    > the Double.toString.
    >
    > Any solutions?
    > Ralph


    Yes, there is no toString method that accepts a String in the Double class.

    Looking at this might help you:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html

    Your second try/catch block is also wrong: it is missing a catch statement,
    which must always follow the try statement.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Apr 12, 2004
    #2
    1. Advertising

  3. pageV

    pageV Guest

    "Christophe Vanfleteren" <> wrote in message
    news:K7Eec.69641$-ops.be...
    > pageV wrote:
    >
    > > In this code bit:
    > > void saveData()
    > > {
    > > String out;
    > > try
    > > {
    > > //output = new BufferedWriter (file ) ;
    > >
    > > try
    > > {
    > > out = Double.toString(index);
    > > output.write( out + " ") ;
    > > out = Double.toString(twoDig.format(total));
    > > output.write( out + "\n");
    > > }
    > >
    > >
    > > }
    > > catch( IOException ioe )
    > > {
    > > JOptionPane.showMessageDialog( null, "Err: " + ioe );
    > > }
    > > }
    > > I commented out "output = new BufferedWriter (file ) ;" to move it
    > > outside the method so I could write more than one line to the file. Also
    > > moved the close statement outside the method so I could write more than
    > > one line.
    > > But it writes only the last line before I close it. That's the first
    > > problem.
    > > Then I added a line elsewhere in the program to change the look and

    feel
    > > and the compiler started complaining about try without catch. So I
    > > commented
    > > out one of the try's and a pair of brackets. Now I get
    > >
    > > Coffee.java:188: cannot resolve symbol
    > > symbol : method toString (java.lang.String)
    > > location: class java.lang.Double
    > > out = Double.toString(twoDig.format(total));
    > > ^
    > > Put the try back in and get both errors.
    > > Commented out the look and feel statement and still
    > > get the errors. I can fix the try error but I can't
    > > get back to where I was when the compiler accepted
    > > the Double.toString.
    > >
    > > Any solutions?
    > > Ralph

    >
    > Yes, there is no toString method that accepts a String in the Double

    class.
    >
    > Looking at this might help you:
    > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html
    >
    > Your second try/catch block is also wrong: it is missing a catch

    statement,
    > which must always follow the try statement.
    >
    > --
    > Kind regards,
    > Christophe Vanfleteren


    I understand, I forget that twoDig.format made a string. The program works
    now,
    except I am still stuck with metal look and feel
    UIManager.setLookAndFeel( new
    com.sun.java.swing.plaf.windows.WindowsLookAndFeel() );
    and
    UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
    don't seem to have an effect.

    Earlier, i thought i was getting no errors, but the errors were scrolled off
    the screen in Kawa, and all I saw was file compiled.

    Thanks for the help
    Ralph
     
    pageV, Apr 13, 2004
    #3
  4. pageV wrote:

    > I understand, I forget that twoDig.format made a string. The program
    > works now,
    > except I am still stuck with metal look and feel
    > UIManager.setLookAndFeel( new
    > com.sun.java.swing.plaf.windows.WindowsLookAndFeel() );
    > and
    > UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
    > don't seem to have an effect.
    >
    > Earlier, i thought i was getting no errors, but the errors were scrolled
    > off the screen in Kawa, and all I saw was file compiled.
    >


    When are you calling this code? IIRC you should do this before you
    initialize any Swing components.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Apr 13, 2004
    #4
  5. pageV

    pageV Guest

    "Christophe Vanfleteren" <> wrote in message
    news:tnFec.69692$-ops.be...
    > pageV wrote:
    >
    > > I understand, I forget that twoDig.format made a string. The program
    > > works now,
    > > except I am still stuck with metal look and feel
    > > UIManager.setLookAndFeel( new
    > > com.sun.java.swing.plaf.windows.WindowsLookAndFeel() );
    > > and
    > > UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
    > > don't seem to have an effect.
    > >
    > > Earlier, i thought i was getting no errors, but the errors were scrolled
    > > off the screen in Kawa, and all I saw was file compiled.
    > >

    >
    > When are you calling this code? IIRC you should do this before you
    > initialize any Swing components.


    I had
    JPanel jPanel1 = new JPanel(); and 17 similiar statements outside and
    before the constructor. Changed it to Jpanel jpanl1 outside the constructor
    and jPanel1= new JPanel(); inside and now I have Windows look and feel.
    Thanks
    Ralph
    >
    > --
    > Kind regards,
    > Christophe Vanfleteren
     
    pageV, Apr 13, 2004
    #5
  6. pageV

    Roedy Green Guest

    On Mon, 12 Apr 2004 23:12:25 GMT, Christophe Vanfleteren
    <> wrote or quoted :

    >> UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
    >> don't seem to have an effect.

    you want something like this before you create any JFrames.

    public static void main ( String[] args )
    {
    try
    {
    if ( Config.LOOK_AND_FEEL != null )
    {
    UIManager.setLookAndFeel( Config.LOOK_AND_FEEL );
    }
    ToolTipManager.sharedInstance().setInitialDelay( 1000 );
    JFrame.setDefaultLookAndFeelDecorated ( true );

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Apr 13, 2004
    #6
  7. pageV

    pageV Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Mon, 12 Apr 2004 23:12:25 GMT, Christophe Vanfleteren
    > <> wrote or quoted :
    >
    > >> UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
    > >> don't seem to have an effect.

    > you want something like this before you create any JFrames.
    >
    > public static void main ( String[] args )
    > {
    > try
    > {
    > if ( Config.LOOK_AND_FEEL != null )
    > {
    > UIManager.setLookAndFeel( Config.LOOK_AND_FEEL );
    > }
    > ToolTipManager.sharedInstance().setInitialDelay( 1000 );
    > JFrame.setDefaultLookAndFeelDecorated ( true );
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


    Tried it out. Didn't work until I noticed I had Kawa set to jdk1.3.
    Worked fine on jdk1.4.

    Ralph
     
    pageV, Apr 13, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fangs
    Replies:
    3
    Views:
    9,803
    darshana
    Oct 26, 2008
  2. DC Gringo
    Replies:
    2
    Views:
    2,309
    Nikhil Patel
    Feb 26, 2004
  3. Mark
    Replies:
    3
    Views:
    514
    bruce barker
    Aug 26, 2004
  4. Darrel
    Replies:
    2
    Views:
    314
    darrel
    Nov 4, 2004
  5. GenxLogic
    Replies:
    3
    Views:
    1,289
    andrewmcdonagh
    Dec 6, 2006
Loading...

Share This Page