java package error....

error :
package does not exist when i try to import one pakage into other package .But actually package exist.what to do?

Replies

  • komputergeek
    komputergeek
    Post your code here.
  • sahilgandhi87
    sahilgandhi87
    komputergeek
    Post your code here.

    Here first i am providing the whole directory structure and that is followed by coding of .java files.
    ....................................
    My directory structure is:

    C:
    MyProjects: (this is folder) EVERYTHING followed by ":" is folder
    beerV1:
    src:,classes: (sub-folders of berV1)
    ................................................................
    src folder contains:

    src:
    com:
    example:
    web:,model: (sub-folders of example)

    web folder contains:
    BeerSelect.java (file)
    >>>>
    model folder contains:
    BeerExpert.java (file)
    ................................................................................
    similarlly classes folder contains:

    classes:
    com:
    example:
    web:,mode:l

    web:
    (this folder does not contain file yet.BeerSelect.class file goes here after successful compilation)

    model:
    BeerExpert.class
    ...............................................................................

    now when i compile BeerSelect.java like:

    C:\MyProjects\beerV1>javac -classpath C:/tomcat/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java

    Three ERRORs:


    src/com/example/web/BeerSelect.java:3: package com.example.model does not exist
    import com.example.model.*;
    ^
    src/com/example/web/BeerSelect.java:17: cannot find symbol
    symbol : class BeerExpert
    location: class com.example.web.BeerSelect
    BeerExpert be = new BeerExpert();
    ^
    src/com/example/web/BeerSelect.java:17: cannot find symbol
    symbol : class BeerExpert
    location: class com.example.web.BeerSelect
    BeerExpert be = new BeerExpert();
    ^
    3 errors

    .............................................................................
    BeerExpert.java has code:

    package com.example.model;

    import java.util.*;

    public class BeerExpert
    {
    public List getBrands(String c)
    {
    List arr = new ArrayList();
    if(c.equals("amber"))
    {
    arr.add("Jack Amber");
    arr.add("Red Moose");
    }
    else
    {
    arr.add("Jail Pale Ale");
    arr.add("Gout Strout");
    }
    return(arr);
    }
    }
    .............................................................................
    BeerSelect.java has code:

    package com.example.web;

    import com.example.model.*;

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;

    public class BeerSelect extends HttpServlet
    {
    public void doPost(HttpServletResponse response,
    HttpServletRequest request)
    throws IOException,ServletException
    {
    String c = request.getParameter("color");
    BeerExpert be = new BeerExpert();
    List a = be.getBrands(c);

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("Selection Beer Advice
    ");

    Iterator i = a.iterator();
    while(i.hasNext())
    {
    out.println("
    try: "+ i.next());
    }
    }
    ..............................................................


    MAIN PROBLEM LIES WITH IMPORTING OF PACKAGE IN BeerSelect.java
    and ERROR is Package not exist but it exist...
  • arunhero99
    arunhero99
    Beer example eh? Surely Head First series 😛
    I have seen this error in java forums.

    the example is linux format. Use windows format:

    javac -classpath C:\tomcat\common\lib\servlet-api.jar;

    Try adding semicolons to separate classpaths...

You are reading an archived discussion.

Related Posts

Hi, is there any mechanical engineer here, who has either worked, read, or done some project related to Plastic injection molding. I'm currently working with a plastics manufacturing company, but...
​ It's kind of strange that the most anticipated sample media from the latest crop of DSLRs is actually HD video, but that's the way the market's going, and the...
It is well-known that for images, symmetric wavelets have some advantages, does anyone know what they are and why? And is CDF 97 a symmetric filter?
Earlier today The Business Insider reported that CNN may have acquired the massively popular CNNbrk Twitter account, which is currently in a heated race with Ashton Kutcher to attain 1...
Mysterious music man A.J. Gannon's put together this wild Rock Band guitar / Speak n' Spell hybrid for use on his upcoming album. Calling it the Speak n' Spellbinder, the...