Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help error importing own package and class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help error importing own package and class" Watch "help error importing own package and class" New topic
Author

help error importing own package and class

Sahil Ji
Greenhorn

Joined: Apr 04, 2012
Posts: 6
package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Showbeer extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{

String color=request.getParameter("color");
BeerExpert expert=new BeerExpert();
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Selected color is :"+color);

ArrayList list=expert.getBrands(color);
Iterator it=list.iterator();

while(it.hasNext())
{
out.println(it.next());
}

}
}





package com.example.model;

import java.util.*;

public class BeerExpert
{
ArrayList list;

public BeerExpert()
{
list=new ArrayList();
}

List getBrands(String color)
{
if(color.equalsIgnoreCase("black"))
{
list.add("Old Monk");
list.add("Budvizer");
}
else
if(color.equalsIgnoreCase("green"))
{
list.add("Sprite");
list.add("Limca");
}
else
if(color.equalsIgnoreCase("yellow"))
{
list.add("RoyalStag");
list.add("old Monk");
}
else
if(color.equalsIgnoreCase("White"))
{
list.add("WhiteMischif");
list.add("Soda");
}
else
{
list.add("Antiquity");
list.add("Mecdonalds");
}

return list;
}


}



Compiler Error :
F:\Learning Servlets\beer-v1>javac -d classes src\com\example\web\Showbeer.java

src\com\example\web\Showbeer.java:3: package com.example.model does not exist
import com.example.model.BeerExpert; //*(ITS NOT ABLE TO IMPORT THE CLASS BEER EXPERT)******
^
src\com\example\web\Showbeer.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.Showbeer
BeerExpert expert=new BeerExpert();
^
src\com\example\web\Showbeer.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.Showbeer
BeerExpert expert=new BeerExpert();
^
****3 errors
Yalvin Duha
Ranch Hand

Joined: Apr 07, 2012
Posts: 40

Perhaps you are forgetting to pass an appropriate classpath to the Java compiler, e.g.:

Sahil Ji
Greenhorn

Joined: Apr 04, 2012
Posts: 6
i tried but it wont help
Sahil Ji
Greenhorn

Joined: Apr 04, 2012
Posts: 6
Yalvin Duha wrote:Perhaps you are forgetting to pass an appropriate classpath to the Java compiler, e.g.:





Now its giving httpservlet package is not there please help yes above error remove but its not importing java.io and other java packages
Yalvin Duha
Ranch Hand

Joined: Apr 07, 2012
Posts: 40

Then it means that the library jar file that contains HttpServlet implementation is not in your path. What web server or application server are you using? Tomcat? JBoss? GlassFish? Resin? You need to specify where the jar file is located if it's not already in your path, and depending on your OS, you should use ":" (Linux/Unix) or ";" (Windows) to separate each classpath, i.e. src\;path\to\servlet.jar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help error importing own package and class