Cannot compile class with a package

Hello,
I am trying to implement the package example from the SUN Tutorial. It can be found on the page: http://java.sun.com/docs/books/tutorial/java/interpack/QandE/packages-questions.html
I think I am doing like described but it doesn�t work. The files are stored like following on my machine:
D:\Test\Java\mygame\Shared\Utilities.java               (this file can be compiled)
D:\Test\Java\mygame\Server\Server.java                    (can�t be compiled)
D:\Test\Java\mygame\Client\Client.java                    (can�t be compiled)
I have no CLASSPATH set (but I tried), Java is installed in C:\Java\j2sdk, I also tried D:\mygame\Shared\Utilities|Server|Client.java
The error message is:
cannot resolve symbol
Are there any further prerequisites?
Thank you

This is a minimal explanation of packages.
Assume that your programs are part of a package named myapp, which is specified by this first line in each source file: package myapp;
Also assume that directory (C:\java\work\) is listed in the CLASSPATH list of directories.
Also assume that all your source files reside in this directory structure: C:\java\work\myapp\
Then a statement to compile your source file named aProgram.java is:
C:\java\work\>javac myapp\aProgram.java
And a statement to run the program is:
java myapp.aProgram
(This can be issued from any directory, as Java will search for the program, starting the search from the classpath directories.)
Explanation:
Compiling
A class is in a package if there is a package statement at the top of the class.
The source file needs to be in a subdirectory structure. The subdirectory structure must match the package statement. The top subdirectory must be in the classpath directory.
So, you generate a directory structure C:\java\work\myapp\ which is the [classpath directory + the package subdirectory structure], and place aProgram.java in it.
Then from the classpath directory (C:\java\work\) use the command: javac myapp\aProgram.java
Running
Compiling creates a file, aProgram.class in the myapp directory.
(The following is where people tend to get lost.)
The correct name now, as far as java is concerned, is the combination of package name and class name: myapp.aProgram (note I omit the .class) If you don't use this name, java will complain that it can't find the class.
To run a class that's NOT part of a package, you use the command: java SomeFile (assuming that SomeFile.class is in a directory that's listed in the classpath)
To run a class that IS part of a package, you use the command java myapp.aProgram (Note that this is analogous to the command for a class not in a package, you just use the fully qualified name)
Here is a reference: http://java.sun.com/j2se/1.4.1/docs/tooldocs/findingclasses.html

