×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    17

    How to access LWUIT theme (.res) file in my J2ME app? (I'm using Eclipse IDE)

    Hi all,

    I'm trying to get a REALLY simple HelloWorld app using LWUIT up and running, and I'm using the latest Eclipse IDE.

    Great news is it compiles and runs, bad news is it completely refuses to load and use any theme file (.res) I supply and I have no idea why - so I'm just getting an unthemed (black and white) LWUIT app.

    Error I am getting at runtime is:

    Installing suite from: http://127.0.0.1:54445/HelloLWUIT.jad

    ****warning****
    ****Untrusted user classes must never be put
    ****on the system class path
    ****warning****

    java.lang.NullPointerException: 0
    - java.io.DataInputStream.read(), bci=4
    - java.io.DataInputStream.readUnsignedShort(), bci=1
    - java.io.DataInputStream.readShort(), bci=1
    - com.sun.lwuit.util.Resources.openFile(), bci=20
    - com.sun.lwuit.util.Resources.<init>(), bci=28
    - com.sun.lwuit.util.Resources.open(), bci=16
    - HelloLWUITMIDlet.startApp(), bci=6
    - javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
    - com.sun.midp.midlet.MIDletPeer.startApp(), bci=7
    - com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=269
    - com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
    - com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
    - com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
    - com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26

    The important line being: - HelloLWUITMIDlet.startApp(), bci=6
    which when clicked hilights this line in my source:
    Resources r = Resources.open("themes2/test.res");

    That file (test.res) is showing correctly (I think?) in the Package Explorer heirarchy. To get it in there, I went to my project's properties in Eclipse, then Java Build Path->Source tab->Add folder, then added 'themes2' and right clicked 'themes2' in the hierarchy back in package explorer and hit 'refresh' so that it showed up the .res file in the hierarchy too.

    I've no idea why I'm getting the untrusted user classes warning at the top, and whether this is related to the theme not loading. When adding the LWUIT.jar in the first place, I again brought up my project's settings->Java Build Path->Libraries tab->Add External JARs... and then LWUIT.jar showed up in Package Explorer under my project, under 'Referenced Libraries' folder.

    I REALLY need some help PLEASE, am completely stuck!

    Relevant source code is:

    public void startApp() {
    Display.init(this);

    try {
    Resources r = Resources.open("themes2/test.res");
    UIManager.getInstance().setThemeProps(r.getTheme("test"));
    } catch (IOException ioe) {
    // Do something here.
    }

    Form f = new Form("Hello, LWUIT!");

    f.show();

    etc....

    Many thanks,
    Alex

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: How to access LWUIT theme (.res) file in my J2ME app? (I'm using Eclipse IDE)

    See LWUIT demo, how they use it.

    Resources res = Resources.open(getClass().getResourceAsStream("/theme.res"));

    this theme.res should be in the res folder of the project and it should be generated by the resource editor of the current version of LWUIT, which JAR you are using.

    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    17

    Re: How to access LWUIT theme (.res) file in my J2ME app? (I'm using Eclipse IDE)

    Quote Originally Posted by im2amit View Post
    See LWUIT demo, how they use it.

    Resources res = Resources.open(getClass().getResourceAsStream("/theme.res"));

    this theme.res should be in the res folder of the project and it should be generated by the resource editor of the current version of LWUIT, which JAR you are using.

    thanks,
    ~Amitabh
    Thanks - that didn't actually work, it just gave me more errors and the app refused to load, BUT it did lead me to the right solution (so thanks!) because I went and looked at the source code for LWUIT demo, then LWUIT Makeover (both from the current LWUIT_1.3 distribution) and ended up changing these 2 lines in my source code:

    Resources r = Resources.open(getClass().getResourceAsStream("/LWUITtheme.res"));
    UIManager.getInstance().setThemeProps(r.getTheme("LWUITtheme"));

    to the code used in LWUIT Makeover:

    Resources res = com.sun.lwuit.util.Resources.open("/theme.res");
    UIManager.getInstance().setThemeProps(res.getTheme(res.getThemeResourceNames()[0]));

    and my imports section at the top also had to have:
    import com.sun.lwuit.plaf.UIManager;
    import com.sun.lwuit.util.Resources;

    and noticed that LWUIT Makeover also put it's theme (.res) file and other resources directly in the src directory, so I copied my theme .res file there and right clicked and did refresh so it showed up in the heirarchy in Package Explorer. I deleted my themes2 resource folder completely and the theme under the res dir.

    The only this is I am still getting this warning at runtime and am not sure why:

    ****warning****
    ****Untrusted user classes must never be put
    ****on the system class path
    ****warning****

    My source file HelloLWUITMidlet.java is under the "(default package)" under src in the heirarchy in Package Explorer - I am wondering if this is this issue? But not sure how to fix...

    App is running and using theme though, thanks!

  4. #4
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Re: How to access LWUIT theme (.res) file in my J2ME app? (I'm using Eclipse IDE)

    You don't have to put the res files in the src folder. Though it will not cause you any problem but the recommended way is to put them in res folder only. Please make sure that you are creating the res files with the editor supplied with the SDK you are using. I had experienced problems when used an old version of resource editor to create the file.

Similar Threads

  1. J2ME File Write Access in the jar file
    By bergteufel in forum Mobile Java General
    Replies: 2
    Last Post: 2010-03-20, 03:40
  2. Error with makesis.exe and creating the .pkg file
    By gramya87 in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2007-10-10, 13:53
  3. Replies: 0
    Last Post: 2005-02-16, 17:45
  4. how to access directories and files from J2ME app
    By johnmobile in forum Mobile Java General
    Replies: 6
    Last Post: 2004-01-23, 21:25
  5. access point for j2me app in nokia3650?
    By garyshi in forum Mobile Java General
    Replies: 0
    Last Post: 2003-06-11, 15: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
  •  
×