This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Any ideas why Double errors

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C:\javaupg\javaprg\TooLarge.java:91: Method parseDouble(java.lang.String)
not found in class java.lang.Double.

dataFields.setMyDouble(Double.parseDouble(stringDouble.getText())); ^
1 error
datafields is a reference to a class containing three fields
int, double, String and all work except the above line of code and it says it cannot find the method, yet jdk 1.3 has a method to parseDouble, I have checked. It is static but should be able to be referenced as above yes?
Hope you can help the classes are long but the code is below
:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TooLarge implements ActionListener, WindowListener, Serializable,
TextListener {
//TextArea editorDoc = new TextArea(" ", 5, 20);
TextField stringText = new TextField(" ", 10);
Label textLbl = new Label("Text");
TextField stringInt = new TextField(" ", 5);
Label intLbl = new Label("Integer");
TextField stringDouble = new TextField(" ", 5);
Label doubleLbl = new Label("Double");
Panel containerPanel = new Panel();
Panel stringPanel = new Panel();
Panel messagePanel = new Panel();
Label message = new Label();
boolean setFailed = false;
int colorInt = 0;
//
Serial dataFields = new Serial();
//
Frame editorFrame = new Frame("Editor");
Panel topPanel = new Panel();
Panel buttonContainer = new Panel();
Button saveBtn = new Button("Save");
Button openBtn = new Button("Open");
Button setDataBtn = new Button("Set");
Button getDataBtn = new Button("Get");
File theFile = new File("c:/Bruce/Test5.txt");
FileOutputStream fos;
ObjectOutputStream oos;
FileInputStream fis;
ObjectInputStream ois;
//TooLarge secondEditor;
//BufferedWriter bw;
//FileWriter fw;
boolean append = true;
boolean endOfArray = false;
char space = ' ';
//
//
public static void main(String args[]) {
TooLarge myEditor = new TooLarge();
}
TooLarge() {
//editorFrame.add(editorDoc);
stringPanel.add(stringInt);
stringPanel.add(intLbl);
stringPanel.add(stringDouble);
stringPanel.add(doubleLbl);
stringPanel.add(stringText);
stringText.addTextListener(this);
stringPanel.add(textLbl);
containerPanel.add(stringPanel);
messagePanel.add(message);
containerPanel.add(messagePanel);
containerPanel.setLayout(new GridLayout(2, 0));
editorFrame.add(containerPanel, BorderLayout.CENTER);
editorFrame.add(topPanel, BorderLayout.NORTH);
editorFrame.add(buttonContainer, BorderLayout.SOUTH);
saveBtn.setEnabled(false);
getDataBtn.setEnabled(false);
openBtn.setEnabled(false);
buttonContainer.add(saveBtn);
buttonContainer.add(openBtn);
buttonContainer.add(setDataBtn);
buttonContainer.add(getDataBtn);
editorFrame.addWindowListener(this);
saveBtn.addActionListener(this);
openBtn.addActionListener(this);
setDataBtn.addActionListener(this);
getDataBtn.addActionListener(this);
editorFrame.pack();
editorFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "Set") {
dataFields.setMyString(stringText.getText());
try {
dataFields.setMyInt(Integer.parseInt(stringInt.getText()));
} catch (NumberFormatException nfe) {
message.setText("Remove any spaces which are in the integer");
message.setSize(30,4);
stringInt.setBackground(Color.red);
setFailed = true;
editorFrame.pack();
//editorFrame.setVisible(true);
}
dataFields.setMyDouble(Double.parseDouble(stringDouble.getText()));
if (setFailed == false) {
stringInt.setBackground(Color.white);
saveBtn.setEnabled(true);
//openBtn.setEnabled(true);
setDataBtn.setEnabled(false);
message.setText(" ");
stringInt.setText(" ");
stringDouble.setText(" ");
stringText.setText(" ");
}
setFailed = false;
}
if (e.getActionCommand() == "Get") {
stringInt.setText(String.valueOf(dataFields.getMyInt()));
if (Integer.parseInt(stringInt.getText()) > 0) {
stringText.setText(dataFields.getMyString());
stringDouble.setText(String.valueOf(dataFields.getMyDouble()));
}
saveBtn.setEnabled(false);
openBtn.setEnabled(false);
getDataBtn.setEnabled(false);
setDataBtn.setEnabled(true);
}
if (e.getActionCommand() == "Save") {
try {
//String text = editorDoc.getText();
fos = new FileOutputStream(theFile);
oos = new ObjectOutputStream(fos);
oos.writeObject(dataFields);
//secondEditor = (TooLarge)oos.readObject();
//} catch (ClassNotFoundException cnfe) {
} catch (NotSerializableException nse) {
System.out.println("Not serializable exception");
} catch (IOException ioe) {
System.out.println("IOException on Save");
} finally {
try {
oos.close();
fos.close();
} catch (IOException ioe2) {
System.out.println("error on output close");
}
}
setDataBtn.setEnabled(false);
saveBtn.setEnabled(false);
openBtn.setEnabled(true);
}
if (e.getActionCommand() == "Open") {
try {
fis = new FileInputStream(theFile);
ois = new ObjectInputStream(fis);
dataFields = (Serial)ois.readObject();
} catch (FileNotFoundException fe) {
System.out.println("File not Found");
} catch (ClassNotFoundException cnfe) {
System.out.println("Class not Found");
} catch (IOException ioe) {
System.out.println("IO error on Open");
} finally {
try {
ois.close();
fis.close();
} catch (IOException ioe2) {
System.out.println("error on input close");
}
}
openBtn.setEnabled(false);
getDataBtn.setEnabled(true);
//secondEditor.editorFrame.setVisible(true);
}
}
public void textValueChanged(TextEvent te) {
colorInt++;
if (colorInt == 1) {
stringDouble.setBackground(Color.blue);
}
if (colorInt == 2) {
stringDouble.setBackground(Color.green);
}
if (colorInt == 3) {
stringDouble.setBackground(Color.orange);
colorInt = 0;
}
}

