Hi,
I am using Eclipse IDE, Ant and J2ME Polish to create an application. I have made two public classes in the same package. But, I am getting an illegalAccessException when I am trying to create an object of one class in another.
The code I have written is :
Class #1
package LocationFinder;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import java.util.Timer;
import java.util.TimerTask;
class giveList extends TimerTask
{
public Display display;
public List firstList;
public giveList(Display display,List firstList)
{
this.display=display;
this.firstList=firstList;
}
public void run()
{
this.display.setCurrent(firstList);
}
}
public class firstScreen extends MIDlet implements CommandListener{
public Command quitCmd = new Command( "Quit", Command.EXIT, 0 );
public Command start=new Command("OK",Command.OK,0);
public Display display;
public Form firstScreen=new Form("New Form");
public Timer timer;
giveList menuScreen;
String options[]={"My Location","Messenger","Important Sites Here","Resources Here","Geographical Info"};
int selection;
List firstList= new List("Location Finder",List.IMPLICIT,options,null);
public firstScreen()
{
super();
//#style heading
this.firstScreen.append("Welcome");
this.firstScreen.addCommand(quitCmd);
this.firstScreen.addCommand(start);
this.firstList.addCommand(quitCmd);
firstScreen.setCommandListener(this);
firstList.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException{
this.display = Display.getDisplay( this );
this.display.setCurrent( firstScreen );
timer=new Timer();
menuScreen=new giveList(display,firstList);
timer.schedule(menuScreen,1000);
}
public void commandAction(Command cmd, Displayable screen) {
if(cmd==quitCmd)
{
this.notifyDestroyed();
}
else if(cmd==start)
{
menuScreen.run();
}
else if(cmd==List.SELECT_COMMAND)
{
selection=firstList.getSelectedIndex();
getLocation locate=new getLocation(firstList,selection);
try
{
locate.startApp();
}
catch(Exception e)
{
//Do nothing
}
}
}
protected void pauseApp(){
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException{
}
}
Class #2
package LocationFinder;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class getLocation extends MIDlet {
Display display;
List firstList;
int selection;
public getLocation(List firstList,int selection) {
super();
this.selection=selection;
this.firstList=firstList;
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
public void startApp() throws MIDletStateChangeException {
this.display = Display.getDisplay( this );
this.display.setCurrent(firstList);
//#style heading
firstList.append("Selection is "+selection, null);
}
}
and my build file is :
<project name="LocationFinder" default="j2mepolish">
<property file="${user.name}.properties" />
<property file="midlet.properties" />
<property name="polish.home" value="C:\Program Files\J2ME-Polish2.0.7" />
<property file="${polish.home}/global.properties" />
<property name="wtk.home" value="C:\WTK2.5.2_01" />
<property name="nokia.home" value="C:\Nokia" />
<taskdef name="j2mepolish"
classname="de.enough.polish.ant.PolishTask"
classpath="${polish.home}/lib/enough-j2mepolish-build.jar:${polish.home}/lib/jdom.jar"/>
<target name="j2mepolish">
<j2mepolish>
<info
license="GPL"
name="firstScreen"
version="0.0.1"
vendorName="Tarang"
jarName="${polish.vendor}-${polish.name}-${polish.locale}-firstScreen.jar"
/>
<deviceRequirements>
<requirement name="Identifier" value="Generic/DefaultColorPhone" />
</deviceRequirements>
<build usePolishGui="true">
<midlet class="LocationFinder.firstScreen" />
<midlet class="LocationFinder.getLocation" />
</build>
<emulator />
</j2mepolish>
</target>
<target name="clean" >
<delete dir="build" />
<delete dir="dist" />
</target>
</project>
Please help me out..I am stuck on the same problem since yesterday and I am not able to move ahead at all..Thanks..

Reply With Quote





