Hi,
I am kinda new to java netbeans...i have downloaded some java code which is n implementation of the algorithms in the book AI:A Modern Approach.

After extraction, the folder has bin, build, doc and src folders which hold various .class and .java files.

Now my problem is that i want to access these classes in another netbeans project. I tried using the template "project with exisiting sources", but i ended up with an "incorrect package" error all over.

Plss help....

Suvir

Recommended Answers

All 9 Replies

If you also have a .jar file of the classes in that download, you can just add it as a library to your project (from Project Properties window). The same would work for the folder containing the class files themselves.

Thats what doesnt seem to be happening.I added the *.class files' folder in the project properties.It returns an "incorrect package" error...what could be the possible reason...

There is a second possibility that suvirj uses a book that from chapter section to another chapter section change code little and he would like to keep original code, but on other hand he also want to apply changes as suggested in new exercises.
In this case create new project as the book ask you, then in Windows Explorer go to location of your original/previous project, copy files from src (source) folder to src folder of your newly created project directory.
In doing so you will have copy of previous exercise and you can continue with new one.

PS: You just posted reply, but this still does not make sense. Can you clarify issue with consideration of what I wrote above?

I am only trying to add the files that i downloaded into a blank project in NB.
Step 1) I created a new project in NB
Step 2) I right clicked project name->project properties->Libraries, and i added the directory which contains the class files.

But this doesnt do it. In the "project" window ( to the left by default) I see the names of all the classes that i want to add. BUT next to each one, I see a small red exclamation mark which says "Incorrect package" when i hover my pointer over it.

????

Well, if you had read the instructions for that project (which I found here in just a couple of clicks), you might have seen this part:

If you just want to use the classes, all you need to do is put the aima-java/build directory on your CLASSPATH.

Which means you should just add that folder to your Libraries under the Project Properties.

Ok. I had read that before but probably didnt do it properly. I made a new project and added the library as u said.

But still half of them are showing an "incorrect package" error.

What really is an "incorrect package" error?

It means the package declaration in the file does not match the package structure on disk. Are you certain that you added the 'build' folder in the Libraries section using the "Add jar/folder" button? I downloaded the code and added that folder to my own project with no problems at all.

commented: I would have already started abusing and swearing by now :P +4

Umm...it worked...my mistake must have been that I was trying to add the build folder under the "Run" tab also...

Ok, so where do I add the .java files now?

Do as per may previous post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.