0

I'm using eclipse, the jar files locate in ~/zmx/alg4/algs4.jar, the class file I need is algs4.jar/A.class. my project exists in ~/workspace/test. the jar file are already in Referenced Libraries, how can I use the class file in my project? I've already tried:

import A; private A variable = new A(); 

but it doesn't work.

10
  • what is the package that reside A? Commented Feb 9, 2014 at 14:45
  • It should work if you have algs4.jar in your references libraries. Commented Feb 9, 2014 at 14:46
  • @Iakshman no package in A, only class files. Commented Feb 9, 2014 at 14:50
  • @Ankit I've already done Add External JARS Commented Feb 9, 2014 at 14:52
  • 1
    Is your class in the default package? If not, then unfortunately, it will have to be, because classes in the default package can't be imported, and Princeton decided to put all their classes in the default package. So the only way for your class to used the princeton classes is to also put them in the default package. Commented Feb 9, 2014 at 15:36

1 Answer 1

1

You can’t use classes in the default package from a named package: "[import] require a compile-time error on any attempt to import a type in an unnamed package". You may want to access it via reflection (see below), or repackage your library algs4.jar if you have the source code.

 Class.forName("SomeClass").getMethod("someMethod").invoke(null); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.