FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Problem with resources folder

 
Post new topic   Reply to topic    NetBeans Forums -> Java ME Users
View previous topic :: View next topic  
Author Message
Raff89



Joined: 26 Aug 2009
Posts: 5

PostPosted: Wed Aug 26, 2009 2:19 pm    Post subject: Problem with resources folder Reply with quote

Hello, I was trying to create a simple Java ME application using NetBeans 6.7.1. The app just shows an image on the screen.
The code is correct, as I can create the ".class" files using Sun's Wireless Toolkit and it runs properly. But I'm getting errors using NetBeans emulator. The error message says "Exception The application cannot be launched. The application may have done an illegal operation. Contact the application provider to resolve the issue.", so I suspect it can't recognize my image files.

Where should I put my resources (e.g. png images)? There isn't any "res" folder in my project folder. NetBeans shows a "Resources" tree option in my project, I right-clicked on it selecting "Add Folder" and added my res folder path, but it still can't read my images. I put a copy of the png image everywhere in my project folders, but it still can't find them.

I know that the emulator works as I can run other demo projects with images, but I still don't understand where to put the images. And I wouldn't like to switch to Wireless Toolkit every time I make a little change to the code.
Thanks.
Back to top
View user's profile Send private message
Karol Harezlak
Posted via mailing list.





PostPosted: Wed Aug 26, 2009 2:29 pm    Post subject: Problem with resources folder Reply with quote

Hi,
You can store your images anywhere you want: source code, resources,
jar. More important is to provide correct path for image in source code.
To understand how image path works you can look at the generated code by
Splash Screen component in Visual Mobile Designer Midlet. Unfortunately
I'm not able to say if your error is image related.

K.

Raff89 wrote:
Quote:
Hello, I was trying to create a simple Java ME application using NetBeans 6.7.1. The app just shows an image on the screen.

The code is correct, as I can create the ".class" files using Sun's Wireless Toolkit and it runs properly. But I'm getting errors using NetBeans emulator. The error message says "Exception The application cannot be launched. The application may have done an illegal operation. Contact the application provider to resolve the issue.", so I suspect it can't recognize my image files.



Where should I put my resources (e.g. png images)? There isn't any "res" folder in my project folder. NetBeans shows a "Resources" tree option in my project, I right-clicked on it selecting "Add Folder" and added my res folder path, but it still can't read my images. I put a copy of the png image everywhere in my project folders, but it still can't find them.



I know that the emulator works as I can run other demo projects with images, but I still don't understand where to put the images. And I wouldn't like to switch to Wireless Toolkit every time I make a little change to the code.

Thanks.












--
Karol Harezlak <address-removed>
Sun Microsystems, Inc. NetBeans Mobilty/JavaFX
Back to top
Raff89



Joined: 26 Aug 2009
Posts: 5

PostPosted: Wed Aug 26, 2009 3:48 pm    Post subject: Reply with quote

Thanks for the answer. I used the following strings in my project (one for each test):
img = Image.createImage("/dir.png");
img = Image.createImage("C:/Documents and Settings/..../res/dir.png");
img = Image.createImage("/res/dir.png");
But none worked. I don't think it's a "correct path" issue.

To create a new project, I choose: New Project->Java ME->Mobile Application, i think it's correct.

I opened the "Sun Samples - Demo" sample project, and followed the image structure used in one of those apps as you suggested, I created the exact directory structure but it still doesn't work.

Crying or Very sad

Anyway, the portion of code is this one:

try
{
img = Image.createImage("/res/dir.png");
sprite = new Sprite(img,32,32);
}
catch ( IOException e )
{
System.err.println("Error: " + e);
}

The png image must be 32x32?
This is the only try-catch block I have in my class. Shouldn't it give me the message "Error: " plus the rest, instead of the error string I posted above?
Back to top
View user's profile Send private message
peter_budo



Joined: 03 Oct 2008
Posts: 27

PostPosted: Thu Aug 27, 2009 9:57 am    Post subject: Reply with quote

Have look here, it should help you Cool
Back to top
View user's profile Send private message
Raff89



Joined: 26 Aug 2009
Posts: 5

PostPosted: Thu Aug 27, 2009 10:55 am    Post subject: Reply with quote

Thanks, I followed that page's instructions, now it still doesn't work, but at least I don't get the error message. Now it just runs saying (on the emulator screen) "Select one to launch:" and the screen below that string is empty. Here is the simple code. Can you explain me what's wrong?


a class:
Code:

package raf;


import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
/**
 *
 * @author Raf
 */
public class MioCanvas extends GameCanvas
{

    private Image img;
    private Sprite sprite;

    public MioCanvas()
    {
        super(true);

        try
        {
            img = Image.createImage("/raf/res/pallaTrasp.png");
            sprite = new Sprite(img,32,32);
        }
        catch(IOException ex)
        {
            System.err.println("Errore: " + ex);
        }
    }

    public void disegna()
    {
        Graphics g = getGraphics();
        g.setColor(187,213,252);
        g.fillRect(0,0,getWidth(),getHeight());
        sprite.setPosition(10,10);
        sprite.paint(g);
    }


}


and main class:
Code:

package raf;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 *
 * @author Raf
 */
public class Lezione1 extends MIDlet
{
    private Display d;
    private MioCanvas schermata;

    public Lezione1()
    {
        d = Display.getDisplay(this);
        schermata = new MioCanvas();
        schermata.disegna();
    }

    public void startApp()
    {
        d.setCurrent(schermata);
    }

    public void pauseApp()
    {

    }

    public void destroyApp( boolean unconditional )
    {

    }
}


I Evil or Very Mad javaME and its editor programs.

Edit: and here is the project structure:

-Project1
_____-Source Packages
__________-raf <--(a package)
_______________Lezione1.java
_______________MioCanvas.java
__________-res <--(a package)
_______________pallaTrasp.png
_____-Resources
_____-Project Configurations

Maybe it's due to the png image? Does it have to have certain properties, or can it be a common png file e.g. created with Windows' Paint?
Back to top
View user's profile Send private message
Raff89



Joined: 26 Aug 2009
Posts: 5

PostPosted: Fri Aug 28, 2009 10:20 am    Post subject: Reply with quote

I tried to replace the working imgs with my pngs, but they don't display. Only non-mine pngs display. Is there a program to create the exclusive png format for javaME, as Windows' Paint's png doesn't work with javaME? What kind of PNG images are compatible with javaME and how to make them?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java ME Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB