×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    20

    Cant access another public class in the same Package. illegalAccessException

    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..

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Cant access another public class in the same Package. illegalAccessException

    Both classes are MIDlets. Only the Application Manager should create MIDlets; you should not instantiate them yourself. A MIDlet is the application itself; it doesn't represent a "screen". You must have only one subclass of MIDlet. "Screens" are those classes that extend javax.microedition.lcdui.Displayable.

    Cheers,
    Graham.

  3. #3
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Cant access another public class in the same Package. illegalAccessException

    Quote Originally Posted by tarang127 View Post
    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..

    whats the need of instantiate another midlet in first midlet. Cant do like u done. Cant instantiate another midlet in other midlet in same package too.
    thanks,
    jitu_goldie..

    KEEP TRYING..

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Cant access another public class in the same Package. illegalAccessException

    Hi,
    this is the reason for the error you are getting.
    getLocation locate=new getLocation(firstList,selection);
    As Grahm suggested,you can only have 1 midlet(multiple you can have in case of midlet suite).And just do whatever you want to do in the midlet constructor/startApp and then just forget...midlet will be called by the application manager and hence you need not to write the quoted line.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Super Contributor
    Join Date
    Jun 2007
    Location
    Mumbai
    Posts
    539

    Re: Cant access another public class in the same Package. illegalAccessException

    Unless u want Multiple Midlet, means a midlet suite, u are a doing a very wrong way of j2me coding.
    au revoir
    Prakash Raman

  6. #6
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Cant access another public class in the same Package. illegalAccessException

    Quote Originally Posted by jitu_goldie View Post
    whats the need of instantiate another midlet in first midlet. Cant do like u done. Cant instantiate another midlet in other midlet in same package too.
    as a tip : it may be usefull NOT to quote a whole lot of code just to place half a sentence at the end of it
    it might make the difference between a readable and a unreadable forum

  7. #7
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Cant access another public class in the same Package. illegalAccessException

    Quote Originally Posted by Tiger79 View Post
    as a tip : it may be usefull NOT to quote a whole lot of code just to place half a sentence at the end of it
    it might make the difference between a readable and a unreadable forum
    i'll take care of that. anyways thanks..
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. Bluetooth and java using J2se
    By amirdqpb in forum Bluetooth Technology
    Replies: 5
    Last Post: 2008-09-09, 10:29
  2. is there any Emulator that supports video recording
    By habib117 in forum Mobile Java Tools & SDKs
    Replies: 5
    Last Post: 2008-07-18, 16:10
  3. need information about j2me polish
    By rathikathangaraj in forum Mobile Java General
    Replies: 4
    Last Post: 2007-12-19, 09:01
  4. Nokia 3410 emul err: Bad class access rights
    By Babikov in forum Mobile Java General
    Replies: 2
    Last Post: 2003-06-01, 16:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×