Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


Java
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;
	}


}


JavaScript
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
Updated 24-Mar-12 1:00am
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900