Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
Hi,
I am a big noob in java and facing problem in importing my own class.
 
My dir structure is : F:/learning servlets/beer-v1/src/com/example/
 
There are 2 dir under this path viz. web & model.
Web contains java Container file(Showbeer.java) and model has a model(BeerExpert.java) file.
 
I want to use a method in BeerExpert.java in Showbeer.java. I have written package statement for both of the classes and have also imported com/example/model inside Showbeer.java. But i am getting a compiler error. Can anyone help me on this ?
 

Thanks in advance.
Pasting a snippet of both the classes for reference.
 

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 -cp "C:\Program Files\Apache Software Foundat
ion\Tomcat 6.0\lib\servlet-api.jar" -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;
                        ^
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
 
F:\Learning Servlets\beer-v1>
Posted 24-Mar-12 1:34am
Edited 24-Mar-12 2:00am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 24 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100