×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    18

    java.lang.SecurityException

    Hi all,

    Can anybody help in this exception area .Actually i am coding for textbox to call from canvas.i am calling midlet class from canvas class and created a textbox object and set the current display as text box.when i executed the code i am getting java.lang.SecurityException:application not authorised to access restricted api.
    waiting for the reply ,its urgent.

  2. #2
    Regular Contributor
    Join Date
    Dec 2007
    Posts
    122

    Re: java.lang.SecurityException

    Hey,
    Please post your code, your chances to get appropriate answer will increase.
    Its hard to understand by explanation.

    Regards,

    --Maoz

  3. #3
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: java.lang.SecurityException

    Are you trying to create MIDlet class in your code. Based on your description that's the only guess I have so far. Also tell, which phone you are using (and if it is branded for an operator)

    Hartti

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    18

    Re: java.lang.SecurityException

    Quote Originally Posted by maozet View Post
    Hey,
    Please post your code, your chances to get appropriate answer will increase.
    Its hard to understand by explanation.

    Regards,

    --Maoz
    hi
    Thanks for reply.
    i am posting my query with code just analyse the code and send the reply.

    This code is part of canvas class where i get a textbox from response and i set the flag as true then i select the textbox and click the fire button to call the text box for the user to enter the input.i am calling constructor of a midlet there i am creating and displaying text box.
    if(t_flag==true)
    {
    m.fire_flag=true;
    try
    {
    System.out.println("in t_flag of FIRE::");
    new MobiBrowser("TextBox");
    System.out.println("mobibrowser constructor is called::");
    }
    catch(Exception e)
    {
    System.out.println("exception e::"+e);
    }

    This is the constructor of midelt class which is called in canvas class.here i am setting the current display as textbox and tb_flag as true.and in startApp() if the tb_flag is true then set the current display as textbox.

    public MobiBrowser(String tbs)
    {
    display=Display.getDisplay(this);
    System.out.println("in mobibrowser(tbs) constructor::");
    tb_flag=true;
    ok=new Command("OK",Command.BACK,1);
    tb=new TextBox(tbs,"",250,TextField.ANY);
    tb.addCommand(ok);
    tb.setCommandListener(this);
    }

    protected void startApp()
    {
    if(tb_flag==true)
    {
    System.out.println("tb_flag::"+tb_flag);
    display.setCurrent(tb);
    tb_flag=false;
    }
    menu = new Menu(this, null);
    }

  5. #5
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: java.lang.SecurityException

    Ok, so you are trying to create a new MIDlet class in your code (see my previous answer).

    At least you have new MobiBrowser call in your code and you tell later that the MobiBrowser is a MIDlet class.
    You cannot do that in your code. only the Java Environment can start a new MIDlet.

    Hartti

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    18

    Re: java.lang.SecurityException

    hi
    thanks for ur reply.
    i tried the same thing wih different code.
    here is my code to call text box from canvas class

    if(t_flag==true)
    {
    m.fire_flag=true;
    try
    {
    new User1();
    System.out.println("mobibrowser constructor is called::");
    }
    catch(Exception e)
    {
    System.out.println("exception e::"+e);
    }
    and the user1 is another midlet which contains only text box.when i select the text box on canvas and press the fire key it should call this midlet class to display the text box.and when perss the ok command user sholud goto canvas.

    import javax.microedition.lcdui.TextBox;
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;

    public class User1 extends MIDlet implements CommandListener
    {
    ReaderCanvas r;
    MobiBrowser browser;
    private TextBox tb1;
    private Command ok;
    private Display display;

    public User1()
    {
    display=Display.getDisplay(this);
    ok=new Command("OK",Command.BACK,1);
    tb1=new TextBox("user","",100,TextField.ANY);

    tb1.addCommand(ok);
    tb1.setCommandListener(this);
    }
    public void startApp()
    {
    display.setCurrent(tb1);
    }
    public void pauseApp()
    {
    }
    public void destroyApp(boolean unconditional)
    {
    }

    public void commandAction(Command c,Displayable s)
    {
    if(c==ok)
    {
    new ReaderCanvas();
    }

    }
    }

  7. #7
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: java.lang.SecurityException

    I was perhaps unclear in my previous answers.
    The problem is that User class extends MIDlet class. You cannot create a new MIDlet class in your code. Hence the new User() throws an exception.
    Try dropping the "extends MIDlet" away from the User class definition

    Hartti

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    18

    Re: java.lang.SecurityException

    hi

    This is the code that I wrote in a Canvas. From here I'm going to call another class file which extends the TextBox, to display the textbox.
    if(t_flag==true)
    {
    m.fire_flag=true;
    try
    {
    u=new User("user","aa",10,1); // from here we are
    // calling the textbox
    }
    catch(Exception e)
    {
    System.out.println("exception e::"+e);
    }


    Here I'm creating another class file using the following code:

    import javax.microedition.lcdui.TextBox;
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.*;
    import java.io.*;

    public class User extends TextBox
    {

    String user="USER";
    static final int MAX_USER_LENGTH = 164;
    ReaderCanvas r;
    MobiBrowser browser;
    Display display;

    public User(String s, String s1, int i, int j)
    {
    super(s, s1, i, j);
    Display.getDisplay(browser).setCurrent(this);
    }
    }

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    18

    Re: java.lang.NullPointerException

    hi
    for this code i am getting nullpointerexception.how to solve this problem

    This is the code that I wrote in a Canvas. From here I'm going to call another class file which extends the TextBox, to display the textbox.
    if(t_flag==true)
    {
    m.fire_flag=true;
    try
    {
    u=new User("user","aa",10,1); // from here we are
    // calling the textbox
    }
    catch(Exception e)
    {
    System.out.println("exception e::"+e);
    }


    Here I'm creating another class file using the following code:

    import javax.microedition.lcdui.TextBox;
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.*;
    import java.io.*;

    public class User extends TextBox
    {

    String user="USER";
    static final int MAX_USER_LENGTH = 164;
    ReaderCanvas r;
    MobiBrowser browser;
    Display display;

    public User(String s, String s1, int i, int j)
    {
    super(s, s1, i, j);
    Display.getDisplay(browser).setCurrent(this);
    }
    }

  10. #10
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: java.lang.NullPointerException

    This line is likely the problem

    Display.getDisplay(browser).setCurrent(this);
    As browser variable is still null. One solution is that you provide the MIDlet as a parameter to the class User

    Hartti

Similar Threads

  1. java.lang.securityexception error
    By fuatsungur in forum Mobile Java Tools & SDKs
    Replies: 15
    Last Post: 2008-02-20, 16:15
  2. unusual java.lang.SecurityException
    By atantc in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-07-16, 20:09

Posting Permissions

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