Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem using class.invoke

  Asked By: David    Date: Sep 28    Category: Java    Views: 905
  

when I run my program (the important parts are down below) I
get an error saying "Can't invoke print: Illegal Argument
Exception...."

public ArrayList getMethodsList()
{
Method[] meths = Compiler.class.getMethods();
ArrayList output = new ArrayList();

for(int count = 0; count < meths.length; count++)
{
Class retType = meths[count].getReturnType();
Class[] para = meths[count].getParameterTypes
();
if(retType.equals(void.class) && para.length
== 3 &&
para[0].equals(String.class) && para
[1].equals(ArrayList.class)
&& para[2].equals
(StringLinizer.class))
output.add(meths[count]);

}

return output;
}

public void actionPerformed(ActionEvent a)
{
outputFrame.removeAll();

String s = input.getText(); //equals print 'some
string'
StringLinizer line = new StringLinizer(s);
ArrayList vars = new ArrayList();

String next = "";
String start = "";
while(line.hasNext())
{
next = line.next();
start = next.substring(0, next.indexOf(" "));
if(next.indexOf(" ") == -1 || start.indexOf
("(") != -1)
start = next.substring(0, next.indexOf
("("));
for(int count = 0; count < methods.size();
count++)
{
if(start.equals(((Method) methods.get
(count)).getName()))
{
try
{
String str =
next.substring(start.length());
((Method) methods.get
(count)).invoke(Compiler.class, new Object[] {str, vars, line});

}
catch (Exception e)
{
throw new
IllegalArgumentException("Can't invoke "+methods.get(count)+": "+e);

}
}
}
}
}

Just a quick note, a StringLinizer is like a StringTokenizer only it
breaks the String up into lines. Any help?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Problem using class.invoke Or get search suggestion and latest updates.




Tagged: