JavaCompiler outputs .class files in wrong folder

I'm trying to compile some code using the Compiler API. The code belongs to package "compile", however, upon compiling the code, the class file ends up in the root directory rather than in the "compile" folder as I was expecting. The compiler seems to be ignoring the package info. What am I doing wrong here?
package compile;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import javax.tools.*;
import javax.tools.JavaCompiler.CompilationTask;
public class CompilerTest {
     private static final String code =
          "package compile;\n" +
          "class TestClass {\n" +
          "     public static void main(String[] args) {\n" +
          "          System.out.println(\"Hello World!\");\n" +
          "     }\n" +
          "}\n";
     public static void main(String[] args) {
          JavaStringObject source = new JavaStringObject("compile.TestClass", code);
          Iterable<? extends JavaFileObject> sources = Arrays.asList( source );
          JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
          CompilationTask task = compiler.getTask(null, null, null, null, null, sources);
          System.out.println( task.call() );
     /** Java source from a String */
     private static class JavaStringObject extends SimpleJavaFileObject {
          private final String code;
          public JavaStringObject(String className, String content) {
               super( URI.create("string:///"+className.replace('.','/')+Kind.SOURCE.extension), Kind.SOURCE );
               code = content;
          public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
               return code;
}Thanks

How do we know it is wrong?
You are not showing where you compile and run this from.
Also you are making it more confusing than it needs to be because your test class and the data for the compilation have the same package - I'd put CompilerTest and TestClass into different packages just to remove the potential for confusion.
You are not specifying a -d option to the compiler.
You are not specifying what the working directory is and the classpath when you run your test.
You are not telling us where the generated class file is placed.
When you say root directory do you mean the file system root, or the working directory or what?
With some more information we might be able to either reproduce your fault or alternatively explain to you why what you are observing is the expected behaviour.
Bruce

Similar Messages

  • Class file has wrong version 51.0,should be 49.0

    Dear All,
    I have 2 jdk in my computer, one is 1.7 and another is 1.5. I got a eclipse from my co-worker, checkout project from svn, complied it successful. However, there is error : class file has wrong version 51.0,should be 49.0 when I run it in eclipse( this is google gwt project).
    One of my colleague said I should modify one cache file under the eclipse direcotry, but he forgot the loaction of this file.
    Anyone knows?

    After modified this file : org.eclipse.jdt.launching.prefs under : <project folder>\.metadata\.plugins\org.eclipse.core.runtime\.settings,
    this problem has been fixed.
    The modification is :
    add
    <libraryLocations>\r\n<libraryLocation
    jreJar\="D\:/Java/jdk7/jre/lib/resources.jar"
    jreJavadoc\="http\://docs.oracle.com/javase/7/docs/api/"
    jreSrc\="D\:/Java/jdk7/src.zip" pkgRoot\=""/>\r\n
    to it.
    eclipse is :
    Eclipse Java EE IDE for Web Developers.
    Version: Luna Release (4.4.0)
    Build id: 20140612-0600
    my questions are :
    1. what is this file used for?
    2. when use this file?
    3. why I have to add these information to it by hand rather than generate these automatically when I set jdk in eclipse preference?
    4. why this error occur if this file doesn't has <libraryLocations> when running project(the project compile success before running)?

  • Initialization error : class file has wrong version 49.0, should be 45.3 or

    I have Jdeveloper Base installation and JDK 1.5..the classpath and JAVA_HOME environment variables are set to the respective JDK1.5\bin folders. Even then when i try to make a web application, with a simple JSP page i get the following error :
    Initialization error: class file has wrong version 49.0, should be 45.3 or 46.0 or 47.0 or 48.0 on CLASSPATH ..(followed by a long list of paths)
    pls help,
    thanks

    i have windows XP. i have tried to unset the class path...i get the same error.
    i have JDeveloper 10g 10.1.2.
    i have changed the jdev.conf file to set the Java Home to the path that contains the JDK 1.5..

  • Need help with "class file contains wrong class"

    I have a dbUtil package as
    package dbUtil;
    public class dbConfig {
    public String getHost(String db) {
    This file called dbConfig.java has been compiled with -d option and rthe class files resides in dir <install_dir>/webapps/test/WEB-INF/classes/eb/dbUtil/
    I have a jsp file in <install_dir>/webapps/test/test.jsp which imports the dbUtil package
    <%@ page import="eb.dbUtil.dbConfig" %>
    and I am getting this error:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: -1 in the jsp file: null
    Generated servlet error:
    [javac] Compiling 1 source file
    /opt/hpws/tomcat/work/Standalone/localhost/test/test_jsp.java:12: cannot access eb.dbUtil.dbConfig
    bad class file: /opt/hpws/tomcat/webapps/test/WEB-INF/classes/eb/dbUtil/dbConfig.class
    class file contains wrong class: dbUtil.dbConfig
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    import eb.dbUtil.dbConfig;
    ^
    1 error
    Can anyone tell me what am I doing wrong? I am using tomcat 4.1
    Thanks!
    L.

    Given your java file, the fully qualified name of the class is dbUtil.dbConfig.
    What you are importing is eb.dbUtil.dbConfig
    These things are not the same.
    The root of the classpath for the webapp is the classes directory.
    So either
    1 - specify dbConfig.java to be in package eb.dbUtil
    2 - move the class file into web-inf/classes/dbUtil/dbConfig.class, and import dbUtil.dbConfig.
    Also, by convention, classnames should start with a capital letter ie dbUtil.DbConfig.
    Cheers,
    evnafets

  • Importing my class files from another folder

    hello everybody ,im creating a software package for a new company and want to organise my class files into different folders so that it would be easier for someone to navigate through them and update if necessary ,how do i import an instance of a class in a file that is in a subfolder of the folder that contains the class that is calling it.(sorry for being a bit long winded) iv tried diff things and they didn't work.
    At the moment i have all the files in the one folder,but as i said above want to put them into appropriate folders.
    I would be very gratefull if someone could give me some examples and if not some appropriate links,thanks iv tried looking for this on the net but could not find anything.

    What you should probably do is to organise your classes into a heirarchy of packages not merely folders. Java expects the package structure to be reflected in the directory structure holding both the source and class files. If it's looking for a class called, say, com.mycompany.widgets.MainWidget it expects to find it in a directory com//mycompany/widgets relative the the directory on the class path.
    Use the package directive in each source file to indicate the package path.

  • Storing class file into another folder

    can i compile a java program "abc.java" in folder one and its class file will be automatically created in folder two.

    Yes, you can use the -d flag when invoking javac:
    // *nix/MacOS
    javac -d two/ one/abc.java
    // Windows
    javac -d two\ one\abc.javaFor all javac options, execute:
    javac -help

  • How to include applet in jsp if applet.class file in another folder

    hi,
    i'm getting problem when my applet.class file is not with its appropriate jsp file. i'm using jsp :plugin tag.it work when jsp file n apllet.class file at same location.
    in short my jsp file is at location /webapps/jsp-examples/myproject/includeDemo.jsp
    n applet i want in a WEB-INF folder.
    Plz help me to solve this..
    or give me other way that an applet can be loaded in jsp page n applet should be in WEB-INF file..
    Help me for this

    http://forum.java.sun.com/thread.jspa?threadID=5148764&messageID=9556205

  • Imported files into wrong folder, easy way to move them to another?

    Two things happened to me this weekend using Lr that caused files to go into the wrong folders.
    On one import I forgot to change the folder to a new one and it dropped all of my pics from the CF card into an existing folder. Oops.
    On another import I actually had images from what I would consider two seperate events. One was me goofing around taking pictures of the moon and the others were from St. Pattys day at the pub. So I've got moon pics in my St. Pattys 07 folder.
    So is there an easy way to correct this without deleting and reimporting? I tried the obvious drag and drops of selected files in the grid but it seemed adamant that this was a no-no.
    Sam

    Try from the center of an image and you should get a wornng dialogue about moving on the hard drive when you drop them on the folder you want. Hey do have to be all from the same folder for a given move.
    Try selecting some and doing the arrow trick by the filename in Metadata to go to the folder and then move all you want from one folder to another.
    Rather than in All Photos, as I previously mis-stated.
    Don
    Don Ricklin, MacBook 1.83Ghz Duo 2 Core running 10.4.8 & Win XP, Pentax *ist D
    http://donricklin.blogspot.com/

  • Batch processing saves files in wrong folder.

    I ran into a problem the other day, and I believe an item should be added to the Process Multiple Files window, or perhaps it's a bug that should be squashed.
    I have a folder with many subfolders in it, all full of jpegs. I wanted to use the Process Multiple Files function to convert the jpegs into png files and have the png files placed into the same folder as the jpeg it originated from.
    I have the Destination set to Same as Source, but instead of placing the files into the subfolders, all the images go directly into the parent folder. It was much more time-consuming to try to sort them out than to start over and process each folder individually. I should be able to leave the computer unattended and have the files saved into the proper folders; Instead I had to stay close so I could change the Source folder every few minutes.
    I see no reason why there isn't an option to place the converted files into their original folder. Isn't that what the Same as Source setting is supposed to do?

    Sure, if you owned all of those files and were doing it strictly for yourself you could certainly write a plugin to Acrobat (in C/C++) that could do some/all of the things you asked for.

  • DREAMWEAVER putting files in wrong folder

    Our webhost ATT made a big server switch. I've made all the changes required to point Dreamweaver in the right direction, but the files I try to "put" on our website are going to a hidden folder and not on the active site. I've spent loads of time talking to ATT tech support and they say that the changes need to be made in Dreamweaver. I know enough about Dreamweaver to change and 'put' files on our site. HELP!  This folder has to be updated frequently as we sell tickets for performances online.

    OK, I think that still used the CS4 style menus...
    1. Verify you have your site definition open. From the Files window (F8 if it's not open) in DW, make sure you have the site name showing in the left hand drop down and Local View in the right hand menu at the top. Below those will be your toolbar starting with Connect and ending with Expand. Below that will be all of your site files, which should look something like...
    Where your site should say something like...
    Site - YourAwesomeSite (whatever you named your site in DW)
         -htdocs
              -index.html
              +css
              +fonts
              +pages
              etc...
              etc...
    2. If your site looks like the YourAwesomeSite example above, where everything shows up under the htdocs folder, all you need to do is click and drag the files out of htdocs and drop them on the MyAwesomeSite level. DW will ask you to update links, click Update or Yes. Delete the now empty htdocs folder.
    3. Test the pages
    4. If everything is working in Preview, Go to your settings: Site > Manage Sites > click the site you are working on > Edit
    5. Under the Advanced tab, click Remote Info and make sure /public is in your Host Directory (it might also be called Root Directory or Server Root maybe). If you had to add it, click Apply or Save or Done, whichever one is there. Close the settings window and the Manage Sites Dialogue
    6. Click the Expand button in the Files window. That will make it take up the whole screen and place your remote view on one side and local on the other.
    7. Hit connect. If everything is set up correctly, you should only see the public folder and its contents on the Remote View side. If you see anything else at the top of the file list for remote view, your FTP info is not set up correctly.
    8. If you are seeing the public folder and its contents only, go ahead and click Put to put the entire site to that folder.
    That should do it.

  • Cannot acces (a class), bad class file, class file contains wrong class

    Hi,
    I am trying to implement a Java package and I've never done this before. The package is called 'randomX' and I downloaded it from here: http://www.fourmilab.ch/hotbits/source/randomX/randomX.html
    I downloaded the .tar file on my Windows Vista system, unzipped it, and dragged and dropped into(in my case): C:\Program Files\Java\jdk1.6.0_05\src\java\util
    This is also the directory where Random.java is, so I figured it went there, plus the Java Documentation says that, I think.
    The Java Docs are here: http://www.fourmilab.ch/hotbits/source/randomX/doc/
    Thanks in advance,
    Rommel.

    dcminter wrote:
    No. That's not right - you need to put the JAR file into your classpath.
    [http://en.wikipedia.org/wiki/Classpath_(Java)|http://en.wikipedia.org/wiki/Classpath_(Java)]
    If it doesn't come with a JAR file then you'll need to build it first. Sounds like that might be outside your comfort zone.Thanks for the link and the tip. I have no idea what a JAR file is, much less how to build one.
    However, the thing has a "Makefile" file. Can I build the JAR from this?
    #   Makefile for randomX package
    JAVA = /usr/java/jdk1.5.0_06
    CLASSPATH = $(JAVA)/classes:..:.
    SRC = randomX.java randomJava.java randomHotBits.java randomLCG.java \
          randomMCG.java randomLEcuyer.java randomXdemo.java
    CLASS = $(SRC:.java=.class)
    all:     
         javac -classpath ..  *java ; cp -p *class randomX
    test:
         java randomXdemo
    clean:
         rm -f *.bak *.class
         rm -rf doc
         mkdir doc
         rm -rf randomX
         mkdir randomX
    RELEASE = $(SRC) Makefile
    release:
         tar cfvz randomX.tar.gz $(RELEASE)
    html:
         javadoc -classpath $(CLASSPATH) -d doc *.java
    images:
         ( cd $(JAVA)/images ; tar cfv /tmp/ZZimages.tar . )
         rm -rf doc
         mkdir doc
         mkdir doc/images
         (cd doc/images ; tar xfv /tmp/ZZimages.tar )
         rm -f /tmp/ZZimages.tar
         touch randomX.java
    .SUFFIXES:  .java .class

  • NEW CLASS FILES

    I need to use some different class files to the ones that come with the SDK. Where do I need to put them so that I can import them...? At the moment they are in a folder on my c: drive, but the import keyword cannot find them.. can sumone help? Please email me if you can...
    [email protected]

    I've tried putting it in the classpath, and its says:
    C:\java_code\sheep.java:1: package ann.easyio does not
    exist
    import ann.easyio.*;
    ^
    C:\java_code\sheep.java:7: cannot access Screen
    bad class file: C:\ann\easyio\Screen.class
    class file contains wrong class: ann.easyio.Screen
    Please remove or make sure it appears in the correct
    subdirectory of the classpath.
         public static Screen output = new Screen();
    my classpath is:
    .;.;C:\PROGRA~1\JMF21~1.1\lib\sound.jar;C:\PROGRA~1\JMF
    1~1.1\lib\jmf.jar;C:\WINDOWS\java\classes;.%CLASSPATH%;
    :\ann\easyio;
    i know these class files work cause i've used them at
    uni...
    help!!!???
    thanksYou should have c:\ in your class path. The Screen.java contains a class called ann.easyio.Screen. Since your Screen.java file resides in C:\ann\easyio directory, to refer to that class you should put c:\ in your class path. It should work with that.

  • UDF error: bad class file

    Hi to all!
    i faced with following problem:
    i'm trying to use in message mapping exported Java function and get following error:
    <i>Source code has syntax error:  E:/usr/sap/DXI/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb97a3fc699d611dcaf9d001b78d07a70/source/com/sap/xi/tf/_UserToRoleId_.java:3: cannot access kolpix.echo bad class file: E:\usr\sap\DXI\DVEBMGS00\j2ee\cluster\server0\.\temp\classpath_resolver\Mapb97a3fc699d611dcaf9d001b78d07a70\classpath\Echo_1(kolpix/echo.class) class file has wrong version 50.0, should be 48.0 Please remove or make sure it appears in the correct subdirectory of the classpath. import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.*;import kolpix.echo; ^ 1 error</i>
    There is my Java function:
    package kolpix;
    public class echo {
        public echo() {
        public static String hello(String str) {
            return "Hello "+str+"!";
    in UDF into the <b>Imports</b> textField i just put <b>kolpix.echo;</b>
    and in body function i just put <b>return echo.hello("World");</b>
    Could any one explain what does it mean and what i must do to solve the problem?
    Thx in advance.

    <a href="http://j-integra.intrinsyc.com/support/kb/article.aspx?id=183240">That info explain all</a>

  • Trying to move inner class to a class file

    Hi folks,
    I keep getting an error which puzzles me. I cut the following class (MyDocumentListener) out of an outer class (CenterPanel).
    MyDocumentListener compiles OK but...
    Now when I compile the outerclass I get the folowing error:
    C:\divelog> javac -classpath C:\ CenterPanel.java
    CenterPanel.java:54: cannot access divelog.MyDocumentListener
    bad class file: C:\divelog\MyDocumentListener.class
    class file contains wrong class: MyDocumentListener
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    MyDocumentListener myDocumentListener = new MyDocumentListener(); // define
    the listener class
    ^
    1 error
    ... yes I checked, it is there..
    C:\divelog>dir m*.j*
    Directory of C:\divelog
    MYDOCU~1 JAV 936 03-04-03 11:16p MyDocumentListener.java
    ====================================================================
    MyDocumentListener tests to see if the current document has changed.
    Required fields: boolean documentWasChanged;
    import javax.swing.event.*;
    // ------ Document listener class -----------
    public class MyDocumentListener implements DocumentListener {
    public void insertUpdate(DocumentEvent e) {
    wasChanged(e);
    public void removeUpdate(DocumentEvent e) {
    wasChanged(e);
    public void changedUpdate(DocumentEvent e) {
    public boolean wasChanged(DocumentEvent e) {
    // indicate that the document was changed
    //and test before opening another file or closing the application.
    boolean documentWasChanged = true;
    return documentWasChanged;
    } // close class MyDocumentListener
    ====================================================================
    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.JTextComponent.*;
    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 boolean changed;
    public boolean documentWasChanged;
    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
    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
    // --------- test to see if the current file was modified and give an option to save first.
    if (documentWasChanged) // add and IF filename not null
    // ----- display pop-up alert --------------------------------------------------------------
    int confirm = JOptionPane.showConfirmDialog(null,
    "Click OK to discard current changes, \n or Cancel to save before proceeding.", // msg
    "Unsaved Modifications!", // 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 wants to save changes
    try {
    // let user save the file
    catch(Exception e) {}
    else // let user open a new file
    } // close "if (documentWasChanged)" - display pop-up alert ----------
    JFileChooser jfc = new JFileChooser();
         //Add a custom file filter and disable the default "Accept All" file filter.
    jfc.addChoosableFileFilter(new JTFilter()); // /** found in Utils.java /*
    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();
    // --------- change test was here -----------
    /* a: */
    if (file != null && choice == JFileChooser.APPROVE_OPTION)
    String filename = jfc.getSelectedFile().getAbsolutePath();
    // -- 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(newline + "Save command cancelled by user." + newline);
    // ========= }
    } // end-if save button
    } // close method actionPerformed
    } //close constructor CenterPanel
    // <<<<<<<<<<<<<<<<<
    // <<<<<<<<<<<<<<<<< MyDocumentListener class was here <<<<<<<<<<<<<<<<<
    // <<<<<<<<<<<<<<<<<
    } // Closes class CenterPanel

    You didn't put your MyDocumentListener class in the package divelog.
    Add
    package divelog;to the top of MyDocumentListener.java and recompile.

  • Javac probleme: bad class file error

    I'm new to java
    I have two classes myPoint.jav and TestPoint.java, when I compile them, I error:
    in the command line I type:
    C:\otman\java>javac -g geometry\src\myPoint.java TestPoint.java
    TestPoint.java:8: cannot access myPoint
    bad class file: c:\otman\java\geometry\src\myPoint.class
    class file contains wrong class: geometry.src.myPoint
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
    myPoint p = new myPoint();
    ^
    1 error
    Can some one help me Thanks
    //Here is the class c:\otman\java\TestPoint.java
    import geometry.src.*;
         Testing my class Point
    public class TestPoint {
    public static void main(String[] args) {
              myPoint p = new myPoint();
              System.out.println("thank you very much");
              System.exit(0);
    // And here is the class c:\otman\java\geometry\src\myPoint.java
    package geometry.src;
         class myPoint members and methods of a 3D point
    public class myPoint {
         private double m_x,m_y,m_z;          // the coordinates
         public double getx() {return m_x;}
         public double gety() {return m_y;}
         public double getz() {return m_z;}
         public void setx(double x) {m_x=x;}
         public void sety(double y) {m_y=y;}
         public void setz(double z) {m_z=z;}
         public void translate(double dx,double dy, double dz) {
              m_x += dx;m_y += dy;m_z += dz;
         // Constructor ------------------------------------------------------------
         myPoint(double x,double y,double z) {
              m_x=x;m_y=y;m_z=z;
         myPoint() {
              m_x=0;m_y=0;m_z=0;
         myPoint(myPoint p) {
              m_x=p.getx();m_y=p.gety();m_z=p.getz();
    // ---------------------------------------------------------------------------------

    Thank you for the reply but still have problem.
    I created a directory classes and the directories look like:
    C:\otman\java\
    TestPoint.java
    classes\
    geometry\
    src\
    myPoint.java
    When I compile using the line command:
    C:\otman\java>javac -g -d classes geometry\src\myPoint.java TestPoint.java
    I get the error:
    TestPoint.java:8: cannot find symbol
    symbol : constructor myPoint()
    location: class geometry.src.myPoint
    myPoint p = new myPoint();
    ^
    1 error
    Now the directories look like:
    C:\otman\java\
    TestPoint.java
    classes\
    geometry\
    src\
    myPoint.class
    geometry\
    src\
    myPoint.java
    I think that myPoint was compiled without problem but TestPoint was not compiled and it gives 1 error.
    Can you help me? Thanks.<!--Session data-->

Maybe you are looking for

  • LR 5: Destination Folder Problem in Import Panel

    When making a new  destination folder for import it does not appear in the folder list on  the right side of the import panel until the panel is closed down and  re-opened, at which point the images have to be reselected. Given the slow loading  thum

  • I dropped my phone is water. How do I get it to work again?

    So I dropped my phone in water and I quickly took it out. And it still works, but the speakers are broken on it. How do I get them to work?

  • Is this a scam? too good to be true?

    Saw a ad in kijiji selling a brand new 440s for $1250 cash.  specs  i7 intel Win7 pro no touchscreen fullHD IPS 8 GB RAM 256 SSD 3 year warranty He says its brand new sealed in box. He wont open box until i am 100% sure to buy it. If I buy similar la

  • FI/CO module flow and standard business content InfoCubes , DataSources

    Hi Im new to BW. Can anyone tell me 1) Flow of FI/CO Module for BW. 2) What are the standard InfoCubes and ODS , DataSources for FI/CO module Please let me know. I will assing the points kumar

  • Finding the reference document?

    Hi I have created Credit memo request with reference to Sales order/Billing document. How would I know which one is referenced. Thanks Suddu