Results 1 to 4 of 4
  1. #1
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Question How to use resource (.res) file in your java me project

    Hi,
    Hope you all will be fine. I just go through a tutorial using how to create resource file using resource editor. I created a file ProjectResource.res. in which i set theme, the name of theme is Theme2. Now can any one tell me how can i use this resource file into my project. First i created a directory Resource in the same folder where my src folder is present and then put the .res file in to it. I want to ask do i add this file in the Resource tree too of netbeans where we include jar files. Or what step i follow after creating this .res file. I am using Netbeans6.8

    Thanks

  2. #2
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Red face

    Hi,
    I am using this code but it gives me null pointer exception

    Java Code:
        try {
    
             //Load resource
    			Resources sampleThemeResource = Resources.open("/ProjectTheme.res");
    
                            System.out.println("Under rasource.open");
    
    			//get the hashtable for the theme
    			Hashtable sampleTheme = sampleThemeResource.getTheme("Theme2");
    
    
    			//instll the theme
    			UIManager.getInstance().setThemeProps(sampleTheme);
    		}
    
             catch (IOException ioe) {
               System.out.println("Resource can't be loaded");
             }
    and the exceptions are

    Java Code:
    java.lang.NullPointerException
            at java.io.DataInputStream.read(DataInputStream.java:83)
            at java.io.DataInputStream.readUnsignedShort(+4)
            at java.io.DataInputStream.readShort(+4)
            at com.sun.lwuit.util.Resources.openFile(Resources.java:134)
            at com.sun.lwuit.util.Resources.<init>(Resources.java:114)
            at com.sun.lwuit.util.Resources.open(Resources.java:449)
            at HelloResourceEditor.startApp(HelloResourceEditor.java:32)
            at javax.microedition.midlet.MIDletProxy.startApp(+7)
            at com.sun.midp.midlet.Scheduler.schedule(+270)
            at com.sun.midp.main.Main.runLocalClass(+28)
            at com.sun.midp.main.Main.main(+80)
    Resource can't be loaded
    I am using gradient look and feel in the resource file. I have a res folder in the same place where my src folder is present and in the res folder there is a file named ProjectResource.res. And in my netbeans i add the res folder in the Resources node same where we add jar

    Any idea why i am getting null pointer exception

    Thanks

  3. #3
    Basit781 is offline Member
    Join Date
    May 2010
    Posts
    47
    Rep Power
    0

    Thumbs up

    Hi,
    I have known how to use it. It's very simple. First use theme creator that comes with LWUIT 1.3 package. Create theme then create folder named res in the same folder where your src folder present and put the .res file in it. Then in NetBeans , in your project Tree, right click on Resources select add folder and then add res folder. Then use this in your code

    Java Code:
      try {
          Display.init(this);
    
          Resources r = Resources.open(getClass().getResourceAsStream("/ProjectTheme.res"));
            System.out.println("Under rasource.open");
           UIManager.getInstance().setThemeProps(r.getTheme("Theme2"));
       } catch (Exception e) {
       e.printStackTrace();
       }
    Thanks

  4. #4
    javajr is offline Member
    Join Date
    Aug 2010
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Resource File
    By dvlchd3 in forum Eclipse
    Replies: 2
    Last Post: 01-13-2010, 10:32 AM
  2. Replies: 0
    Last Post: 11-24-2009, 01:49 PM
  3. Jar resource file size
    By OrangeDog in forum Java Applets
    Replies: 1
    Last Post: 04-30-2009, 04:12 AM
  4. Reading a properties file using resource bundle.
    By rudrakanth in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 12:23 PM
  5. Replies: 0
    Last Post: 02-11-2009, 09:53 AM

Posting Permissions

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