Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use com.javaranch.common in the assignment?

 
Joanne Li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all.
I downloaded the JavaRanchCommon.zip, and tried to use it in the assignment. I am working on UNIX, and I use "setenv CLASSPATH xxx" to set it to the JavaRanchCommon.zip directory. In my program, "import com.javaranch.common;", but the compiler always complain about this import statement. How to solve it? I tried compile with "javac -classpath xxx myclass.java", the same result. thanks.
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this instead:
import com.javaranch.common.* ;
 
Joanne Li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marilyn. I can compile successfully, but got run time error of java.lang.NoClassDefFoundError. Can you pls take a look at my code? Thanks.
import com.javaranch.common.*;

public class DaysOld {

-- code deleted by Marilyn to protect future participants --

}

[This message has been edited by Marilyn deQueiroz (edited January 08, 2001).]
 
Marilyn de Queiroz
Sheriff
Posts: 9065
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joanne Li:
Thanks Marilyn. I can compile successfully, but got run time error of java.lang.NoClassDefFoundError. Can you pls take a look at my code? Thanks.

Joanne -
When I ran your code, I did not get this error. Therefore I think that that error is in the classpath setting rather than in your code. When you compile, you use the "path". When you run, you use the "classpath".

You should set your classpath to include the current directory, the directory where your *.java file is, and the directory where you have JavaRanchCommon.zip.

My classpath is
CLASSPATH=C:\Java;C:\Java\JavaRanchCommon.zip;.
because my DaysOld.java file is in C:\Java and my JavaRanchCommon.zip file is also in C:\Java

 
Joanne Li
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marilyn. I can run my program now, and I just submitted to the nitpick. But I have problem doing the next assignment, NaturalLanguageMultiply, just do not know how to start? I do not understand the requirement of Assignment 3.4. Maybe the sample output is better.
 
paul wheaton
Trailboss
Pie
Posts: 21597
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go and book up on what HashMap does. That should help quite a bit.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic