• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Error: package com.example.model does not exist

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am compling a servlet program.

package com.example.web;

//import com.example.model.*;
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(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println ("Beer Selection Advice<br>");
String c = request.getParameter("color");



BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while (it.hasNext())
{

out.print("<br> try:" + it.next());

}

}
}
while compling this error message displayed as

C:\Java Prog\Servlet\MyProject\beerV1\src\com\example\web\BeerSelect.java:4: package com.example.model does not exist
import com.example.model.*;
^
C:\Java Prog\Servlet\MyProject\beerV1\src\com\example\web\BeerSelect.java:23: cannot resolve symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
C:\Java Prog\Servlet\MyProject\beerV1\src\com\example\web\BeerSelect.java:23: cannot resolve symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors

Tool completed with exit code 1


And here is "BeerExpert" file

package com.example.model;

import java.util.*;

public class BeerExpert
{
public List getBrands(String color)
{
List brands = new ArrayList();

if(color.equals("amber"))
{
brands.add("Jack Amber");
brands.add("Red Moose");
}

else
{
brands.add("Jails Pale Ale");
brands.add("Gout stout");
}

return(brands);
}
}


Please help me to resolve this problem
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi divya,

Do you have package com.example.model in your application?
Do you have class BeerExpert? If so, where it is located?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a javac/classpath issue.
The best place to go for help with such issues is the Java In General (Beginner) forum.

Moving...
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please reply to resolve the problem
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by divya sharma:
Please reply to resolve the problem



It would be helpful if you replied to Ludmila's questions first.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Please reply to resolve the problem"

How about answering Ludmila's questions, so that we can help you further.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes , I do have a "BeerExpert"
Path : C:\Java Prog\Servlet\MyProject\beerV1\src\com\example\model\BeerExpert.java

and it code is on my last post

Thanks
Divya
 
lowercase baba
Posts: 13003
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We also would appreciate it if you would list the source of where this code came from. Aside from copywrite issues, it's just plain polite. Especially since many of those authors hang out here.

I'm pretty sure this code came from the "Head First" book, yes?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the 'C:\Java Prog\Servlet\MyProject\beerV1\src' directory in your classpath ?
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for you reply...

Well Yes this is a code from HEAD First Servlet.

Well That's the path where the "BeerExpert.java" saved

ClassPath :.;C:\j2sdk1.4.2_13\lib
Java_home : C:\j2sdk1.4.2_13
Path :.;C:\j2sdk1.4.2_13\bin

Thanks
Divya
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joanne Neal: "Is the 'C:\Java Prog\Servlet\MyProject\beerV1\src' directory in your classpath ?"

divya sharma: "ClassPath :.;C:\j2sdk1.4.2_13\lib"

Put C:\Java Prog\Servlet\MyProject\beerV1\src in the CLASSPATH as Joanne suggests.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well it still not work... same error after putting same path on ClassPath
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first compile BeerExpert.java and then compile the servlet
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have done the same. No error while complieing "BeerExpert" but while compling "BeerSelect" it show an error coz it's unable to call BeerExpert.
 
Rajesh Pitty
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
navigate to your "src" folder and ,try compliing with this command


javac -classpath . com/example/web/BeerSelect.java



Rajesh
www.rajeshpg.com
[ March 23, 2007: Message edited by: Rajesh Pitty ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic