0

I'm working on a school project right now, and every time I have in the past, I always make a new Project in IntelliJ IDEA. However, this time she gave us some .class files that have methods in them that we can't see (she described what they do so we know how to use them) but need to use, so they have to be in the same folder, obviously.
SIDENOTE: I'm also new to using Macs, which is what I'm on at the moment.
Anyways, I put the .class files in my src folder that I found in the Project8 folder. I just made an array of the Book objects, which was one of the .class files I moved, and now I need to use a method from the other .class file, named BookInventory.class. I put that file in the src folder just like the other, but it won't let me use the only method in that class, which is LoadBooks.
Here is the LoadBooks signature:
public static void LoadBooks(Book[] b)

And here's the description of it that she gave to us:
"For each element in the array, accepts user input for the book, creates the Book object, and stores the object into the array."

So, when I made the array of Book objects, IDEA made an import statement up top all by itself, I didn't type it:

import java.awt.print.Book;

So why does IDEA recognize the Book.class file and allow me to use it in this .java file for my project, but it doesn't seem to notice the BookInventory.class file?
Any help appreciated, thanks ahead of time.

Mazzone
  • 318
  • 1
  • 4
  • 20
  • Did she give them as individual .class files, or packaged in an archive like a `.jar` file? – Mark Peters Apr 22 '15 at 02:56
  • Individual .class files. Since I posted the question, I've added them to a separate folder I called "class files" and made it a module in my project, and made it a dependency to my project. It's still not letting me call the method, so I have no idea what to do now. – Mazzone Apr 22 '15 at 03:00
  • 1
    I think this should answer your question: http://stackoverflow.com/questions/854264/how-to-add-directory-to-classpath-in-an-application-run-profile-in-intellij-idea – Mark Peters Apr 22 '15 at 03:45

1 Answers1

1

What is happening is when you first typed the line with LoadBooks(Book[] b), IntelliJ could not "see" your class files (you have subsequently loaded them in "class files" and added that as a project library, I presume).

IntelliJ however searched for and found a Book class in the internal java libraries, java.awt.print.Book. Note that this is a different class to the one your teacher gave you, which might have been e.g. edu.myschool.homework.Book.

Firstly, try to delete the line including the import statement, or manually change it to the correct package (your teacher can inform you what it is).

If the same import comes back automatically, you can go into Settings -> Editor -> General -> Auto Import and untick Add unambiguous imports on the fly - this will cause intellij to prompt you before adding imports.

Also, I would ask your teacher to give you the class files in a jar file, since that's the usual approach.

Good luck.

vikingsteve
  • 38,481
  • 23
  • 112
  • 156