In the program will encounter the reference resource file path problem, combined with their own problems, summed up as follows:
The default path to my Eclipse project is F:/workbench, where the resource files are sent in the project's res, and if the resource file (the project name is mytext and the picture name is A.png) can be displayed while running in Eclipse, the path is res/ A.png, this path represents the search for a file under the current path, the current path is f:/workbench/mytext/, or./res/a.png is also available,./table current directory. But it cannot be/res/a.png, because the/representation is the root path of the current project, that is f:, the path to find the file with/res/a.png when the eclipse is run is f:/res/a.png, which of course cannot be found.
But if you want the jar to be in a different place to display the picture after the program is packaged, the path described above is incorrect. You should use Class.getResource (), such as URL imageUrl = MyText.class.getResource ("/res/a.png"), to package the program, When you run load mytext to MyText root path jar package to find resources, such as I put the jar on the desktop, then use/res/a.png when the program to find the full path of the resource file is C:/users/hwl/desktop/mytext.jar!/res /a.png, (MyText for package name) so you can definitely find the file you want. If it is getresource ("./res/a.png") or res/a.png, there is no response when you double-click the jar package.
As for J2ME, you should pay special attention to the path of the resource file is not res/a.png, but/a.png. Because Eclipse creates a new MIDlet suit, the default resource file path is the Res folder, so it automatically goes to res to find the file, without adding res to the path. You can see in window->preferences->j2me->new Midlet suit that automactically use resources Directory in New projects is ticked, and resources Directory is set to Res.