aspose file tools*
The moose likes Beginning Java and the fly likes Error: package com.example.model does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error: package com.example.model does not exist" Watch "Error: package com.example.model does not exist" New topic
Author

Error: package com.example.model does not exist

divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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


Divya
Ludmila Snova
Greenhorn

Joined: Aug 31, 2006
Posts: 20
Hi divya,

Do you have package com.example.model in your application?
Do you have class BeerExpert? If so, where it is located?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This is a javac/classpath issue.
The best place to go for help with such issues is the Java In General (Beginner) forum.

Moving...


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
Please reply to resolve the problem
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3455
    
  12
Originally posted by divya sharma:
Please reply to resolve the problem


It would be helpful if you replied to Ludmila's questions first.


Joanne
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

"Please reply to resolve the problem"

How about answering Ludmila's questions, so that we can help you further.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11243
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3455
    
  12
Is the 'C:\Java Prog\Servlet\MyProject\beerV1\src' directory in your classpath ?
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

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

Joined: Jan 25, 2007
Posts: 87
Well it still not work... same error after putting same path on ClassPath
Rajesh Pitty
Greenhorn

Joined: Jan 27, 2005
Posts: 9
first compile BeerExpert.java and then compile the servlet


Rajesh<br /><a href="http://www.rajeshpg.com" target="_blank" rel="nofollow">www.rajeshpg.com</a>
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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

Joined: Jan 27, 2005
Posts: 9
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: package com.example.model does not exist