I have made a custom fileloader that finds the path of the file using JFileChooser. But how do I load the external class file into my program an create an instance of the class??
I really need help 
I have made a custom fileloader that finds the path of the file using JFileChooser. But how do I load the external class file into my program an create an instance of the class??
I really need help 
Go ask in the Gameplay/Design or Newless Clewbies section. Then maybe you’ll get a response.
grumble grumble damnkidswiththeirl33tsigns grumble don’tknowthefirstthingaboutl33t grumble
use a classLoader…
You can get a classloader from this.getClass().getClassloader() and then call loadClass() with the path to your external class. Then you just call newInstance() on the class that loadClass() returns.
If this is a bit unclear how to do, then just look in the api docs for ClassLoader and you’ll find examples.
regards
JBanes: No comments…
HarryK: Thankyou very much. I will go try again the way you suggested.
L33t comments aside, again it really would have been more useful to future posters if you’d posted this in a more appropriate forum, especially after you name the topic so clearly as to have it found.
Its just community spirited really…
Kev
Well I concidered “loading an external class file” as a general question.
Fair enough, just there are quite a few people that only read the sections they’re interested in. As since this is >Games< General Discussion quite a few don’t bother reading it because they want technical detail not games talk.
I think Mr Banes was just saying it might have been more suitable in a different section,
Kev
This works:
ClassLoader loader = this.getClass().getClassLoader();
Class myClass = loader.loadClass("fileRelated.ExampleGenerator");
// Create a new object from the class object
Object myObject = myClass.newInstance();
However, I have exported the ExampleGenerator and when I try to run it from a glodbal path like D:/ExampleGenerator.class i doesnt work. How can I load it this way?
You should probably use a URLClassLoader instead, look for examples @ your preferred search engine since I haven’t really used it myself.
regards
[quote]Well I concidered “loading an external class file” as a general question.
[/quote]
Except that this isn’t a General Question forum. It’s a general news and discussion forum. KevGlass already politely informed you in another thread. So I’m now informing you not so politely.
BTW, you might try reading the JavaDoc comments for java.lang.ClassLoader.
[quote]Well I concidered “loading an external class file” as a general question.
[/quote]
Frankly, it’s a clueless newbie question that any “normal” java programmer ought to already know the answer to (or at least should have the ability to google for).
Which makes it annoying to other people to see being placed outside that area.
Shrug.
maybe it’s more annoying to see 10 different “answers” or lectures about netiquette, than a misplaced post once in a while.
[quote]maybe it’s more annoying to see 10 different “answers” or lectures about netiquette, than a misplaced post once in a while.
[/quote]
It’s called “moderation” and since sun won’t pay people to do it and won’t allow unpaid people to do it we have to manage it ourselves each in our own way.
So people try to inform (induct people into the conventions) and coerce (apply pressure to get them to conform) others. It’s all that keeps the SNR tolerably high around here.
[quote]maybe it’s more annoying to see 10 different “answers” or lectures about netiquette, than a misplaced post once in a while.
[/quote]
It would be ok if this was the first time. But he has repeatedly posted in the wrong place. Then it is in its place to give a hint.
[quote] It would be ok if this was the first time. But he has repeatedly posted in the wrong place
[/quote]
Jesus Christ. Why are people behaving like children? I post in Games General Discussion because I would like to load an external class file into my game !!!
Jesus Christ. Some of you chicks need to chill.
[quote]Jesus Christ. Some of you chicks need to chill.
[/quote]
Right. Ban 'im for swearing. ;D
Seriously, though. Have you ever considered that there is a reason why you were asked to choose a more appropriate forum for your posts? When things are out of place, the signal to noise ratio drops. So we nicely asked you to keep the forum organization in mind. Several times. You consistently ignored the requests, and now people are a little miffed about it.
If you want to complain about childish behavior, how about starting with number one?
BTW, did you find the solution in the JavaDoc I linked to?
I believe all of the YaBB God’s are in agreement on this one. It’s definitely misplaced. This isn’t the kind of thing I want to run into when I view the General Discussions section. Please accept the mistake and try to be more respectful of the community and its structure in the future.
Actually a moderator should just move it to the appropriate forum. End of story 
Unfortunately the moderation here is a little odd at the best of times, so folks are just trying to encourage posters to get them in the right place the first time…
Its not really meant to come off as heavy as it sometimes does
Kev