4 Replies - 318 Views - Last Post: 01 August 2014 - 06:58 AM Rate Topic: -----

#1 cdare77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-July 14

Issue with starting a package

Posted 31 July 2014 - 07:43 PM

Hello, I'd like to start off by saying I'm very new to CompSci per se, and thus I have had no experience prior with packaging classes. My issue here is that I have created two classes, one which extends JPanel and one which contains the main function for executing the GUI operation. In both classes I declared the package (on the first line, syntax doesn't seem to be the issue as far as my understanding); however, an error is thrown when I attempt to compile the driver class, wherein the main function I declared a new ExamplePanel object. The simplified code for both of these is as follows:


package foo.example;

      import javax.swing.JPanel;
      import java.awt.Graphics;

      public class ExamplePanel extends JPanel{
         public void paintComponent(Graphics g){
             super.paintComponent(g);
             /* code */
         }
       }   

package foo.example;

      import javax.swing.JFrame;
      
      public class ExamplePanelTester{
         public static void main(String[] args){
            ExamplePanel panel = new ExamplePanel() //Error occurs here, error: cannot find symbol ExamplePanel
            /* code */
          }
        }

As aforesaid, I have no experience working with packaging, and thus the reason is most likely obvious; however, any help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Issue with starting a package

#2 kayyos  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 16
  • Joined: 22-October 13

Re: Issue with starting a package

Posted 31 July 2014 - 10:40 PM

Your code as you have it runs Error free.

Are both the classes in the same directory?
Was This Post Helpful? 0
  • +
  • -

#3 cdare77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-July 14

Re: Issue with starting a package

Posted 01 August 2014 - 06:00 AM

That's the issue I'm not entirely sure about, they were originally compiled separately and I just recently declared them a part of the same package. If they by chance aren't in the same directory, how would I check?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2814
  • View blog
  • Posts: 11,915
  • Joined: 20-September 08

Re: Issue with starting a package

Posted 01 August 2014 - 06:35 AM

goose@vaio:/tmp$ ls -l *.java
-rw-r--r-- 1 goose goose 227 Aug  1 13:11 ExamplePanel.java
-rw-r--r-- 1 goose goose 308 Aug  1 13:12 ExamplePanelTester.java
goose@vaio:/tmp$ javac -d . *.java
goose@vaio:/tmp$ java foo.example.ExamplePanelTester



If you're using Windows, your first command would be dir *.java
Was This Post Helpful? 0
  • +
  • -

#5 kayyos  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 16
  • Joined: 22-October 13

Re: Issue with starting a package

Posted 01 August 2014 - 06:58 AM

View Postcdare77, on 01 August 2014 - 06:00 AM, said:

That's the issue I'm not entirely sure about, they were originally compiled separately and I just recently declared them a part of the same package. If they by chance aren't in the same directory, how would I check?


They should both be in the same source folder.

This post has been edited by kayyos: 01 August 2014 - 06:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1