Reputation: 904
Greetings
I'm developing my first app in java and I wanted to know how can I do the following
I created this
public class Test
{
...
public void control()
{
final ArrayList<Module> mods = new ArrayList<Module>();
if (i == 0)
{
mods.add( null );
mods.add(moduleList.get( i ));
Thread t = new Thread( new Runnable()
{
public void run()
{
StartController(mods);
}
});
}
}
public void StartController(ArrayList<Module> modList)
{
//Do Stuff
}
}
But I am unable to accomplish this! he can't find StartController....
I would like to keep the code close to this. Is there a way to do that?
Upvotes: 0
Views: 5764
Reputation: 367
Another option could be to make the StartController(..) method static.
public static void StartController(ArrayList<Module> mods) {
// do stuff
}
And then change the call to:
Test.StartController(mods);
Upvotes: 0
Reputation: 19717
try to use ExecutorService and the Runnable interface instead. You can see an easy example right here:
http://programmingexamples.wikidot.com/executorservice
Upvotes: 0
Reputation: 12443
That looks 100% correct but a common solution for this, in situtations where that type of call doesn't work, is to do:
Test.this.StartController(mods)
instead of
StartController(mods)
Upvotes: 1