Similar Messages

  • Yet another ALERT: Cannot create class in system package

    I've searched on the forums and seen several postings and none that really explained a solution, just the initial poster replying they fixed the problem. I am new to J2ME and java in general, I'm going off a book and my first test worked fine but this one gives me the the ALERT: Cannot create class in system package, when I select the GO command. The error occurs in the commandAction method where command == go trying to create an alert message. I am using MIDP 2.0 and as I stated new to this whole thing so a detail response would be greatly appreciated and what I need to do to resolve this for now and the future.
    Source code for TextBoxTest.java :
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class TextBoxTest extends MIDlet implements CommandListener
       private TextBox textBox;
       private Alert alert;
       private Command quit;
       private Command go;
       public TextBoxTest()
          // Setup the UI
          textBox = new TextBox("Enter Name", "", 20, TextField.ANY);
          go = new Command("Go", Command.SCREEN, 1);
          quit = new Command("Quit", Command.EXIT, 2);
          textBox.addCommand(go);
          textBox.addCommand(quit);
          textBox.setCommandListener(this);
       protected void startApp() throws MIDletStateChangeException
          Display.getDisplay(this).setCurrent(textBox);
       protected void pauseApp()
       protected void destroyApp(boolean unconditional)
            throws MIDletStateChangeException
       public void commandAction(Command command, Displayable displayable)
          try
             if (command == quit)
                destroyApp(true);
                notifyDestroyed();
             if (command == go)
                alert = new Alert("", "Greetings " + textBox.getString(), null,
    AlertType.CONFIRMATION);
                Display.getDisplay(this).setCurrent(alert);
          catch (MIDletStateChangeException me)
             System.out.println(me + " caught.");
    }

    Ok so my problem isn't with the code it's with the build order. I guess I needed to state that I was following a book and trying to compile and preverify through command line and not using the toolkit or an IDE. So if I use NetBeans 5.0 or the Wireless Toolkit 2.5 I can compile fine.
    So my new question is, can someone show me the steps to build through command line? This is MIDP 2.0.

  • Cannot create class in system package

    Hello,
    I wrote a J2ME game for nokia S40 phones. It compiles without any errors, but when I'm trying to run in on the Nokia 7210 phone emulator I receive the following message:
    Cannot create class in system package.
    Howerver running on the Nokia 6230 phone emulator is ok.
    I have obfuscated my applet as I read in previous topics, but still it does not work.
    Can anyone help me?
    Thanks,
    Alexander.

    You get that error when you try to reference a class that is part of the MIDP framework but isn't installed on the phone.
    The 7210 doesn't support MMAPI or WMA or MIDP 2.0, while the 6230 does, so check that you don't have any references (even an import statement), to classes from those packages (like the javax.microedition.media.*, javax.microedition.lcdui.game.*,javax.wireless.messaging.*, etc. packages hierarchies).
    shmoove

  • Cannot create class in system package while Using Sprite class

    Hi i developed a game using Sprite class & imported
    javax.microedition.lcdui.game.*; package. But when i tried to build this project it gave me "Cannot create class in system package" error. Worst thing is that now again if i build, then it displays error "package javax.microedition.lcdui.game.*; does not exist" . Pls help me

    First exception means that you tried to create a class with the package name equaling one from the predefined libraries in midp/cldc.
    For your second error, add all the jars you are using into the project's classpath.
    Mihai

  • Jsr 180 cannot create class in system package.

    Hi,
    I am trying to run the jsr 180 api sip-example midlets from jbuilder. The project buildes fien but when I run it I get the following:
    C:\JBuilderX\j2mewtk2.0\bin\emulator.exe -Xdevice:DefaultColorPhone -Xdescriptor:"C:\Documents and Settings\aishling\jbproject\aisling\lib\sip-examples.jad"
    Running with storage root DefaultColorPhone
    ALERT: Cannot create class in system package
    Execution completed successfully
    398951 bytecodes executed
    8 thread switches
    434 classes in the system (including system classes)
    2473 dynamic objects allocated (82448 bytes)
    3 garbage collections (58908 bytes collected)
    From going through the archives, I thought I should change the name of the package. So I renamed the directory containing the midlet files from /src/examples to /src/aisexamples and updated each file to include package aisexamples. However this just results in another error (22 + 14) unable to create MIDlet aisexamples.
    Please, please can someone let me know whats going on?
    Thanks,
    Aisling.

    i m also facing the same prob can any body help us

  • Problem with compiling a class with a package

    Hello,
    I am trying to implement the package example from the SUN Tutorial. It can be found on the page: http://java.sun.com/docs/books/tutorial/java/interpack/QandE/packages-questions.html
    I think I am doing like described but it doesn�t work. The files are stored like following on my machine:
    C:\mygame\Shared\Utilities.java               (this file can be compiled)
    C:\mygame\Server\Server.java                    (can�t be compiled)
    C:\mygame\Client\Client.java                    (can�t be compiled)
    I have no CLASSPATH set (but I tried), Java is installed in C:\Java\j2sdk
    If I try to compile the file Client.java with javac the following error message occurs:
    C:\mygame\Client>javac Client.java
    Client.java:7: cannot resolve symbol
    symbol : class Utilities
    location: package shared
    import mygame.shared.Utilities;
    ^
    Client.java:23: cannot resolve symbol
    symbol : variable Utilities
    location: class mygame.client.Client
    Utilities.printMsg("creating output stream");
    ^
    Client.java:32: cannot resolve symbol
    symbol : variable Utilities
    location: class mygame.client.Client
    Utilities.printMsg("writing current date");
    ^
    3 errors
    Are there any further prerequisites?
    Thank you

    Thank you for helping me. Now I am one step forward. Now I can compile each of my Java classes. But if I want to start them with java the following messages occurs. In addition I changed all pathes and class names to lower case.
    C:\mygame\server>java server
    Exception in thread "main" java.lang.NoClassDefFoundError: server
    C:\mygame\server>cd ../client
    C:\mygame\client>java client
    Exception in thread "main" java.lang.NoClassDefFoundError: client
    C:\mygame\client>cd ../shared
    C:\mygame\shared>java utilities
    Exception in thread "main" java.lang.NoClassDefFoundError: utilities
    C:\mygame\shared>

  • Compiling files with the 'package'-statement

    Hi,
    I have a problem compiling files that uses the 'package'-statement:
    I have 2 files ClassA.java and ClassB.java. ClassA uses objects of type ClassB. When I compile ClassA.java the compiler also automatically compiles ClassB.java. No problem so far.
    But when I add "package mypackage" to ClassA.java and ClassB.java and then try to compile ClassA.java with the command "javac -d . ClassA.java" I get the compile-error "Class mypackage.ClassB not found". This would mean that I would have to compile all my files separately?
    Can anybody tell me what I am doing wrong?
    Thx,
    Jan

    I was still working on it, but I think I have it now :-)
    Let me try to summarize what I think/hope that I understand:
    I have the following files in package mypackage:
    C:\src\mypackage\ClassA.java
    C:\src\mypackage\ClassB.java
    with ClassA using ClassB.
    I want to compile them into C:\classes\mypackage\ClassA.class and C:\classes\mypackage\ClassB.class
    I change directory to C:\classes and then give the command
    >javac -d . ..\src\mypackage\ClassA.java
    This didn't work at first because my classpath wasn't set correctly. To make it work I had to add C:\src to my classpath. Which surprised me a little because I thought that the classpath was only used to find *.class files and not by javac to find *.java files?
    If anybody has something to add to this, please feel free to do so.
    Jan

  • Compiling class in a package

    Hi,
    for some reason i can't understand i am having a hard time compiling some of my classes in a particular package.
    Lets say my packages are
    classes\arm\matrix\util\
    classes\arm\pdm\
    I have numerous .class files in the util directory which are precompiled under the matrix\util dir structure.
    I have some classes in pdm folder and in their first line i gave
    package arm.pdm;
    I am trying to compile classes in arm\pdm
    My classes in arm\pdm can read the classes in the matrix\util directroy
    but they can't understand the classes in the same dir
    For example if i have --
    arm\pdm\P1.java and arm\pdm\P2.java
    so if i complie P2.java and am using P1.class in it and i get an error
    saying cannot resolve symbol P1.
    This is the command am using to compile the class
    c:\server\webapps\test\web-inf\classes\arm> javac -classpath . pdm\P2.java
    Please help. .....
    Any help would b greatly apprectiated
    thanks

    Hi,
    for some reason i can't understand i am having a hard
    time compiling some of my classes in a particular
    package.
    Lets say my packages are
    classes\arm\matrix\util\
    classes\arm\pdm\
    I have numerous .class files in the util directory
    which are precompiled under the matrix\util dir
    structure.
    I have some classes in pdm folder and in their first
    line i gave
    package arm.pdm;
    I am trying to compile classes in arm\pdm
    My classes in arm\pdm can read the classes in the
    matrix\util directroy
    but they can't understand the classes in the same dir
    For example if i have --
    arm\pdm\P1.java and arm\pdm\P2.java
    so if i complie P2.java and am using P1.class in it
    and i get an error
    saying cannot resolve symbol P1.
    This is the command am using to compile the class
    c:\server\webapps\test\web-inf\classes\arm> javac
    -classpath . pdm\P2.java
    Please help. .....
    Any help would b greatly apprectiatedDo you have the following file?
    c:\server\webapps\test\web-inf\classes\arm\arm\pdm\P1.class
    That is how your class path is set.
    Try one of the following for your class path
    -classpath ..
    -classpath c:\server\webapps\test\web-inf\classes

  • Import CLASS with no package name in VAJ

    IMport statement in VAJ for .class (no source and No package specified in the class) goes always to the "default package". Is there any way how to:
    1. change package in existing class wihout source
    2. do the "package naming" when the class is imported ?
    3. refer this "default package" by import statement ?(it has no valid name , of course)
    I have tried whatever, but ...? I know, this question was already here in forum at 2001, but, nobody responded ... tks //petr

    There is no way of doing it to the class file. Class files cannot be compiled and therefore cannot be changed.
    You could download a decompiler which gives decompiles the class into a .java file. Then edit that java file to move the class.
    Will

  • Cannot find class in same package but in different file

    I have following two source files. Both the file has same package statement as below
    package java.buron.doeacc ;
    But whenever i try to compile File: shoepolish.java ( mainfram.java compiled succesfully before)
    following error message appear
    ..\..\buron\doeacc\shoepolish.java:12: cannot resolve symbol
    symbol : class MainFrame
    location: class java.buron.doeacc.shoepolish
              MainFrame mainFrame = new MainFrame();
    ^
    ..\..\buron\doeacc\shoepolish.java:12: cannot resolve symbol
    symbol : class MainFrame
    location: class java.buron.doeacc.shoepolish
              MainFrame mainFrame = new MainFrame();
    ^
    Please tell me What is the problem and how it can be solved.
    why cannot find the class that are in same package.
    I have JDK 1.3
    FOLLOWING ARE THE TWO FILES
    File: mainframe.java/////////////////////////////////////////////////////////////////////
    package java.buron.doeacc ;
    import javax.swing.* ;
    import java.awt.*;
    import java.awt.event.* ;
    class MainFrame extends JFrame
         private final String APP_NAME = "Shoe Polish";
         // constructor
         public MainFrame()
              super("Shoe Polish");
              setSize(500, 500);
              setVisible(true);
    File : shoepolish.java
    package java.buron.doeacc ;
    import java.io.* ;
    import java.buron.doeacc.* ;
    class shoepolish
         public static void main(String args[])
              MainFrame mainFrame = new MainFrame();

    The javac compiler uses the Classpath to find classes. If your directory structure is c:\myjava\buron\doeacc (for example) then you need to have c:\myjava in the Classpath when you compile. For example javac -classpath c:\myjava MainFrame.java

  • Compiling classes in their package structure

    I want to compile all classes using one command line
    I have the file structure.
    With .java files contained in two packages
    com.mine.FoldOne
    com.mine.FoldTwo so in the system
    C:/javaProj/src/com/mine/FoldTwo
    C:/javaProj/src/com/mine/FoldOne
    And the folder I want to compile too
    C:/JavaProj/classes
    FromC:/JavaProj I have tried javac @javaProj –d classes
    And
    Javac *.java –d classes
    And several variations of this
    Please tell me how I can compile all my packages using one command line.
    Thanks

    user10778915 wrote:
    Thanks for your advise i will look into building it with antIt's a good tool to know as your projects get more complex. However, if you really do just have 2 packages, then, as suggested by jschell, a simple batch script will suffice, and will probably be simpler. If you just want to get something going as quickly as possible, and don't expect a more complex package structure any time soon, ant may be overkill. But if you're going to be working on bigger projects in the near future, it's probably worth cutting your teeth on ant with a simple project now.

  • Compiling classes with JDK1.5 instead of 1.4

    When compiling this perfectly working piece of code under SJSC2EA2:
    private double eval(double t, int... p) {
    return ( p[0] * Math.pow(1-t, 3) +
    3 * p[1] * Math.pow(1-t, 2) * t +
    3 * p[2] * (1-t) * Math.pow(t, 2) +
    p[3] * Math.pow(t, 3));
    I get this error message (between the dashed lines) from the compiler:
    init:
    deps-jar:
    Compiling 2 source files to C:\Documents and Settings\mohsen madi\Desktop\sjstudio8\bezierAndPostscript\build\classes
    C:\Documents and Settings\Desktop\sjstudio8\bezierAndPostscript\src\BezPSNoComments.java:227: variable-arity methods are not supported in -source 1.4
    (try -source 1.5 to enable variable-arity methods)
    private double eval(double t, int... p) {
    C:\Documents and Settings\Desktop\sjstudio8\bezierAndPostscript\src\BezierPostScript.java:316: variable-arity methods are not supported in -source 1.4
    (try -source 1.5 to enable variable-arity methods)
    private double eval(double t, int... p) {
    2 errors
    BUILD FAILED (total time: 0 seconds)
    Of course, I right-clicked my project, selected proprties, and saw that:
    - in "Libraries", the Java Platform field is set to JDK1.5 (Default)
    - in "Build->Compiling", I added the "-source 1.5" in Additional Compiler Options, and
    - in "Run", I added "-source 1.5" at the VM Options field
    But non of that worked for me!
    Apparently, one would get the same message any time one uses a Java 5 feature like the "variable-length argument list" above or the "enhanced for loop".
    How can I make my project be compiled by JDK 1.5 to make benefit of the Java 5.0 features and not have it go to J2EE 1.4 apparently or wherever it goes?
    Thanks,
    Mohsen Madi

    YOu might want to post this on the Creator 2 EA 2 forum instead.
    Just sign on here like you did to download it and post it in the fourm: https://feedbackprograms.sun.com/login.html?ref=%2Fhome%2Ehtml%3F

  • Problem compiling module with named package

    Hi,
    I'm relatively new to Flex and only recently came upon Flex modules. I am trying to use an interface between the modules and my main application, both to enforce compatibility and to ease data access from the modules to the main application (i.e., the preferred approach on Adobe's module implementation docs). I am, however, running into a problem when trying to compile the module (using Ant) due to its implementation of an interface in a named package. It seems I have a choice between two compilation errors:
    1) an error referring to difference between the named package structure and the unnamed package for my module
    2) an interface not found error when I specify the full package name for the interface in the module "implements" attribute
    #2 seemed more promising as I figured this was just some sort of source path error. After adjusting the source path many times, though, I have been unable to get past the interface not found error. I even tried to compile the interface into a SWC and then place the SWC on the library path.
    Overall, the structure of the code is very simple:
    com.example.workers.IModule
    WorkerModule1
    If I go ahead and make IModule part of an unnamed package, I can get past problem #1 (avoid #2) and get it to compile, but then I do not have the ability to cast the child of the loaded module (ModuleLoader.child) to the interface in my main application to insure that it is of the right type (though I can hack around this by checking if the child has a certain property or function).
    Anyway, I am guessing that there might be something simple that I am missing here--i.e., some way to get the named package onto the path for my mxmlc-based compilation of the module or some way to add the named package structure to my module (adding an xmlns did not accomplish anything). In any case, any help here would be greatly appreciated.
    --jonathan

    You definitely have the wrong version. You want 2.0.1 (we
    haven't made a 2.1). The download on the Flex page is always the
    most current version, 2.0.1 in this case. Try it again.

  • Cannot compile code with debug symbols

    I have a source code file that will not compile with debug symbols. I get an assertion failed in file ../src/regman/regman_local.cc at line 5224. The compile command and output are below.
    /opt/SUNWspro/bin/cc -g -xarch=v9b -xopenmp=noopt -xc99=all -c -o output/spirecon.o spirecon.c
    cg: assertion failed in file ../src/regman/regman_local.cc at line 5224
    cg: Out of range
    cg: 1 errors
    cc: cg failed for spirecon.c
    However without the debug options and using the default -fast switch, i.e.
    /opt/SUNWspro/bin/cc -fast -xarch=v9b -xopenmp=noopt -xc99=all -c -o output/spirecon.o spirecon.c
    it compiles without any problems.
    I was hoping someone might have a suggestion as to how what might cause this type of error.

    I have been told this is bugid: 4420630
    It only happens when you try to use the optimizing
    backend code generator without any optimization.
    (That's what -xopenmp=noopt does)
    If you add an -xO1 flag the assertion should go away, but you
    will also lose some (but not all) of your debuggability.
    --chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Upgraded to R2 CU3 from SP1 CU4, cannot update consoles with provided package

    It appears that I cannot install the Console upgrades... gives error 1642.
    The version we have installed is an x86 version.
    Any Ideas?

    I would suggest you completely remove the SP1 CU4 Console version and install the R2 Console version (located on your SCCM server at %DriveLetter%\Program Files\Microsoft Configuration) Manager\tools\ConsoleSetup
    Then apply the CU3 Console MSP file either via the package that the CU creates for you or directly by copying it from \\%YOURSERVER%\SMS_XXX\hotfix\KBXXXXXXX\AdminConsole\i386 and executing.
    Cheers
    Damon

Maybe you are looking for

  • How to install oracle 11g on oracle linux 6.1.

    Hello everyone here at oracle forum.! I'm new on using the linux and i badly need to learn it including the Oracle Database for making PHP website. Because of this i downloaded all the packages of Oracle Linux Release 6 Update 1 Media Pack for x86 (3

  • Re: error code

    can anyone help me and explain this message im getting from fcp while editing. AN UNEXPECTED ERROR OCCURRED (error code -600) im running FCP Studio pro on powerbook 17" g4. thanks

  • Ipadmini and OpenVPN

    Hello, I'm a new user of Ipad mini. I need to work with openvpn on Windows. I found openvpn on ipad, and get all needed files from my firm's IT specialist (btw he never worked on ipad, and he doesn't know IOS). I've got 4 files: ca.crt, name.crt, nam

  • How to restore my mac mini

    how do i restore my mac mini to factory settings?

  • Imac 27inch display with laptop

    Hi there all, I have a iMac 27inch and would like to know if it is possible to use it as a display when working with my windows work laptop? Cheers Straydingo