5
IntelliJ IDEA 12.1.4 Community Edition
Fedora release 18 (Spherical Cow)

Hello,

I have created a package name called com.insystems.gumball

I have a class called Gumball with some functions.

package com.insystems.gumball;

public class Gumball {
    /* functions here */
}

Now I have created a new command line app project called gumball_test

package com.insystems.gumballtest;

import com.insystems.gumball;

public class Main {

    public static void main(String[] args) {
        Gumball gb = new Gumball(5);
    }
}

The problem is that I get a:

unused port statement

and

cannot resolve symbol gumball

Both these projects are in different directories as I want to keep all my packages in a directory that I can import whenever I need them.

I am new to Java and IntelliJ so I am not sure how can I set the path of my packages that can be used in my other projects?

Many thanks for any suggestions,

ant2009
  • 27,094
  • 154
  • 411
  • 609

1 Answers1

5

The problem is in your import com.insystems.gumball; line (this means import gumball class in com.insystems package). Since there is none, you get this error.

You need to import certain class

import com.insystems.gumball.Gumball;

or the whole package

import com.insystems.gumball.*;

This might help to clarify things more

Community
  • 1
  • 1
Tala
  • 8,888
  • 5
  • 34
  • 38
  • Just quick question. I am coming from C/C++ so we always link the *.so and provide a path. In Java how does the import statement know where to find the package, if I haven't provided in path to where the package is located? – ant2009 Aug 15 '13 at 08:39
  • they're looked in the same package and in classpath. Read this http://en.wikipedia.org/wiki/Classpath_(Java) – Tala Aug 15 '13 at 08:42
  • I understand what you mean by the importing the actual class. I have done that and just as expected I still get the cannot find symbol. I think this is because it doesn't know where to find it. I would like to keep my packages self-contained. – ant2009 Aug 15 '13 at 08:42
  • 1
    The question you're asking is all about classPath. Please read the wikipedia article and mainly this: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html – Tala Aug 15 '13 at 08:44