Click here to Skip to main content

AllainLG asked:

Open original thread
Hi,
 
I can't figure out, how to use getDeclaredMethods() (reflection) if the user chooses the file from GUI.
Something like this:
Class inclass= Class.forName("ClassName");
Method[] methods = inclass.getDeclaredMethods();

But I don't know "ClassName", I get it later.
 
I'd like to get the declared methods from the input file, and then list them in my GUI. The user can choose a txt or java file, when he/she did, the program will get the methods from this (if there are any) and list them on a jList.
Works if I know the Object's name, but not if it comes later.
 
additional information copied from comment below
So my program would work like this: it starts, the user chooses a file (txt or java), when this happens the program gets the file's text into an Arraylist, and list's the file's methods and fields on a JList and displays them.
But the inputfile.getClass() won't work, since it's not an object, and I don't know how to get the input file's class, if I don't know the class name before the program starts.

Thank you for helping me.
Tags: Java, reflection, Refactor

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100