• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

URLClassLoader problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've searched the topics in this forum and cam across many people who seem to have the same problem as me, but my problem remains.

I'm simply trying to load a class that isn't in the classpath of my app. No matter what I do or what I try it simply cannot find the class

Here is my code:




And here is the output:




What am I doing wrong?!?!
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a class file there?
 
tracey ruark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Is there a class file there?



Yes, I complied the file already to check it.

Here's the contents of the file at E:\URLClassLoaderTesting_TEMP\projects\project1\tests\ClassToBeLoaded.java
(It is just a dummy class for the proof of concept)

 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And where is file ClassToBeLoaded.class located?
 
tracey ruark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:And where is file ClassToBeLoaded.class located?



That is an excellent question. I say that because when I started this whole thing I dropped the .class file right next to the java file. However, when the .java and .class file reside next to each other in the same directory the program spits this out at me:

 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In what folder are you when you're executing the JVM? It should be E:\URLClassLoaderTesting_TEMP\projects\project1. Also, you error tells me that the .class file does not think it belongs in the tests package; the fully qualified name in the .class file is ClassToBeLoaded, not tests.ClassToBeLoaded.

Have you perhaps created the .class file before you added the package statement?
 
tracey ruark
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:In what folder are you when you're executing the JVM? It should be E:\URLClassLoaderTesting_TEMP\projects\project1. Also, you error tells me that the .class file does not think it belongs in the tests package; the fully qualified name in the .class file is ClassToBeLoaded, not tests.ClassToBeLoaded.

Have you perhaps created the .class file before you added the package statement?



Ah Hah! Thank you. It's been so many years since I've worked with java I'd completely forgotten about how it works at it's most fundamental levels.

My new code looks like this:



My output now looks like this, which is what I'm after:



Thank you so much Mr. Prime!
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic