简体   繁体   中英

Why Eclipse does not see .jar file of a library?

I have a java project in which I have "Referenced Libraries". In the "Referenced Libraries" I have a .jar file of a library that I use (I use only one external library).

When I try to "Run -> Run" the code I have a NullPointerException. From my previous experience I know that it it (very likely) because my code does not see the library.

I just started to use Eclipse and it can be the I do not "connect" libraries in a correct way. Should I use some options or additional action to force Eclipse to see the .jar file of the library?

ADDED:

By the right click on the library I get a drop-down menu in which I see "Build Path". My be I need to do something there?

Have you tried this? http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29

Add the library's to your build path :]

External JARs should be added with Java Build Path -> Libraries -> Add External JARs.

Generally the lack of wavy red lines under your class references will tell you Eclipse has recognised the JAR ok.

Depending on your target type (you don't say) there may be additional steps to deploy the JAR.

Many things can cause a NullPointerException. It would be useful to see the full error and callstack. In my experience, missing library content manifests as ClassNotFoundExceptions.

Are you sure it's the missing Jar?

NullPointerException will not usually happen if you have a missing jar For that you may get a ClassNotFoundException or MethodNotFoundException

Adding a breakpoint for NullPointerException in eclipse will tell you when it happened

对我来说,发生了这样的情况:我已经添加了JAR,而Eclipse仍然没有注意到它们,然后我去了项目属性-> Java Build Path->库并删除了错误的引用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM