Divelog errors
Hi everyone.
I am trying to compile the Divelog.java file but seem to get the following two errors.
C:\>javac c:\divelog\Divelog.java
c:\divelog\Divelog.java:7: class DiveLog is public, should be declared in a file named DiveLog.java
public class DiveLog extends JFrame
^
c:\divelog\Divelog.java:63: cannot resolve symbol
symbol : class WebSite
location: class divelog.DiveLog
tabbedPane.addTab("Favorite Web Site", null, new WebSite(), "Click here to see a web site" );
^
2 errors
I have installed j2se in the following directory c:\j2sdk1.4.2
The Divelog files are located in the following directory c:\divelog\
(so for example my Divelog.java file is located in c:\divelog\Divelog.java
Please could anyone help me with this problem, all the dive log files are correct, as i have checked several times.
Any help would be very much so aprreciated
hi, thanks for replying.
the file Divelog.java is as follows
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog extends JFrame
{ // Opens Divelog class
private JTabbedPane tabbedPane; //Not assigned yet.
public DiveLog()
{ // Opens Divelog constructor
// Create a frame object to add the
// application GUI components to.
super("A Java(TM) Technology Dive Log");
// Closes from title bar
//and from menu
addWindowListener(new WindowAdapter()
{ // Opens addWindowListener method
public void windowClosing(WindowEvent e)
{ // Opens windowClosing method
System.exit(0);
} // Closes windowClosing method
}); // Closes addWindowListener method
// Tabbed pane with panels for Jcomponents
// Instantiate JTabbedPane with keyword new
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
// Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
// Calls a method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu buildMenu();
getContentPane().add(tabbedPane);
} // Ends constructor
private void populateTabbedPane()
{ // Opens populateTabbedPane method definition
// Create tabs with titles
tabbedPane.addTab("Welcome",null,new Welcome(),"Welcometo the Dive Log");
tabbedPane.addTab("Diver Data",null,new Diver(),"Click here to enter diver data");
tabbedPane.addTab("Log Dives",null,new Dives(),"Click here to enter dives");
tabbedPane.addTab("Statistics",null,new Statistics(),"Click here to calculate" +" dive statistics");
tabbedPane.addTab("Favorite Web Site", null, new WebSite(), "Click here to see a web site" );
tabbedPane.addTab("Resources",null,new Resources(),"Click here to see a list " +"of resources");
} //Ends populateTabbedPane method
// Method header
private void buildMenu()
{ // Opens buildMenu method definition
// Instantiates JMenuBar, JMenu,
// and JMenuItem.
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Ends buildMenu method
//Adds the item to the menu object
menu.add(item);
//Adds the menu object with item
//onto the menu bar
mb.add(menu);
//Sets the menu bar in the frame
setJMenuBar(mb);
}// Closes buildMenu method
// main method and entry point for app
public static void main(String[] args)
{ // Opens main method
DiveLog dl = new DiveLog();
dl.pack();
dl.setSize(765, 690);
dl.setBackground(Color.white);
dl.setVisible(true);
} // Closes main method
} //Ends class
the divelog folder aslo contains several other filse relevent to the divelog application(as followed from the tutorial)
Similar Messages
-
Another cannot find symbol error (DiveLog)
Hi I am fairly new to java and I decided to try the tutorial DiveLog. I followed the instructions, however when I try to compile it, not with the DOS command, I keep getting an error stating that, Cannot find symbol class ..... The errors keep recurring at the tabbedPane.addTab(".....",
package DiveLog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
{ // Opens class
public JTabbedPane tabbedPane;
public JFrame dlframe;
public DiveLog()
{ // Opens contructor
//Create a frame object to add the application
//GUI components to.
dlframe = new JFrame("A Java(TM) Technology Dive Log");
// Closes from title bar
//and from menu
dlframe.addWindowListener(new WindowAdapter()
{ // Opens addWindowListener method
public void windowClosing(WindowEvent e)
{ // Opens windowClosing method
System.exit(0);
} // Closes windowClosing method
}); // Closes addWindowListener method
// Tabbed pane with panels for Jcomponents
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
//A method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
} //Ends the constructor
private void populateTabbedPane()
{ // Opens populateTabbedPane method
// Create tabs with titles
tabbedPane.addTab("Welcome",
* null,*
* new Welcome(),*
* "Welcome to the Dive Log");*
* tabbedPane.addTab("Diver Data",*
* null,*
* new Diver(),*
* "Click here to enter diver data");*
* tabbedPane.addTab("Log Dives",*
* null,*
* new Dives(),*
* "Click here to enter dives");*
* tabbedPane.addTab("Statistics",*
* null,*
* new Statistics(),*
* "Click here to calculate dive statistics");*
* tabbedPane.addTab("Favorite Web Site",*
* null,*
* new WebSite(),*
* "Click here to see a web site");*
* tabbedPane.addTab("Resources",*
* null,*
* new Resources(),*
* "Click here to see a list of resources");*
* } //Ends populateTabbedPane method*
private void buildMenu()
{ // Opens buildMenu method
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
} //Ends the buildMenu method
} //Ends class
If you could help me, please explain it into terms that I would understand as I am still new to the entire language. Thankscannot find symbol: whatever class or method signature or variable you use was never declared. It's as simple as that. Make sure that the names are correct; if a class is missing (thanks a bunch for omitting the relevant part of the error message :p), ensure the compiled .class file is in the classpath, if a method isn't found make sure that the arguments are provided exactly in the same order, number and type as the method declaration declares, and if a variable is missing make sure that you actually declared it.
Learn about code tags when posting code next time, by the way. -
Another DiveLog can't resolve symbol error
I am using NetBeans to go through the DiveLog tutorial, which I have first typed, then cut/pasted in (hence I've not included it here). On compilation I get the following error:
divelog/DiveLog.java [41:1] cannot resolve symbol
symbol : method addTab (java.lang.String,<nulltype>,divelog.Welcome,java.lang.String)
location: class javax.swing.JTabbedPane
tabbedPane.addTab("Welcome",
^
1 error
Errors compiling divelog (->).
The rest of the line looks like this:
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
(Note that I have cut out all the other tabs, just to focus the mind)
As I am sure you expect if I set the component parameter to null (rather than new Welcome()) it compiles just fine.
I have read the troubleshooting tips on the tutorial, and understand that I am not compiling the whole package, but as far as I know I am! I highlight the package and compile all, I have compiled the project, and both with the same result. I have also read many, many newsgroup entries on the same subject and I have been trying all the various solutions for the last two days.
I note that whilst the others have an error that points to Welcome, the error message I get is on the symbol addTab.
I get the same error if I javac it too. (from the Divelog directory I typed javac -classpath d:\java\myjava\ DiveLog.java, and also tried setting a CLASSPATH environmental variable)
I have my path (environmental variable) set to: d:\java\j2sdk_nb\j2sdk1.4.2\bin
I have also set CLASSPATH to d:\java\myJava
Please remember the pain of newbie!
Thanks, Myles
PS I am working in Windows XPThe compiler is saying that in the JTabbedPane class, there is no method that takes a String, a null, a divelog.Welcome, and another String as parameters. I am guessing that in the divelog.Welcome class source code, you are missing something like the bolded text below.
public class Welcome extends JPanel
I'm making this guess because the JTabbedPane needs a Component for the third argument. If you still can't make sense of this, post the page of the tutorial so we can look at it. -
Error compling DiveLog app,
Hi,
I am trying to build the DiveLog app from the "Building an Application". I have just completed the first part and when I try to complie it I get this error:
error: cannot read: DiveLog.java.
Thsi error is not covered in the PDF that I downloaded. My version of the DiveLog.java file is held in C:\Java\diveLog.
Any ideas as to what I am doing wrong ?
Thanks
StephenO.K.
My file is in a folder called diveLog under another folder called Java, so the address is C:\Java\diveLog\DiveLog.java. All the other class files needed for the first part of "Building an Application" are also in this diveLog folder.
The command I put in was C:\jdk1.3.1_01\bin\javac divelog\DiveLog.java
And I got this error:
:106: 'class' or 'interface' expected
public static void main(String[] args)
Is that enough info, any ideas what's wrong ?
Stephen -
Class error - cannot resolve symbol "MyDocumentListener"
Hello,
this is a groaner I'm sure, but I don't see the problem.
Newbie-itis probably ...
I'm not concerned with what the class does, but it would be nice for the silly thing to compile!
What the heck am I missing for "MyDocumentListener" ?
C:\divelog>javac -classpath C:\ CenterPanel.java
CenterPanel.java:53: cannot resolve symbol
symbol : class MyDocumentListener
location: class divelog.CenterPanel
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
^
CenterPanel.java:53: cannot resolve symbol
symbol : class MyDocumentListener
location: class divelog.CenterPanel
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
^
2 errors
package divelog;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
import javax.swing.text.*;
public class CenterPanel extends JPanel implements ActionListener
{ // Opens class
static private final String newline = "\n";
private JTextArea comments;
private JScrollPane scrollpane;
private JButton saveButton, openButton;
private JLabel whiteshark;
private Box box;
private BufferedReader br ;
private String str;
private JTextArea instruct;
private File defaultDirectory = new File("C://divelog");
private File fileDirectory = null;
private File currentFile= null;
public CenterPanel()
{ // open constructor CenterPanel
setBackground(Color.white);
comments = new JTextArea("Enter comments, such as " +
"location, water conditions, sea life you observed," +
" and problems you may have encountered.", 15, 10);
comments.setLineWrap(true);
comments.setWrapStyleWord(true);
comments.setEditable(true);
comments.setFont(new Font("Times-Roman", Font.PLAIN, 14));
// add a document listener for changes to the text,
// query before opening a new file to decide if we need to save changes.
MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
comments.getDocument().addDocumentListener(myDocumentListener); // create the reference for the class
// ------ Document listener class -----------
class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
Calculate(e);
public void removeUpdate(DocumentEvent e) {
Calculate(e);
public void changedUpdate(DocumentEvent e) {
private void Calculate(DocumentEvent e) {
// do something here
scrollpane = new JScrollPane(comments);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
saveButton = new JButton("Save Comments", new ImageIcon("images/Save16.gif"));
saveButton.addActionListener( this );
saveButton.setToolTipText("Click this button to save the current file.");
openButton = new JButton("Open File...", new ImageIcon("images/Open16.gif"));
openButton.addActionListener( this );
openButton.setToolTipText("Click this button to open a file.");
whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER);
Box boxH;
boxH = Box.createHorizontalBox();
boxH.add(openButton);
boxH.add(Box.createHorizontalStrut(15));
boxH.add(saveButton);
box = Box.createVerticalBox();
box.add(scrollpane);
box.add(Box.createVerticalStrut(10));
box.add(boxH);
box.add(Box.createVerticalStrut(15));
box.add(whiteshark);
add(box);
} // closes constructor CenterPanel
public void actionPerformed( ActionEvent evt )
{ // open method actionPerformed
JFileChooser jfc = new JFileChooser();
// these do not work !!
// -- set the file types to view --
// ExtensionFileFilter filter = new ExtensionFileFilter();
// FileFilter filter = new FileFilter();
//filter.addExtension("java");
//filter.addExtension("txt");
//filter.setDescription("Text & Java Files");
//jfc.setFileFilter(filter);
//Add a custom file filter and disable the default "Accept All" file filter.
jfc.addChoosableFileFilter(new JTFilter());
jfc.setAcceptAllFileFilterUsed(false);
// -- open the default directory --
// public void setCurrentDirectory(File dir)
// jfc.setCurrentDirectory(new File("C://divelog"));
jfc.setCurrentDirectory(defaultDirectory);
jfc.setSize(400, 300);
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
Container parent = saveButton.getParent();
//========================= Test Button Actions ================================
//========================= Open Button ================================
if (evt.getSource() == openButton)
int choice = jfc.showOpenDialog(CenterPanel.this);
File file = jfc.getSelectedFile();
/* a: */
if (file != null && choice == JFileChooser.APPROVE_OPTION)
String filename = jfc.getSelectedFile().getAbsolutePath();
// -- compare the currentFile to the file chosen, alert of loosing any changes to currentFile --
// If (currentFile != filename)
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
try
{ //opens try
comments.getLineCount( );
// -- clear the old data before importing the new file --
comments.selectAll();
comments.replaceSelection("");
// -- get the new data ---
br = new BufferedReader (new FileReader(file));
while ((str = br.readLine()) != null)
{//opens while
comments.append(str);
} //closes while
} // close try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Open command not successful:" + ioe + newline);
} // close catch
// ---- display the values of the directory variables -----------------------
comments.append(
newline + "The f directory variable contains: " + f +
newline + "The fileDirectory variable contains: " + fileDirectory +
newline + "The defaultDirectory variable contains: " + defaultDirectory );
else
comments.append("Open command cancelled by user." + newline);
} //close if statement /* a: */
//========================= Save Button ================================
} else if (evt.getSource() == saveButton)
int choice = jfc.showSaveDialog(CenterPanel.this);
if (choice == JFileChooser.APPROVE_OPTION)
File fileName = jfc.getSelectedFile();
// -- get the current directory name -------
// public File getCurrentDirectory( );
File f=new File(System.getProperty("user.dir"));
fileDirectory = jfc.getCurrentDirectory();
// -- remember the last directory used --
if (defaultDirectory != fileDirectory)
{defaultDirectory = fileDirectory;}
//check for existing files. Warn users & ask if they want to overwrite
for(int i = 0; i < fileName.length(); i ++) {
File tmp = null;
tmp = (fileName);
if (tmp.exists()) // display pop-up alert
//public static int showConfirmDialog( Component parentComponent,
// Object message,
// String title,
// int optionType,
// int messageType,
// Icon icon);
int confirm = JOptionPane.showConfirmDialog(null,
fileName + " already exists on " + fileDirectory
+ "\n \nContinue?", // msg
"Warning! Overwrite File!", // title
JOptionPane.OK_CANCEL_OPTION, // buttons displayed
// JOptionPane.ERROR_MESSAGE
// JOptionPane.INFORMATION_MESSAGE
// JOptionPane.PLAIN_MESSAGE
// JOptionPane.QUESTION_MESSAGE
JOptionPane.WARNING_MESSAGE,
null);
if (confirm != JOptionPane.YES_OPTION)
{ //user cancels the file overwrite.
try {
jfc.cancelSelection();
break;
catch(Exception e) {}
// ----- Save the file if everything is OK ----------------------------
try
{ // opens try
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
bw.write(comments.getText());
bw.flush();
bw.close();
comments.append( newline + newline + "Saving: " + fileName.getName() + "." + newline);
break;
} // closes try
catch (IOException ioe)
{ // open catch
comments.append(newline +"Save command unsuccessful:" + ioe + newline);
} // close catch
} // if exists
} //close for loop
else
comments.append("Save command cancelled by user." + newline);
} // end-if save button
} // close method actionPerformed
} //close constructor CenterPanel
} // Closes class CenterPanelThere is no way to be able to see MyDocumentListener class in the way you wrote. The reason is because MyDocumentListener class inside the constructor itself. MyDocumentListener class is an inner class, not suppose to be inside a constructor or a method. What you need to do is simple thing, just move it from inside the constructor and place it between two methods.
that's all folks
Qusay -
Error in compiling and running a packaged application
Hi all,
I am new to java and studying alone java from sun's site.Now i am going through sun's step by step programming.From there i got a packaged Application named DiveLog which i wrote and saved in divelog directory in jdk1.2.2which is in C directory.
When i tried to compile it i got the error message as class Resource .java not found.But i have created the file Resource.java and saved in the same divelog directory.
somehow i get rid of the error and looked for the directory but class file is not there.So i understood that Compilation doesn't took place.
Can anyone help me to get rid of the error and compile and run the Application successfully.
Here is the DiveLog application i have written.
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JTabbedPane tabbedPane;
private JFrame dlframe;
public DiveLog()
dlframe = new JFrame("A Java(TM) Technology Dive Log");
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0)
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765,690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
private void populateTabbedPane()
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
tabbedPane.addTab("Diver Data",
null,
new Diver(),
"Click here to enter diver data");
tabbedPane.addTab("Log Dives",
null,
new Dives(),
"Click here to enter dives");
tabbedPane.addTab("Statistics",
null,
new Statistics(),
"Click here to calculate dive statistics");
tabbedPane.addTab("Favorite Web Site",
null,
new WebSite(),
"Click here to see a web site");
tabbedPane.addTab("Resources",
null,
new Resources(),
"Click here to see a list" + "of resources");
private void buildMenu()
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
public static void main(String[] args)
DiveLog dl = new DiveLog();Classpath problem. Read the old threads related to in the classpath problem.
/Sreenivasa Kumar Majji.
Hi all,
I am new to java and studying alone java from sun's
site.Now i am going through sun's step by step
programming.From there i got a packaged Application
named DiveLog which i wrote and saved in divelog
directory in jdk1.2.2which is in C directory.
When i tried to compile it i got the error message as
class Resource .java not found.But i have created the
file Resource.java and saved in the same divelog
directory.
somehow i get rid of the error and looked for the
directory but class file is not there.So i understood
that Compilation doesn't took place.
Can anyone help me to get rid of the error and compile
and run the Application successfully.
Here is the DiveLog application i have written.
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
private JTabbedPane tabbedPane;
private JFrame dlframe;
public DiveLog()
dlframe = new JFrame("A Java(TM) Technology Dive
Dive Log");
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0)
tabbedPane = new
e = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
populateTabbedPane();
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765,690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
private void populateTabbedPane()
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive
"Welcome to the Dive Log");
tabbedPane.addTab("Diver Data",
null,
new Diver(),
"Click here to enter
"Click here to enter diver data");
tabbedPane.addTab("Log Dives",
null,
new Dives(),
"Click here to enter
"Click here to enter dives");
tabbedPane.addTab("Statistics",
null,
new Statistics(),
"Click here to calculate
"Click here to calculate dive statistics");
tabbedPane.addTab("Favorite Web Site",
null,
new WebSite(),
"Click here to see a web
"Click here to see a web site");
tabbedPane.addTab("Resources",
null,
new Resources(),
"Click here to see a
"Click here to see a list" + "of
t" + "of resources");
private void buildMenu()
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new
istener(new ActionListener()
public void actionPerformed(ActionEvent
ed(ActionEvent e)
System.exit(0);
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
public static void main(String[]
d main(String[] args)
DiveLog dl = new DiveLog(); -
Cannon Resolve Symbol, DiveLog Tute Example...
I have followed the Tute "DiveLog" and cannot get it to compile...
I have created the other .Java required and placed the in the same dir...
Divers.java etc...
All files are in c:\java\DiveLog\ FILES ARE HERE.
I have set the path ver.. can complir "Hello World" example works fine so I think the path is set OK...
I have look at this issue from other q's posted at this forum, followed there instructions, but no luck...
All files are from the Sun web site from Tute 1....
Help this is a prob as I start Uni tomorrow and I need to have Java up and running on my machine
code:
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DiveLog
{ // Opens class
private JTabbedPane tabbedPane;
private JFrame dlframe;
public DiveLog()
{ // Opens contructor
//Create a frame object to add the application
//GUI components to.
dlframe = new JFrame("A Java(TM) Technology Dive Log");
// Closes from title bar
//and from menu
dlframe.addWindowListener(new WindowAdapter()
{ // Opens addWindowListener method
public void windowClosing(WindowEvent e)
{ // Opens windowClosing method
System.exit(0);
} // Closes windowClosing method
}); // Closes addWindowListener method
// Tabbed pane with panels for Jcomponents
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
//A method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
} //Ends the constructor
public void populateTabbedPane()
{ // Opens populateTabbedPane method
// Create tabs with titles
tabbedPane.addTab("Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
tabbedPane.addTab("Diver Data",
null,
new Diver(),
"Click here to enter diver data");
tabbedPane.addTab("Log Dives",
null,
new Dives(),
"Click here to enter dives");
tabbedPane.addTab("Statistics",
null,
new Statistics(),
"Click here to calculate dive statistics");
tabbedPane.addTab("Favorite Web Site",
null,
new WebSite(),
"Click here to see a web site");
tabbedPane.addTab("Resources",
null,
new Resources(),
"Click here to see a list of resources");
} //Ends populateTabbedPane method
private void buildMenu()
{ // Opens buildMenu method
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
} //Ends the buildMenu method
public static void main(String[] args)
DiveLog dl = new DiveLog();
} //Ends class
example of one of the other Java file that will not complie...
package divelog;
import javax.swing.*;
import java.awt.*;
public class Resources extends JPanel
{ // Opens class
} // Closes class
Thanks for any help...
ToolBoxYou didn't post the error messages you are getting. That's important. I'll take a guess that you are compiling from the c:\java\DiveLog directory. First, I recommend you rename the DiveLog directory to divelog to match your package name. Then, CD to c:\java and try compiling from there - "javac divelog\DiveLog"
-
Another NoClassDefFound Error. Nothing worked!
Hi. I'm a newbie. I've gone thru the forums but cant find anything to overcome this error msg.I tried the divelog tutorial but when i tried to run using the command line
C:\divelog.java -classpath C:\ divelog.DiveLog
the following error occured:
Error occured during initialization of VM
java/lang/NoClassDefFound Error: java/lang/object
I have J2RE 1.4.1_03 and JDK1.3.1_07 running on Win XP. My env variables are pointed to the J2RE location. Is there a compatibility problem involved?
Please help me to get rid of the error.
Thanks in advance.
Regards,
azareenI had this problem after installing 1.4.2_01 on Linux under slackware9.1.
I found the resolution by running 'java -verbose' as root and as a user and comparing the output, as java ran fine for root.
Turns out that for the user 'java -version' stoipped after loading a couple of jars, and as root it didn't.
These jars in the JAVA_HOME/jre/lib directory only had root read/write permissions. After changing these permissions to all read and root write it worked fine for the user (so far)
Maybe you could look into something similar if you are not the admin on the Windows environment you're working on.
John -
DiveLog.java , i can't run it
Hi,
I have problem running DiveLog.java
I was adviced to complie it in this way because to compile a packaged application i must include the classpath which points to, the directory where the files live.
The way I compile:
C:\jdk1.3.1\bin\>javac �classpath C:\jdk1.3.1\ DiveLog.java
The way I run it
C:\jdk1.3.1\bin\>java �classpath C:\jdk1.3.1\ divelog.DiveLog
This is the error I get if I run the program
Exception in thread "main" java.lang.NoClassDefFoundError: divelog/DiveLog
My DiveLog.java program is in the bin folder
I�m using windows 98
What is wrong?
Thank you for your kind helphi lisa
i had the same problem a month ago trying to run DiveLog.java and the error message was the same.
I did the following to solve my problem, may be you can try if it's relevant to you:
I went and scrutinise my autoexec.bat file and found that some other programs had set some paths in the file. That's why Java was confused where the right path was. So, I removed those unnecessary paths, and left on Windows and Program Files paths in there.
After deleting the redundant paths, I also added the correct path in the autoexec.bat. I added C:\JAVA\BIN
In your case it would be C:\jdk1.3.1\BIN
You will encounter this problem if you had installed QuickTime in your machine.
Just scrutise the autoexec.bat and remove those redundant paths. If you are worried about making mistakes, what you can do is to make a copy of the existing autoexec.bat and call it autoexec-1.bat. If my method fail, you can always copy it back .
Good luck -
hi guys, this is going to drive me crazy... i don't think its a classpath...
here is my program:
package divelog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* @author Administrator
public class DiveLog {
private JFrame dlframe; //Not assigned yet.
private JTabbedPane tabbedPane; //Not assigned yet.
/** Creates a new instance of Class */
public DiveLog() {
// Create a frame object to add the
// application GUI components to.
dlframe = new JFrame("A Java Technology Dive Log");
// Closes from title bar
//and from menu
dlframe.addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
// Tabbed pane with panels for Jcomponents
// Instantiate JTabbedPane with keyword new
tabbedPane = new JTabbedPane(SwingConstants.LEFT);
// Calls method to set color
tabbedPane.setBackground(Color.blue);
tabbedPane.setForeground(Color.white);
//A method that adds individual tabs to the
//tabbedpane object.
populateTabbedPane();
//Calls the method that builds the menu
buildMenu();
dlframe.getContentPane().add(tabbedPane);
dlframe.pack();
dlframe.setSize(765, 690);
dlframe.setBackground(Color.white);
dlframe.setVisible(true);
}// Ends constructor
private void populateTabbedPane()
// Create tabs with title
tabbedPane.addTab(
"Welcome",
null,
new Welcome(),
"Welcome to the Dive Log");
tabbedPane.addTab(
"Diver Data",
null,
new Diver(),
"Click here to enter diver data");
tabbedPane.addTab(
"Log Dives",
null,
new Dives(),
"Click here to enter dives");
tabbedPane.addTab(
"Statistics",
null,
new Statistics(),
"Click here to calculate" +
" dive statistics");
tabbedPane.addTab(
"Favorite Web Site",
null, new WebSite(),
"Click here to see a web site");
tabbedPane.addTab(
"Resources",
null,
new Resources(),
"Click here to see a list " +
"of resources");
}//Ends populateTabbedPane method
// Method header
private void buildMenu()
{ // Opens buildMenu method
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
//Closes the application from the Exit
//menu item.
item.addActionListener(new ActionListener()
{ // Opens addActionListener method
public void actionPerformed(ActionEvent e)
{ // Opens actionPerformed method
System.exit(0);
} // Closes actionPerformed method
}); // Closes addActionListener method
menu.add(item);
mb.add(menu);
dlframe.setJMenuBar(mb);
} //Ends the buildMenu method
public static void main(String[] args)
DiveLog d1 = new DiveLog();
} //end of class
and here is one of the classes:
package divelog;
* Dives.java
* Created on October 31, 2004, 2:14 PM
import javax.swing.*;
//import for layout manager
import java.awt.*;
* @author Administrator
public class Dives extends JPanel{
/** Creates a new instance of Dives */
public Dives() {
basically the class does nothing "for now" but still my program is giving me an error message. i tried to set the classpath to C:\divelog 'where my classes are' but still keep getting the following errors:
DiveLog.java [78:1] cannot resolve symbol
symbol : class Dives
location: class divelog.DiveLog
new Dives(),
^
i am getting six errors for the six classes. i tried everything but still can't get it to work. Its a simple divelog example that i followed!.
does anyone see any problem? please let me know
thanksthats right, i mounted C:\divelog at first and thats
why I couldn't access none of the classes, but after i
mounted C:\ i was able to access them but only with
javac command and not from the compiler itself.I don't understand what you mean here.
>
do you think re-installing the compiler would fix the
problem? Unlikely unless you have corrupted your current installation! It is more than likely a 'path' or 'classpath' problem.
First check that the compiler and runtime system can be accessed.
1) Try ' javac -version'
This should give you a list of options. If you get " 'javac' not recognised...." then you need to add the directory containing 'javac.exe' to your path (not classpath).
For example, if your jdk is located at c:\j2sdk1.4.1 then you will have to add "c:\j2sdk1.4.1\bin" to your path using Control Panel->System->Advanced->Environmental Variables.
2) Now try 'java -version'
This should say which version of java you are using. If it now gives " 'java' not recognised...." then you need to add the bin directory of your JRE to your path. If you have the JDK bin directory in your class path then his should be enough but...
When you get 'java' and 'javac' working then if your program still does not work then it is probably a classpath problem. We would need to see what commands you are typing to go further. -
Please help with small method error
This is straight from:
http://java.sun.com/developer/onlineTraining/new2java/divelog/part1/page7.jsp
Keeps saying ")" is expected....i can't figure it out...usually can figure this error out quick...not this time....
This does not work, and copy/pasting the code from the site does not work
private void buildMenu()
JMenuBar jmb = new JMenuBar();
JMenu menu = new JMenu("File"/**, yes*/);
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new ActionListener()
public void actionPerformed(Action Event ae)
System.exit(0);
}// I added this one hoping it'd fix it.......nope.
This works all by itself....
private void buildMenu()
JMenuBar jmb = new JMenuBar();
JMenu menu = new JMenu("File"/**, yes*/);
JMenuItem item = new JMenuItem("Exit");
The hypothesis is that this is the problem area:
item.addActionListener(new ActionListener()
public void actionPerformed(Action Event ae)
System.exit(0);
}); Thank you!ahhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you, lol!!
spending so much time looking at curly braces didn't go through the rest of the code.....i'm going to go bang my head against the wall.
omfg... -
DiveLog Tutorial - Cannot resolve Symbol
I am having a problem with the DiveLog Tutorial getting the basic code to compile. This is sepcifically on Solaris 2.8 with Java 1.3.1.
I have entered all of the code from Part 1, and have removed all of the syntax errors. (More on this later). I run the Javac command, as directed in the tutorial for Solaris, and I get 6 errors - one for each of the 6 subroutines called - for example it can't resolve "Resources.class". Now thre is a Resources.java, but the javac step will not copmpile. it. So I ran the javac command against Resources.java, and it compiled cleanly, and created the Resources.class file. I reran the javac against DiveLog.java, but it still cannot resolve Resoources.class. All of these files are in the same directory.
Just to be sure, I downloaded the sample code, and tried to compile it. Same problem. I then downloaded a copy of the DiveLog application that will compile under Windows. Same problem.
From what I can see, the compiler does not seem to be looking in the directory the command is executed from to resolve any references. In otherwords - my current working directory is divelog; it contains 7 java files needed for this tutorial. Initially, there was no default classpath set; so i have tried various combinations of CLASSPATH statements, including setting the source directory and the regular classpath. Nothing seems to work.
Anyone have a suggestion on what's wrong here? All of the entries in the forum that I have found relate to WIndows, and not Solaris.
Thanks in advance.
Jerry LawsonFrom what I can see, the compiler does not seem to be
looking in the directory the command is executed from
to resolve any references. To find classes, javac uses the fully qualified class name and searches through the Classpath directories. I know almost nothing about Solaris, but this functionality is the same for all Java platforms, to my knowledge.
Fully qualified means the package name plus the class name. If you have followed the tutorial, you should have these .java files in a directory named divelog and you should have "package divelog;" at the start of each source code file. So, javac is looking for a directory named divelog that contains files with the classes in them.
It might be a simple fix to "cd .." and compile from the directory that contains the divelog directory. Then, assuming the Classpath includes the current directory, javac will look in the current directory for a directory named divelog that contains your .class or .java files.
Otherwise, you need to get the directory 'above' divelog in your Classpath. -
DiveLog program does not compile.
Hi there.
The DiveLog.java program from the step-by-step programming does not work when I tried to compile.
I got the following error messages:
divelog.java:63: cannot find symbol
symbol : class Welcome
location: class divelog.DiveLog
new Welcome(),
^
divelog.java:69: cannot find symbol
symbol : class Diver
location: class divelog.DiveLog
new Diver(),
^
divelog.java:74: cannot find symbol
symbol : class Dives
location: class divelog.DiveLog
new Dives(),
^
divelog.java:79: cannot find symbol
symbol : class Statistics
location: class divelog.DiveLog
new Statistics(),
^
divelog.java:84: cannot find symbol
symbol : class WebSite
location: class divelog.DiveLog
new WebSite(),
^
divelog.java:88: cannot find symbol
symbol : class Resources
location: class divelog.DiveLog
new Resources(),
^
6 errors
Please tell me what is wrong with the code. What should I do to correct the errors?
Ernest EfienamokwuSome of these threads probably describe the problem you have, and provide possible solutions.
An error in the forum software is inserting spaces where they don't belong,
here subCat=sitef orumid
and
here &# 38;
Remove them to use the link.
http://onesearch.sun.com/search/onesearch/index.jsp?qt=divelog&subCat=siteforumid%3Ajava31&site=dev&qp=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums -
Dana Nourie tutorial - compiler error
For the ones that read the tutorial:
when i try to compile DiveLog.java this error appears:
divelog.java:77: cannot resolve symbol
symbol : method addTab (java.lang.String,<null>,java.lang.String)
location: class javax.swing.JTabbedPane
tabbedPane.addTab("Resources",
^
it repeats for all the other classes: Dives, Diver...
If you experienced this problem please tell me what to do.For the ones that read the tutorial:
when i try to compile DiveLog.java this error
appears:
divelog.java:77: cannot resolve symbol
symbol : method addTab
(java.lang.String,<null>,java.lang.String)
location: class javax.swing.JTabbedPane
tabbedPane.addTab("Resources",
^
it repeats for all the other classes: Dives, Diver...
If you experienced this problem please tell me what to
do.tabbedPane.addTab("Resources", <- is there supposed to be a "," there -
Hi
I have been using the building an application tutorial,
(http://servlet.java.sun.com/logRedirect/frontpage-banner-title/http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part4/index.jsp)
but have had problems compiling the divelog.java file.
This is my command line: C:\WINDOWS\Desktop\Javac -classpath C:\WINDOWS\ DiveLog.java
and this is the error I get: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/main
I have downloaded the divelog.java file from the site but still get the same error, Any Ideas???This means there is something wrong with your java compiler setup - the javac program cannot find the jar files containing the compiler.
Maybe you are looking for
-
Hi In MIGO am not getting the GR/IR slip no filed. I need the filed. How to get this? Vijay
-
Possible bad Superdrive - would like to confirm opinion
The specs: iMac G5 w/ iSight 2.1 GHz 1 GB RAM OS 10.4.10 Drive = MatsushitaDVD-R UJ-486 Revision = FA0G Serial number = this is blank for some reason Detachable = No Protocol = ATAPI Unit number = 0 Socket type = internal Burn support: Cache = 2048 K
-
Missing message mapping in SXMB_MONI
Hi All, I am doing a mapping from XI to 2 receivers CRM proxy and JMS adapter. When I executed the whole process, I can see success flags in both XI MONI with 2 nodes one for receiver grouping and other for response. The request message mapping node
-
Error when undate solution manager from 700 to 701(700 enp1)
Hi all, error when undate solution manager from 700 to 701(700 enp1),error:OCS package SAPKITL428 does not match the current software component vector. My current supportstack is as follows : SAP_ABA 700 0016 SAPKA70016 SAP_BASIS 700 0016 SAPKB70016
-
I've a Panasonic AG-HVX200. For importing deinterlaced clips (25p) in a sequence, in the sequence I set Field dominance None. But when I put clips in the timeline, a warning says me that the sequence has a difference format from clips. In fact, clips