• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing class in different file

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

I'm having a bit of trouble accessing classes in a seperate .java file and I cannot see what I'm doing wrong. They are in the same package too.

Any help would be greatly appreciated. Many thanks!

This is where I call the ActionListener class:


And the class is as follows:


The error is get is:
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John,

how do you compile it ?
 
John Pisci
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Balu,

I compile it by typing: javac gList.java

gList is the name if the class with the main method in.

Thanks
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are the files in the same package structure ? or package ? ie is both in package guestList. ?

better try like this

 
John Pisci
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried compiling like this:


But I'm still getting the same error:


I know there is something I'm doing wrong, but I've absolutely no idea what!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your class btnSaveListener must be in a file named btnSaveListener.java in the directory guestList (because that's the name of the pacakge that the class is in). It will not work if you put this in a file named gList.java.

The name of the file must always be the same as the name of the public class that is in the file.

You should also put the base directory that contains the package directory in the classpath, so you should put "L:\My Projects\MyJavaApps" in the classpath, not "L:\My Projects\MyJavaApps\guestList".
 
John Pisci
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jesper,

I added to the classpath and think it solved this problem as I am now getting 58 errors!

One of the errors it has picked up is this:


Initially, I had the miglayout folder in the 'MyJavaApps' folder, with the classpath pointing to it and it worked perfectly. Now I've added the above to the classpath, I get the above error. i've even tried moving the miglayout folder to the guestList directory, but still no luck.

I'm sorry if this is all really basic stuff.

EDIT: Forgot to mention that I didn't overwrite the classpath with the above, I added it on to the end.

Would I have to compile it like this?:
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John,

One thing to note is javac -classpath will override the CLASSPATH variable. So you net.miginfocom.swing.*; jar should also be available in classpath.
 
John Pisci
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Balu, Jesper,

Many thanks for all of your help.

I've been able to compile my classes using the following:
 
Space pants. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic