Can't import own classes...

I'm very new to java. I rented a book called Java 2 Grand Cru to learn it on my own. It is based on Java 1.3 but I have 1.4 installed. Now I wanted to write a simple program with a class in an other directory. I added that directory to CLASSPATH so my compiler could find it. These are the 2 programs
import printer;
public class test
     public static void main(String[] args)
          (new printer()).print();
}and
public class printer
     public void print()
          System.out.println("test");
}So I want the first class to use the second to print "test"!
Now I can compile public class printer without any problems but when I compile the first one, I get this:
test.java:1: '.' expected
import Printer;
               ^
1 error
Process Exit Code: 1
Time Taken: 00:00
i don't get it. Is there anything changed with the import instruction in the new version of Java2?
regards

It is the error of my code but probably I did something bad with the copy paste thing :-)... The 'P' should be a 'p'
Anyhow, I don't understand your first comment. 'printer.class' isn't a default package. I made it myself...
regards

Similar Messages

  • How can I import a class in my program?

    In my program I want to use a class named "WordExtractor" that resides in a jar file named "poi-3.0.1-FINAL-20070705.jar".
    This jar file is stored on my computer under:
    D:\java_projects\Word Reader\poi-bin-3.0.1-FINAL-20070705\poi-3.0.1-FINAL\poi-3.0.1-FINAL-20070705.jar
    How can I import this class WordExtractor into my program?
    import ????????? ;

    In my program I want to use a class named
    "WordExtractor" that resides in a jar file named
    "poi-3.0.1-FINAL-20070705.jar".
    This jar file is stored on my computer under:
    D:\java_projects\Word
    Reader\poi-bin-3.0.1-FINAL-20070705\poi-3.0.1-FINAL\po
    i-3.0.1-FINAL-20070705.jar
    How can I import this class WordExtractor into my
    program?
    import ????????? ;After you add this jar file to the lib , you can use a tools(rar extracter tools) to extract "poi-3.0.1-FINAL-20070705.jar" file and find the position of that class "WordExtractor" .
    write "import XXXX.WordExtractor"into your program,"XXXX" is the position that you have found.

  • Only a type can be imported. package.Class resolves to a package

    Hi,
    I made a class for database connection named ConnectionClass.class.
    The JSPs in public_html directory working fine with import and session variables.
    but JSPs under public_html/subdirectory are unable to import this Class and also unable to access session variables.
    I have deploy this class under public_html/WEB-INF/classes/ directory.
    and also in a jar file vidyabharti.jar under public_html/WEB-INF/lib directory
    I am importing it in JSPs like
    <%@ page import="vidyabharti.ConnectionClass, java.sql.*" %>
    but i am getting following error
    An error occurred at line: 6 in the generated java file
    Only a type can be imported. vidyabharti.ConnectionClass resolves to a package
    An error occurred at line: 110 in the jsp file: /welcome.jsp
    ConnectionClass cannot be resolved to a type
    109: <%
    110: ConnectionClass cs=null;
    An error occurred at line: 115 in the jsp file: /welcome.jsp
    ConnectionClass cannot be resolved to a type
    cs=new ConnectionClass();
    i am using Tomcat 5.5.28.
    please help me.

    Hello,
    It's a possible issue whith the JDT compiler version of your tomcat distribution.
    You know that jasper is the engine that transform jsp to classes and to achive this goal uses a jdt compiler or the ant task javac compiler.
    First check that the JDT compiler class is present in the trace of the exception you have.
    If this is the case follow the steps of the tomcat documentation in order to use the ant compiler.
    http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html
    Apache Ant, which was used in previous Tomcat releases, can be used instead instead of the new compiler by simply removing the common/lib/jasper-compiler-jdt.jar file, and placing the ant.jar file from the latest Ant distribution in the common/lib folder. If you do this, you also need to use the "javac" argument to catalina.sh.
    If you check the code of the tomcat compilation context seems that you can do the same, without removing any file, by setting the compile parameter of the JspServlet to an arbitrary value diferent from null.
    Try this other alternative by editing the file %TOMCAT_HOME%\conf\web.xml
    and set the compiler attribute as follow
        <servlet>
            <servlet-name>jsp</servlet-name>
            <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
            <init-param>
                <param-name>fork</param-name>
                <param-value>false</param-value>
            </init-param>
            <init-param>
                <param-name>xpoweredBy</param-name>
                <param-value>false</param-value>
            </init-param>
            <init-param>
                <param-name>compiler</param-name>
                <param-value>Ant</param-value>
            </init-param>
            <load-on-startup>3</load-on-startup>
        </servlet>If this works for your problem we can check the jdt code and perhaps make a patch.
    Best reggards,

  • Can't import custom class!

    I have no idea why as3 is so stupid but it is and I have to
    deal with it. Basically, I creatd a Server.as file with the Server
    class but I can't import it into my .fla! Both are in the same
    folder and when I change properties to use AS2 it works! But when
    I'm doing it in as3 it doesn't work...

    you don't need to use a directory structure for your files'
    location, but you need to use the package designation in your class
    definitions.
    for example, if your Server class file is in the same
    directory with your fla, you can use:

  • How can i import my classes in jsp?

    Dear All,
    i want to access my classes in jsp. i am using apache tomcat
    server. let me know where i have to put my own packages and
    how can i use them in jsp.
    thanks

    Put them in directory /WEB-INF/classes under you webcontext. You can use them in your jsp by importing them or using the useBean directive.

  • HELP- Can't Import My Classes

    I've just recently gotten into Java development and have been able to make very basic programs?if you could call them that. To basically introduce myself to Java programming, I thought I'd create a simple tab-based text editor (think Microsoft Notepad with the ability to edit multiple files at once). I've created a basic menu bar class file, a tab-based editor pane/window class file, but am having trouble with the class file I'm using to incorporate the two together. I've had Steven Haines' Java 2 from Scratch at-hand for a week or two now (up to date, no; useful to a degree, yes) and have designed the application with a structure similar to the app in the book.
    The structure of the main class file:
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import menuBar;
    import jPad;
    public class jNotepad extends JFrame implements ActionListener
    menuBar menu=new menuBar();
    jPad jNote=new jPad();
    public jNotepad()
    super("JNotepad v1.0");
    setJMenuBar(menu);
    menu.addActionListener(this);
    jNote=new jPad();
    getContentPane().add(jNote,BorderLayout.CENTER);
    setSize(600,300);
    setVisible(true);
    addWindowListener
    new WindowAdapter()
    public void windowClosing(WindowEvent closer)
    System.exit(0);
    public void actionPerformed(ActionEvent performed)
    JMenuItem item=(JMenuItem)performed.getSource();
    if(item==menu.fNew)
    System.out.println("File->New");
    else if(item==menu.fOpen)
    System.out.println("File->Open...");
    else if(item==menu.fClose)
    System.out.println("File->Close");
    else if(item==menu.fCloseAll)
    System.out.println("File->Close All");
    else if(item==menu.fSave)
    System.out.println("File->Save");
    else if(item==menu.fSaveAs)
    System.out.println("File->Save As...");
    else if(item==menu.fSaveAll)
    System.out.println("File->Save All");
    else if(item==menu.fPrint)
    System.out.println("File->Print");
    else if(item==menu.fExit)
    System.out.println("File->Exit");
    else if(item==menu.eCut)
    System.out.println("Edit->Cut");
    else if(item==menu.eCopy)
    System.out.println("Edit->Copy");
    else if(item==menu.ePaste)
    System.out.println("Edit->Paste");
    else if(item==menu.eDelete)
    System.out.println("Edit->Delete");
    else if(item==menu.hContents)
    System.out.println("Help->Contents");
    else if(item==menu.hAbout)
    System.out.println("Help->About");
    public static void main(String[] args)
    jNotepad jNotepadv10=new jNotepad();
    For some reason or another, whenever I try to compile the java file into a class file, it gives me an error stating that I need periods after the "import menuBar" and "import jPad." Then if I add the periods and recompile, it says I need identifiers after the periods, so I add asterisk identifier masks and recompile again just to be told the packages menuBar and jPad do not exist. I can't go any further with my program until I resolve this issue. Any assistance would be appreciated.

    use package For example pjb is my initals. I like to have top package of all my programs.
    At the top of the java file of NotePad.java, should be
    package pjb.apps.NotePad;Make sure that java file and compiled class file is in that directory
    \pjb\apps\NotePad.java
    \pjb\apps\NotePad.class
    \pjb\apps\Calculator.class
    Ok Now with your imports do the following. A made up JOS program requires apps to use.
    \pjb\os\jos.java
    \pjb\os\jos.class
    In the jos.java i have
    import pjb.apps.*;
    ...jos coding
    public void showAppCalculator() {
      Calculator josCalculator = new Calculator();
      josCalculator.show();
    ...jos codingAnother example is I just want NotePad imported
    import pjb.apps.NotePad;
    ...jos coding
    public void showAppNotePad() {
      NotePadjosNotePad = new NotePad();
      josCalculator.show();
    ...jos codingor make sure the the classes are all in the same directory as your application program.
    See http://java.sun.com/docs/books/tutorial/java/interpack/index.html
    for more details about packages.
    Hope it helps :)

  • How can I import my class or package in JSP?

    Hello.
    I develop jsp. When I assign variables in jsp, everything work fine. For Example:
    connStr="jdbc:oracle:thin:@191.168.0.1:1521:orcl";
    But I want put some variables inside class or package, so using text editor I created and compiled package:
    package Pack1;
    public class Test1 extends java.lang.Object {
    public static void main(String[] args) {
    String ConnStr = "jdbc:oracle:thin:@191.168.0.1:1521:orcl";
    or class
    class Test1 {
    public static void main(String[] args) {
    String connStr = "jdbc:oracle:thin:@191.168.0.1:1521:orcl";
    But as soon as I put in my jsp line
    <%@ page import="Test1" %> or <%@ page import="Pack1.*" %>
    I always have an error.
    JSP Error:
    Request URI:/DateN/search/Search.jsp
    Exception:
    oracle.jsp.provider.JspCompileException:
    Errors compiling:e:\orant\oem8i\apache\apache\htdocs\daten\_pages\_daten\_search\_Search.java
    C:\orant\oem8i\apache\apache\htdocs\daten\_pages\_daten\_search\_Search.java:12: Package DateN not found in import.
    import Pack1.*; (or Test1)
    ^
    1 error
    I using OEM2.2 with Apache-Server under Win2000. I put my classes:
    Test1 in package: in folder: C:\orant\oem8i\Apache\Apache\htdocs\WEB-INF\classes\Pack1
    If just class, when just in folder: C:\orant\oem8i\Apache\Apache\htdocs\WEB-INF\classes
    If I using just class, when I put just in folder: C:\orant\oem8i\Apache\Apache\htdocs\WEB-INF\classes.
    Im stack. Anybody can help?
    Thank you.

    Another way. You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
    Secrets of the iPad Camera Connection Kit
    http://howto.cnet.com/8301-11310_39-57401068-285/secrets-of-the-ipad-camera-conn ection-kit/
     Cheers, Tom

  • Help - import own classes in jsp

    Hey guys..
    I'm working on a Shopping cat project which is in the directory -
    C:\Tomcat 6\webapps\ROOT\cart
    I've written one code in shop-product.jsp as below -
    <%@ page language = "java" contentType = "text/html"
             import = "ShoppingBasket, Product, java.sql.*"
             errorPage = "errorpage.jsp" %>
    <html>
    <head> <title>Welcome to Shop</title></head>
    <body>
    <table width = "385" border="0" cellspacing="0">
    <tr>
    <td colspan="4">More Books from me</td>
    </tr><tr>
    <td colspan="4" align ="right">
    <a href = "<%=response.encodeURL("shop-basket.jsp") %>"> View Basket </a></td>
    </tr><tr>
    <td><b>Ref</b></td><b>Title</b></td>
    <td><b>Price</b></td></td></tr>
    <%
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Connection connection = null;
    connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "rahul");
    Statement stmt = null;
    ResultSet RS = null;
    stmt = connection.createStatement();
    RS = stmt.executeQuery("select * from items");
    int rowCounter = 0;
        while(RS.next())
          String item_id = RS.getString("id");
          String title = RS.getString("title");
          String desc = RS.getString("desc");
          String price = RS.getString("price");
          rowCounter=rowCounter+1;
          String bg=  (rowCounter % 2 !=0) ?"#C0C0C0":"#ffffff";
    %>
    <tr bgcolor = <%=bg%>">
    <td><%=item_id%></td>
    <td><b><%=title %></b><br/><%=desc%></td>
    <td><b><%=price %></b></td>
    <td>
    <a href =" <% response.encodeURL("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price); %> "> Add to Cart </a></td>
    </tr>
    <% } RS.close(); connection.close(); %>
    </table>
    <jsp:useBean id = "basket" class = "ShoppingBasket" scope = "session"/>
    <% String title = request.getParameter("title");
       if(title!=null)
         String item_id = request.getParameter("item_id");
         double price = Double.parseDouble(request.getParameter("price"));
         Product item = new Product (item_id, title, price);
         basket.addProduct(item);
    %>
    </body></html>{code}
    in which ShoppingBasket and Product are the classes which I want to import. Where should I put those class files if my project path is 
    +C:\Tomcat 6\webapps\ROOT\cart+
    I've put class files into Tomcat_home/lib but it is giving me error
    {code}type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP:
    An error occurred at line: 6 in the generated java file
    The import ShoppingBasket cannot be resolved
    An error occurred at line: 7 in the generated java file
    The import Product cannot be resolved
    An error occurred at line: 62 in the jsp file: /cart/shop-products.jsp
    The method addProduct(Product) in the type ShoppingBasket is not applicable for the arguments (Product)
    59:      String item_id = request.getParameter("item_id");
    60:      double price = Double.parseDouble(request.getParameter("price"));
    61:      Product item = new Product (item_id, title, price);
    62:      basket.addProduct(item);
    63:    }
    64: %>
    65: </body></html>
    Stacktrace:
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.{code}
    Please assist me on, how to import my custom made class files..
    Thanks,
    Rahul...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    What You need to do is to place ShoppingBasket class in a package and import to fully qualified class name (which is class name with package name). I also discourage You to use scriptlets - it's an obsolete, old technology.

  • Can't Import java class in form 10g

    Hi All,
    I have tried to call a web service from oracle form 10g
    so, I read your available document (How to call Web service from Form 10g)
    http://www.oracle.com/technology/obe/obe_as_10g/deploy/callws_fromforms/forms_webservice.htm#r1
    but when I've created a web service from WSDL file and I've deployed it to JAR file using Jdeveloper 10g (10.1.2.1.0).
    I tried to import it into form builder 10g but i have the error :
    java.lang.NoClassDefFoundError: oracle/jdeveloper/webservices/runtime/WrappedDocLiteralStub
    Please, can any body help me to solve this problem?

    Have you put the jar file in the classpaths??

  • How can I create a new own class in WebDynpro?

    I test the Web Dynpro for a while and found all the java classes were generated automatically. I've tried to create an own class. But after I rebuild the project, all of my own classes were cleared.

    Hi
    You can create your own class as mentioned in above replies or one more way,
    1. first you create your java project seperately,  there you can write all your business needs and then, make a jar or that then, you can include that project into your WDproject by
    rightclick on WDproject>properties>libraries>addexternaljars>ok
    2. create seperate java project
    rightclick on WDproject>properties>Projects>selectYourjavaProject>ok
    Regards
    Abhijith YS

  • Problem to Import my own classes

    I try to import own classes to unother class
    I have all classes in the same map
    import StockTablePanel;
    when I tried to compile the code it says
    �.� expected
    StockTablePanel;
    What is wrong?

    I try to import own classes to unother class
    I have all classes in the same mapAlso if by the same map you mean the same folder then you don't even have to import the class.

  • "Import Java Classes"in Oracle6i Forms

    Hello
    I have two questions regarding importing java classes in Forms 6i
    1- How we can add my own class to this list, so that I can import it directly in form 6i and use it?
    2- When these classes are used in form development, are they fully imported to client side or only class wrapper is ported to forms. I m asking this question, cuz I want to develop my application with all bussiness logic(Java classes) in middle tier ie Form Server.
    Can anyone guide me in this regard
    Thanks in advance
    Asif

    OK answers to the questions are:
    1) If your class is on the classpath it will be picked up by the Java importer but you have to restart Forms if you add the class to the path
    2) THe java importer is for middle tier. In Forms, all ofthe application logic is on the middle tier and if you want it integrate this with Java the importer will create a PLSQL wrapper to call the Java - in pretty much the same way as ORA_FFI. (So NOT imported into the client)
    There are some white papers on OTN.
    Regards
    Grant

  • Can't find Java Class

    I create Java Class from JDeveloper(version 9.0.4) and I open Oracle Form(Oracle Form Developer version 9.0.4) I set class path and builder class path complete but I can't import JAVA Class into Form.
    (Calling a web service from oracle appkication server 10g forms services)

    Hello,
    put the complete path/filename of your class in the FORMS90_BUILDER_CLASSPATH registry key.
    Francois

  • How to import a class, which is not in a package?

    Hi all,
    I have the following problem:
    A class A is not in a package. In another class B, which is in a package (let's say package X) I want to use the class A. Without importing the class A, I get the error "Cannot resolve symbol".
    Using the import statement import A; gives the error ". expected".
    How can I import that class?
    Best wishes to all ...
    Heiko

    > I have the following problem:
    A class A is not in a package. In another class B,
    which is in a package (let's say package X) I want to
    use the class A. Without importing the class A, I get
    the error "Cannot resolve symbol".
    I think not putting a class in a package is a bad practice. Avoid that.

  • How to import a .class in eclipse?

    I have a .class file w/ out the source, and im tiring to import that into my project.
    So I go to import->File System and check the .class file. It shows up in my project but when I try to instantiate it I get a "can not be instantiated to a type" error.
    any thoughts?
    this is happening to a lot of people in my course.
    thanks!

    Hi,
    i tried that what you sad, but my eclipse can't import that class.
    So: I have eclipse 3.1, and i would like to import a class (without source). I develop at the moment a J2ME project with eclipse.
    The class what i want to import is in a package, so i must to import like this: import net.jscience.math.kvm.MathFP;
    Can you tell me how in the hell can i this class to import?
    (I tried about 6 hours long, and i got some result, but not the really perfect.)
    When i make this subdirectory structure (what is in the import line) into my project, then in eclipse work the auto completing, 'till the class name. :-/. But the class is there. Egal i add an external class folder, i got always the same result.
    Please help me, because my brain at the moment wants to explode.
    Thanks a lot.

Maybe you are looking for

  • How to look for the Table Name

    Hi Friends, Sometimes we need to download the table for the desired information if the same is not available from a particular report. How to look for the table name? Is there a report or a particular feild, where we can find the name of the particul

  • My dashboard no longer works, can anyone help?

    I dont have a clue what ive done but my dashboard no longer works. it will open, i.e screen goes greyish colour, but there are no widgets on the screen and even when i try to put them on it closes automatically. ive had a look in the forums and some

  • Issue withRAW files from Canon 5DMKIII in camera RAW 7.0

    Hello,  I use Adobe Photoshop CS6 with Camera Raw 7. Photoshop  Bridge CS6 do not recognize the RAW files from the Canon 5D Mark III, any idea? Thanks in advance.

  • Problem With Photoshop Ablum

    I can not find the photoshop ablum. I know where it is suppose to be, but all I have are All the Photos or One from a Camera.

  • Audio not exporting with video

    Hello- I am having trouble exporting a H.264 video using the YouTube HD 24 preset, which I have done dozens of times previously. The footage was captured on a DSLR with external sound and synced via plural eyes. The problem is that the audio, which I