//try {
//String text = editorDoc.getText();
//char[] c = text.toCharArray();
//fw = new FileWriter(out);
//bw = new BufferedWriter(fw);
//int i = 0;
//int j = 0;
//do {
//if ((i + 80) < c.length) {
//System.out.println("in if");
//j = 80;
//while (c[i + j] != ' ') {
//--j;
//}
// reinclude space in printed line so lines start with characters
//++j;
//System.out.println("i " + i + " j " + j);
//bw.write(c, i, j);
//bw.newLine();
//i += j;
//System.out.println(i);
//} else {
//System.out.println("in else");
//bw.write(c, i, (c.length - i));
//endOfArray = true;
//}
//} while (endOfArray == false);
//bw.flush();
//} catch (IOException ioe) {
//System.out.println(ioe);
//} finally {
//try {
//bw.close();
//fw.close();
//} catch (IOException ioe) {
//System.out.println("error on file closing");
//}
//endOfArray = false;
//}
//}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowClosed(WindowEvent e) {}
public void windowOpening(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
}

public class Serial implements java.io.Serializable {
// this class test serialization
//class TooLarge will read and write this data
private int myInt;
private double myDouble;
private String myString;
//
public String getMyString() {
return myString;
}
public int getMyInt() {
return myInt;
}
public double getMyDouble() {
return myDouble;
}
//
public void setMyString(String s) {
myString = s;
}
public void setMyDouble(double d) {
myDouble = d;
}
public void setMyInt(int i) {
myInt = i;
}
}
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bruce,
You seem to have defined 2 public classes Serial, TooLarge in one file. Please check up and let me know.
Regards,
Milind
 
Bruce Blake
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Milind
Thanks for replying.
No the files are separate but because they work together I included both. Serial holds the data which is serialized by TooLarge.
Remove the block of comments from TooLarge and you will have TooLarge as it is in my classFile ie when Compiled.
I get the strings and convert to int, string, double and store in Serial then save serial to a file. Place the code in separate files and run it you will hopefully get the error I do
Thanks again
 
Milind Kulkarni
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bruce,
I am able to compile and run the programs without any problem. 3 text boxes appear for entering integer, double and text and 4 buttons at the bottom.
I am using JDK1.2.2 and OS Win98.
Regards,
Milind
reply
    Bookmark Topic Watch Topic
  • New Topic