• 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

Loading in java file outside of program

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

I'm going round in circles trying to load in a java file on the Desktop for example.
I am able to do it when the file is inside the application simply with Class.forName(path).newInstance where the path is the package name and class name of file.

For the external file, I have a file at:

C://Users/colin/Desktop/categories/MY_HERO/$o$/MyHero.java

The MyHero.java file begins with the line ( package categories.MY_HERO.$o$; )

And the code I'm using:



But I always get a [java.lang.ClassNotFoundException: categories.MY_HERO.$o$.MyHero] exception

Can anyone diagnose the problem, I have googled several pages, but it hasn't helped.

Thanks for any advise.
 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably a dumb question, but do you have a "MyHero.class" file?
 
Colin Smithworth
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I was being dumb, cause the file shows as .java in netbeans, so I left it like that.
I compiled it and it loaded correctly first time, thanks for the help.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you keeping files in your Desktop folder? Why have you got package names beginning with $? I know the compiler won't mind, but it doesn't look right to me. I know it isn't a hard and fast rule, but you shou‍ld avoid identifiers containing $ or (except for constants) _ or UPPER CASE writing.
 
Colin Smithworth
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was just on the desktop as it was simpler to test from there, its normally from inside a folder in the home folder that the application uses to read and write data to.

There are additional folders in the same folder as the $o$ folder, the $o$ folder has a $ in it so that the application knows not to include it in a combobox.
I could have just used another folder with subfolders and gave the $o$ a normal looking name, but I thought this would be simpler.

Thanks

 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a 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