Results 1 to 6 of 6
Thread: Import not working
- 12-16-2008, 03:55 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
Import not working
I was wondering if someone could tell me why I'm getting a compilation error when I try to run this. This code is straight out of a book so I must be missing something.
This is the error:
package edu.colorado.collections does not exist
import edu.colorado.collections.CharStack;
Java Code:import edu.colorado.collections.CharStack; import edu.colorado.collections.DoubleStack; import edu.colorado.io.EasyReader; public class BooleanCalc { public static void main(String[] args) { EasyReader stdin = new EasyReader(System.in); double anser; System.out.println("Type a fully parenthesized arithmetic expression:"); answer = readAndEvaluate(stdin); System.out.println("That evaluates to " + answer); } public static double readAndEvaluate(EasyReader input) { final char DECIMAL = '.'; final char RIUGHT_PARENTHESIS = ')'; final String SYMBOLS = "+-*/"; DoubleStack number = new DoubleStack(); CharStack operations = new CharStack(); while (!input.isEOLN()) { if (Character.isDigit(input.peek()) || (input.peek() == DECIMAL)) { numbers.push(input.charInput()); } else if (SYMBOLS.indexOf(input.peek()) >= 0) { operations.push(input.charInput()); } else if (input.peek() == RIGHT_PARENTHESIS) { input.ignore(); evaluateStackTops(numbers, operations); } else { input.ignore(); } } input.skipLine(); if (numbers.size() != 1) throw new IllegalArgumentException("Illegal input expression."); return numberls.pop(); } public static void evaluateStackTops(DoubleStack numbers, CharStack operations) { double operand1, operand2; if ((numbers.size() < 2) || (operations.isEmpty())) throw new IllegalArgumentException("Illegal expression."); operand2 = numbers.pop(); operand1 = numbers.pop(); switch (operations.pop()) { case '+': numbers.push(operand1 + operand2); break; case '-': numbers.push(operand1 - operand2); break; case '*': numbers.push(operand1 * operand2); break; case '/': numbers.push(operand1 / operand2); break; default: throw new IllegalArgumentException("Illegal operation."); } } }
- 12-16-2008, 04:05 AM #2
Member
- Join Date
- Dec 2008
- Posts
- 25
- Rep Power
- 0
yup,you are totally missing some packages.
this 3 packages are not inside J2SE API.Java Code:edu.colorado.collections.CharStack; edu.colorado.collections.DoubleStack; edu.colorado.io.EasyReader;
so you have to compile this 3 packages somewhere else
where the code will start like this normally
what packages are included in the java?Java Code:package edu.colorado
Java 2 Platform SE v1.4.2
you can refers to the link above.Last edited by angelicsign; 12-16-2008 at 06:18 AM.
- 12-16-2008, 05:11 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
I'm not quite sure I understand what you mean by, compiling them somewhere else. How would I compile the packages? Can I do it in my code or do I do that manually.
I tried adding the package edu.colorado; to my code after the three imports but I get this error:
java:7: class, interface, or enum expected
package edu.colorado;
(there is a carat symbol under the P in the error message)
- 12-16-2008, 05:24 AM #4
Member
- Join Date
- Dec 2008
- Posts
- 25
- Rep Power
- 0
okay, i try to give you a simple example.
this code save inside the directory of vehicles
e.g. c:\directory\vehicles\car.java
save and compile the car.java to get a .class fileJava Code:[COLOR="Red"]package vehicles;[/COLOR] public class car{ code here....... }
this is the main test program, may save at anywhere under same directory.
e.g. c:\directory\testProj\testing.java
you have to packaging it before you import the package.Java Code:[COLOR="Red"]import vehicles.car;[/COLOR] public class testing{ code here.... }
similarly, you are trying to import a package that is not inside java library, so you have to find out where the edu.colorado package come from.
copy paste it then compile it to have a .class file so that you'll able to import
edu.colorado.*;
- 12-16-2008, 06:10 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 50
- Rep Power
- 0
OK, I think I've got it now, I'll let you know if I have any issues. Thanks for the clarification.
- 12-16-2008, 06:14 AM #6
Member
- Join Date
- Dec 2008
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
can any one help?? how to import library
By libish in forum New To JavaReplies: 5Last Post: 02-12-2009, 06:51 AM -
import java.util ????
By kris09 in forum New To JavaReplies: 3Last Post: 08-11-2008, 12:39 AM -
How to import a package in Eclipse?
By naipulb in forum New To JavaReplies: 2Last Post: 06-09-2008, 11:04 AM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM -
import statement.
By diRisig in forum New To JavaReplies: 2Last Post: 02-08-2008, 12:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks