Results 1 to 20 of 58
Thread: [SOLVED] Netbeans 6.5
- 03-14-2009, 07:58 PM #1
[SOLVED] Netbeans 6.5
:confused:
I think it is more likely something that I am doing rather than the IDE but I seem to be having issues regarding validation.
I have a project underway that I have translated over to enable me to use the code again with a few variations(variables) and the first project works fine as it is meant to.
I have a class file named 'bmiRecord' and my main app file is called 'frmBmi' on the gui there is a button labelled 'cmdAdd'
For some reason the codegives me an error 'Cannot find symbol, symbol constructor: bmiRecord(double), location: class bmiassessment3.bmirecord, surround with ...'record = new bmiRecord(
The full script attached to the button is below, can anyone help firstly telling me what this error message means and second by looking at the code and suggesting where I am going wrong.
Thanks in advance for any advice.private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// create a variable called record of class(interface type) videoRecord
bmiRecord record;
//record is a new instance of the variable, get the value from the screen fields
//then write the record variable out to the file linked by output variable
try {
record = new bmiRecord(
Double.parseDouble(txtMembership.getText()));
Double.parseDouble(txtDate.getText());
Double.parseDouble(txtBmi.getText());
output.writeObject(record); // writes the record
}
catch (IOException e) {
optPane.showMessageDialog(this, "Error adding a record","File Write Error",optPane.ERROR_MESSAGE);
}
// Clear cells after adding record
txtMembership.setText("");
txtDate.setText("");
txtBmi.setText("");
txtResults.setText("");
}
-
My guess is that the bmiRecord constructor takes three double parameters. The way you've written it, you've only passed one double parameter:
Try to pass three doubles like so, and see what happens:Java Code:record = new bmiRecord( Double.parseDouble(txtMembership.getText())); Double.parseDouble(txtDate.getText()); Double.parseDouble(txtBmi.getText()); output.writeObject(record);
Java Code:record = new bmiRecord( Double.parseDouble(txtMembership.getText()), Double.parseDouble(txtDate.getText()), Double.parseDouble(txtBmi.getText())); output.writeObject(record); // writes the record
- 03-14-2009, 08:12 PM #3
Netbeans 6.5
Thats perfect
Thanks, I see exactly what I have done now.
-
I'm glad this helped. Please mark your thread as "solved". Happy coding!
- 03-14-2009, 08:42 PM #5
Saying that using the same principles that solved the first issue, I have hit a stumbling block again.
Why does the principle not carry across to this button?private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
// Next Button code
FbRecords record;
//reads the ‘next record’ ie file is already open from reading the first record
try {
//file is already open
record = (FbRecords)input.readObject(); //read whole record
// put record fields in to the screen fields
txtMnumber.setText(double.toString(record.getMnumb er()),
txtRdate.setText(double.toString(record.getRdate() ),
txtBmi.setText(double.toString(record.getBmi()));
}
catch (IOException e) {
Optpane.showMessageDialog(this, "IO Error reading file, possible EOF","File Read Error",Optpane.ERROR_MESSAGE);
-
Given the code posted, I have no idea whatsoever, and you may need to post more code, or even a small compilable program that demonstrates the problem.
One unrelated forum suggestion: when posting code, please be sure that the code is already well-formatted with proper indentations prior to posting. It makes reading the code much easier. Thanks.
- 03-14-2009, 09:43 PM #7
Sorry for the lack of formatting, not used to forums yet.
This program writes to an external text file or should do but only certain fields (3 in total) it is part of the same app as initial app that was solved.
The code is attached to a button again
The three fields on the gui are labelledprivate void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
// Next Button code
FbRecords record;
//reads the ‘next record’ ie file is already open from reading the first record
try {
//file is already open
record = (FbRecords)input.readObject(); //read whole record
// put record fields in to the screen fields
txtMnumber.setText(double.toString(record.getMbrsh ip()),
txtRdate.setText(double.toString(record.getDate()) ,
txtBmi.setText(double.toString(record.getBmi()));
}
catch (IOException e) {
Optpane.showMessageDialog(this, "IO Error reading file, possible EOF","File Read Error",Optpane.ERROR_MESSAGE);
cmdNext.setEnabled(false); //this should disable the next button on the last record so u dont get EOF error message
cmdAddRecord.setEnabled(false); // Disables next but still displays EOF error message.
}
catch (ClassNotFoundException e) {
Optpane.showMessageDialog(this, "Class Error reading next record","File Read Error",Optpane.ERROR_MESSAGE);
}
txtMnumber
txtRdate
txtBmi
The class file is as below
Sorry without giving all the app code I dont know what else would help./*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fatbustersasses3;
import java.io.*; //library statement
/**
*
* @author Student 052109
*
* This class is for the member records
*/
public class FbRecords {
private double mship;
private double date;
private double bmi;
/** Creates a new instance of VideoRecord */
public FbRecords() {
this(0,0,0);
}
public FbRecords(double m, double d, double b) {
setMbrship(m);
setDate (d);
setBmi(b);
}
// Start of membership Number get and put
public void setMbrship(double m){
mship = m;
}
public double getMbrship(){
return mship; // gets data from file to return to GUI
}
// end of membership get and put
// Start of Date Number get and put
public void setDate(double d){
date = d;
}
public double getDate(){
return date; // gets data from file to return to GUI
}
// end of Date get and put
// Start of bmi Number get and put
public void setBmi(double b){
bmi = b;
}
public double getBmi(){
return bmi; // gets data from file to return to GUI
}
// end of bmi get and put
}
-
Hopefully someone else can help you, but I still am at a loss to explain your problem given the data presented. You should tell specifically what is not working -- error message (post it) -- something else?
I suspect that your problem could very well still lie in code not posted.
A great resource that has helped me and will probably help you is an article entitled How To Ask Questions The Smart Way. It will tell you how to formulate your questions so that the folks here will be better able to answer them.
Also, sorry to seem anal-retentive, but your code is still unformatted and thus difficult for me (and others to read). Does this formatted post seem easier for you to read (it does for me)?
Best of luckJava Code:import java.io.*; public class FbRecords { private double mship; private double date; private double bmi; /** Creates a new instance of VideoRecord */ public FbRecords() { this(0, 0, 0); } public FbRecords(double m, double d, double b) { setMbrship(m); setDate(d); setBmi(b); } public void setMbrship(double m) { mship = m; } public double getMbrship() { return mship; } public void setDate(double d) { date = d; } public double getDate() { return date; } public void setBmi(double b) { bmi = b; } public double getBmi() { return bmi; } }
- 03-14-2009, 10:35 PM #9
Sorry the error I am getting is with the script for the Next button on the app.
3 lines of code are getting the same error
double cannot be dereferenced
class expected
')'
';'
The three lines of code are
this is within the script already postedtxtMnumber.setText(double.toString(record.getMnumb er()),
txtRdate.setText(double.toString(record.getRdate() ),
txtBmi.setText(double.toString(record.getBmi()));
Sorry again for the formatting or lack thereof, I tried to tidy up but it just gets thrown back to original state when I post.
-
There is no double.toString.
Perhaps you mean to use String.valueOf(...) method or Double.toString(...) instead (yes, capitalization matters in Java).
- 03-15-2009, 12:59 AM #11
Double to string
Thanks for the help so far.
:confused:
Well as I am relatively new to Java and programming in general maybe you could advise as to whether I actually need to convert double to string
All I am trying to do is read the data back from a .txt file that stores the information back into the text fields in app
Grateful for your knowledge and advice.
Java Code:[B]private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {[/B] FbRecords record; try { record = (FbRecords)input.readObject(); //read whole record [COLOR="Green"]txtMnumber.setText(double.toString(record.getMbrsh ip()), txtRdate.setText(double.toString(record.getDate()) , txtBmi.setText(double.toString(record.getBmi()));[/COLOR] }
-
Yes, you need to convert the double to String. Try using either of the methods that I have listed above.
- 03-15-2009, 01:16 AM #13
Sorry, I know I should have a better idea of putting this together but I seem to be falling at the first hurdle, I see what you have given me but I am having problems understanding what you are telling me
As I say I am new to java and I dont fully understand the (...) part of your code, I am unsure what I should be putting in those brakets.
-
You are using double.toString(...), but double is a primitive type, not a class, and so you cannot call methods on this. Instead, and in place of, try either Double.toString(...) or String.valueOf(...).
Again, you put these methods in the exact same place as double.toString, and you pass the exact same parameter.
- 03-15-2009, 01:49 AM #15
I know I am missing the point, but I cannot put my finger on it
I have tried both of the above but the complete construction of 1 line of valid code seems to be something that I cannot put together.
I have tried
txtMnumber.setText(Double.toString(record.getMnumb er));Hopefully I am constructing the code the way you mean but if not then could you advise please.txtMnumber.setText(String.valueOf(record.getMnumbe r));
-
If those statements don't work then we'll have to back up and reassess. Again, what error messages, if any, are you now receiving and on what lines are these errors being thrown? Consider this as if it's a new problem, and your job is to shed as much light on the problem as possible. Best of luck.
- 03-15-2009, 02:13 AM #17
Fubarable, thanks for your assistance with this, if I wasnt losing my hair id be pulling it out.
The error messages I get
cannot find symbol
symbol : variable getMnumber
location: class fatbustersasses3.FbRecords.getMnumber)
cannot find symbol
symbol: methodtoString(fatbustersasses3.FbRecords.getMnumb er)
location: class.java.lang.Double
I hope this tells you something because I am clueless at this point.
- 03-15-2009, 02:22 AM #18
Member
- Join Date
- Mar 2009
- Posts
- 79
- Rep Power
- 0
The symbols getMnumber and methodtoString don't exist.
Could you post the complete class how you have it right now?
-
bubbless is right -- your record object (the FbRecords class actually) doesn't have a getMnumber() method. This has nothing to do with double vs Double (interesting how solving one error uncovers another). Are you using the correct spelling?
the key lesson here is to believe what the error messages are telling you and to try to use this information to solve the problem.
- 03-15-2009, 02:43 AM #20
Class files
The class file fbRecords is
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fatbustersasses3; import java.io.*; //library statement /** * * @author Student 052109 * * This class is for the member records */ public class FbRecords { private double mship; private double date; private double bmi; /** Creates a new instance of VideoRecord */ public FbRecords() { this(0,0,0); } public FbRecords(double m, double d, double b) { setMbrship(m); setDate (d); setBmi(b); } // Start of membership Number get and put public void setMbrship(double m){ mship = m; } public double getMbrship(){ return mship; // gets data from file to return to GUI } // end of membership get and put // Start of Date Number get and put public void setDate(double d){ date = d; } public double getDate(){ return date; // gets data from file to return to GUI } // end of Date get and put // Start of bmi Number get and put public void setBmi(double b){ bmi = b; } public double getBmi(){ return bmi; // gets data from file to return to GUI } // end of bmi get and put }
The app is as follows - frmBmi
Sorry this code is so long but you did ask for all, I have tried to keep the normal bumpf that netbeans chucks in.Java Code:package fatbustersasses3; import java.text.*; // import library to enable import java.io.*; // import libarary to enable input and output to a file /** * * @author * * This is the .java file that drags all the information from the various class files * FbRecords - Membership Records CLASS file * Conversion - Converts Mesurements and Weights ONLY * Formula - formula to calculate the BMI */ public class frmBmi extends javax.swing.JFrame { ObjectOutputStream output; ObjectInputStream input; File file = new File(new File(getClass().getResource("membership").getFile()),"mbrship.txt"); /** Creates new form frmBmi */ public frmBmi() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void cmdCloseAppActionPerformed(java.awt.event.ActionEvent evt) { // Close Application: System.exit(0); } private void cmdCalculateActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // Variables using sensible nameing conventions double height; double weight; double outputBmi; String outbmi; boolean ok; ok = true; //setting variable as valid to start //Start of try catch for non numeric data being entered in the height field try { height = Double.parseDouble(txtHeight.getText());//expect numeric data only weight = Double.parseDouble(txtWeight.getText());//expect any numerical input } catch (NumberFormatException n) {//to catch none numeric input Optpane.showMessageDialog(this,"Enter numbers only please", "please re-enter",Optpane.ERROR_MESSAGE); // Optpane kicks in on error ok = false; //boolean to trigger Optpane on alpha entry } //End of height non numeric data try catch statement // try catch statements for height if under 100cm and over 300*************** try { height = Double.parseDouble(txtHeight.getText()); //read from screen as integer if (height > 300) throw new IllegalArgumentException("Maximum height of 300cm's"); // set a trap to catch numbers > 300 if (height < 100) throw new IllegalArgumentException("Minimum height 100cm's"); // set a trap to catch numbers < 100 } catch (NumberFormatException e) // will catch the error if the input is not a number { Optpane.showMessageDialog(this,"Height between 100 + 300cm's","ERROR",Optpane.ERROR_MESSAGE); ok=false; } catch (IllegalArgumentException e) //will catch the errors outside of the parameters set { Optpane.showMessageDialog(this,e.getMessage(),"Error",Optpane.ERROR_MESSAGE); ok=false; // e.getMessage will get the message for e as set in the trap } //end of height try catch statement*************** // Start of weight try catch statement try { weight = Double.parseDouble(txtWeight.getText()); //read from screen as double if (weight > 160) throw new IllegalArgumentException("Maximum Weight of 160Kg's"); // set a trap to catch numbers > 160 if (weight < 30) throw new IllegalArgumentException("Minimum Weight 30Kg's"); // set a trap to catch numbers < 30 } catch (NumberFormatException e) // will catch the error if the input is not a number { Optpane.showMessageDialog(this,"Weight between 30 & 160Kg's","ERROR",Optpane.ERROR_MESSAGE); ok=false; } catch (IllegalArgumentException e) //will catch the errors as set up in the trap { Optpane.showMessageDialog(this,e.getMessage(),"Error",Optpane.ERROR_MESSAGE); ok=false; // e.getMessage will get the message for e as set in the trap // End of if statement for Weight } height=Double.parseDouble(txtHeight.getText()); weight=Double.parseDouble(txtWeight.getText()); outputBmi = Formula.bmi(height,weight); txtBmi.setText(outbmi=bodymass.format(outputBmi)); // End of BMI Formulae // If Statements for results : OK, OVERWEIGHT & UNDERWEIGHT if (outputBmi < 18.5) { txtResults.setText("Underweight"); } else{ if (outputBmi > 24.9){ txtResults.setText("Overweight"); } else txtResults.setText("OK"); } //End of if staements for txtResults } private void cmdAddRecordActionPerformed(java.awt.event.ActionEvent evt) { // Add record button code FbRecords record; try { record = new FbRecords( Double.parseDouble(txtMnumber.getText()), Double.parseDouble(txtRdate.getText()), Double.parseDouble(txtBmi.getText())); output.writeObject(record); // writes the record } catch (IOException e) { Optpane.showMessageDialog(this, "Error adding a record","File Write Error",Optpane.ERROR_MESSAGE); } /* Clear cells after adding record*/ txtMnumber.setText(""); txtRdate.setText(""); txtBmi.setText(""); txtGender.setText(""); txtAge.setText(""); txtHeight.setText(""); txtHconversion.setText(""); txtWeight.setText(""); txtWconversion.setText(""); txtResults.setText(""); } private void cmdNewFileActionPerformed(java.awt.event.ActionEvent evt) { // Creates new file on press of the new button try{ output = new ObjectOutputStream(new FileOutputStream(file)); } catch (IOException e) { Optpane.showMessageDialog(this, "error with the input file", "File Error", Optpane.ERROR_MESSAGE); } /* Disables Add before the file has been created */ cmdAddRecord.setEnabled(true); } private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) { // Next Button code FbRecords record; //reads the ‘next record’ ie file is already open from reading the first record try { //file is already open record = (FbRecords)input.readObject(); //read whole record // put record fields in to the screen fields txtMnumber.setText(Double.toString(getMnumber())); // txtRdate.setText(Double.toString(record.getRdate()), // txtBmi.setText(Double.toString(record.getBmi())); } catch (IOException e) { Optpane.showMessageDialog(this, "IO Error reading file, possible EOF","File Read Error",Optpane.ERROR_MESSAGE); cmdNext.setEnabled(false); //this should disable the next button on the last record so u dont get EOF error message cmdAddRecord.setEnabled(false); // Disables next but still displays EOF error message. } catch (ClassNotFoundException e) { Optpane.showMessageDialog(this, "Class Error reading next record","File Read Error",Optpane.ERROR_MESSAGE); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmBmi().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JOptionPane Optpane; private javax.swing.JLabel ageLabel; private javax.swing.JLabel bmiLabel; private javax.swing.JButton cmdAddRecord; private javax.swing.JButton cmdCalculate; private javax.swing.JButton cmdCloseApp; private javax.swing.JButton cmdFirst; private javax.swing.JButton cmdNewFile; private javax.swing.JButton cmdNext; private javax.swing.JButton cmdSearch; private javax.swing.JLabel genderLabel; private javax.swing.JLabel heightLabel; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JLabel mnumberLabel; private javax.swing.JLabel regDateLabel; private javax.swing.JLabel resultsLabel; private javax.swing.JTextField txtAge; private javax.swing.JTextField txtBmi; private javax.swing.JTextField txtGender; private javax.swing.JTextField txtHconversion; private javax.swing.JTextField txtHeight; private javax.swing.JTextField txtMnumber; private javax.swing.JTextField txtRdate; private javax.swing.JTextField txtResults; private javax.swing.JTextField txtWconversion; private javax.swing.JTextField txtWeight; private javax.swing.JLabel weightLabel; // End of variables declaration DecimalFormat bodymass = new DecimalFormat("#0.0"); }
Thanks!
Similar Threads
-
Hi Am New To Use Netbeans
By arunkumarinfo in forum NetBeansReplies: 1Last Post: 01-23-2009, 04:18 AM -
Need Help in Netbeans please
By Akora in forum New To JavaReplies: 3Last Post: 01-21-2009, 05:43 PM -
cannot run web app with Netbeans
By CirKuT in forum New To JavaReplies: 5Last Post: 10-28-2008, 03:48 PM -
netbeans
By sweet angle in forum NetBeansReplies: 1Last Post: 08-05-2008, 04:06 AM -
netbeans 64 bit
By caspermel in forum NetBeansReplies: 1Last Post: 06-26-2007, 10:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks