• 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

Ch3 Excercise in HFJS

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

My java program locations are as follows:
BeerSelect\src\com\example\model\BeerExpert.java
and BeerSelect\src\com\example\web\BeerSelect.java

My compilation command for the first program is:
javac -d classes src/com/example/model/BeerExpert.java

This compiles fine and creates a class file in the appropriate subdirectory under classes (classes/com/example/model)

But I get the following error when trying to compile the BeerSelect.java file.

C:\projects\BeerSelect>javac -d classes src/com/example/web/BeerSelect.java
src/com/example/web/BeerSelect.java:3: package com.example.model does not exist
import com.example.model.BeerExpert;
^
src/com/example/web/BeerSelect.java:13: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src/com/example/web/BeerSelect.java:13: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors

I think I'm making a very silly mistake here. But cannot figure out what.
Using Java version 1.5.0_06. The source code is as follows (from the book)

package com.example.model;

import java.util.*;

public class BeerExpert{
public ArrayList<String> getBrands(String color){
ArrayList<String> brands = new ArrayList<String>();
if (color.equals("amber")){
brands.add("Jack Amber");
brands.add("Red Moose");
}
else {
brands.add("JAil PAle Ale");
brands.add("Gout Stout");
}
return (brands);
}
}

package com.example.web;

import com.example.model.BeerExpert;
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{
String c = request.getParameter("color");
BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
request.setAttribute("styles", result);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request, response);
}
}


Any help is greatly appreciated.

-Jane
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This gets asked frequently. Have a look at the various previous discussions.

Also, please UseCodeTags when posting code of any length. It makes it much easier to read.
[ March 06, 2008: Message edited by: Ulf Dittmer ]
 
Jane Joseph
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf!

My code compiles fine now

-Jane
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic