JavaCard simple applet not displaying text - javacard

I have the following problem:
Many simple examples found in internet, but no success.
The problem is: My menu entry comes in the STK menu, but if I select it, nothing happens. I tried to display text on event EVENT_MENU_SELECTION.
package helloStk;
import javacard.framework.*;
import sim.access.*;
import sim.toolkit.*;
public class helloStk extends Applet
implements ToolkitConstants, ToolkitInterface
{
private static final byte CMD_QUALIFIER = (byte)0x80;
private byte[] menuEntry = {'M','y','M','e','n','u'};
private byte[] textBuf = {'H','e','l','l','o'};
private ToolkitRegistry reg;
private SIMView gsmFile;
public helloStk() {
//Get the GSM application reference
gsmFile = SIMSystem.getTheSIMView();
enter code here`enter code here`
reg = ToolkitRegistry.getEntry();
reg.initMenuEntry(menuEntry,
(short) 0,
(short) menuEntry.length,
PRO_CMD_DISPLAY_TEXT,
false,
(byte) 0,
(short) 0);
}
public static void install(byte[] bArray, short bOffset, byte bLength)
throws ISOException
{
helloStk dt = new helloStk();
dt.register();
}
public void processToolkit(byte event)
throws ToolkitException
{
ProactiveHandler ph = ProactiveHandler.getTheHandler();
if (event == EVENT_MENU_SELECTION) {
ph.init((byte) PRO_CMD_DISPLAY_TEXT, (byte) CMD_QUALIFIER, DEV_ID_DISPLAY);
ph.appendTLV((byte)(TAG_TEXT_STRING | TAG_SET_CR),
textBuf,
(short) 0,
(short) textBuf.length);
ph.send();
}
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
}
}

You should first call the register() method for the Applet instance and then retrieve the ToolkitRegistry entry.

Related

It leaks when I startLeScan in onCreate and stopLeScan in onDestroy

I run my code and rotate the phone couple of times, then dump memory and analyze it.
Below is my code:
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
#Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
LogUtils.e("111");
}
};
private boolean mScanning = false;
private BluetoothManager bm;
private void scanLeDevice(final boolean enable) {
LogUtils.e(enable);
try {
if (enable) {
mScanning = true;
if(bm.getAdapter()!=null)bm.getAdapter().startLeScan(mLeScanCallback);
} else {
mScanning = false;
if(bm.getAdapter()!=null)bm.getAdapter().stopLeScan(mLeScanCallback);
}
invalidateOptionsMenu();
}catch (Throwable e){
}
}
#Override
protected void onDestroy() {
super.onDestroy();
scanLeDevice(false);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initStage();
}
#Override
protected void initStage() {
bm = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
scanLeDevice(true);
}
The java heap:
The LeScanCallback is holding a reference to the Activity. I just ran into this when testing the BluetoothLeGatt sample provided by Google. I copied the scanning code into my app and I suddenly found massive leaks occurring.
I solved it by wrapping the scan callback into a static class which then holds a weak reference to the activity. Much like Google reccomends when using a Handler. Like this:
private final BluetoothAdapter.LeScanCallback mLeScanCallback = new LeScanCallbackClass(this);
private static final class LeScanCallbackClass implements BluetoothAdapter.LeScanCallback {
private String TAG = makeLogTag(LeScanCallbackClass.class.getName());
private final WeakReference<TrackActivity> mAct;
public LeScanCallbackClass(TrackActivity act) {
mAct = new WeakReference<>(act);
}
#Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
LOGI(TAG, String.format("BLE LeScan Result: %s", device.getAddress()));
final TrackActivity act = mAct.get();
act.runOnUiThread(new Runnable() {
#Override
public void run() {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
}
});
act.sendNotification();
}
}

How can I do a sprite to jump with moveYModifier when I touch the screen

I'm still new with programming android. I have a problem with my game project. The problem is I have a problem with moveYModifier for sprite to jump when I touch the screen. Other problem is I got an error when I try to make a touch event method. Can somebody help me, so I can understand how to write correctly the method. I do not use engine extension because I think it's enough by using moveYModifier. I already search the answer but I still confuse about it. Thanks.
here my code :
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.modifier.MoveYModifier;
import org.anddev.andengine.entity.modifier.SequenceEntityModifier;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.background.AutoParallaxBackground;
import org.anddev.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
public class KetigaMainActivity extends BaseGameActivity implements IOnSceneTouchListener{
private int CAMERA_WIDTH = 800;
private int CAMERA_HEIGHT = 480;
private BitmapTextureAtlas bitmapTextureAtlas;
private TiledTextureRegion playerTextureRegion;
private BitmapTextureAtlas autoParallaxBackgroundTexture;
private TextureRegion parallaxLayerBack;
private TextureRegion parallaxLayerMid;
private TextureRegion parallaxLayerFront;
private TextureRegion parallaxLayerBackMid;
private int jumpHeight = 100;
private int jumpDuration = 2;
private int playerX = CAMERA_WIDTH/2;
private int playerY = CAMERA_HEIGHT - playerTextureRegion.getTileHeight() - (parallaxLayerFront.getHeight()/3);
#Override
public Engine onLoadEngine() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
}
#Override
public void onLoadResources(){
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.bitmapTextureAtlas = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.playerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.bitmapTextureAtlas, this, "ulat10.png",0,0,4,2);
this.autoParallaxBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT);
this.parallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "tanah6.png",0,810);
this.parallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "background1.png",0,0);
this.parallaxLayerBackMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "gunung3.png",0,490);
this.parallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "awan5.png",0,700);
this.mEngine.getTextureManager().loadTextures(this.bitmapTextureAtlas, this.autoParallaxBackgroundTexture);
}
#Override
public Scene onLoadScene(){
new Scene();
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.parallaxLayerBack.getHeight(), this.parallaxLayerBack)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-1/4.0f, new Sprite(0, CAMERA_HEIGHT - this.parallaxLayerBackMid.getHeight() - (parallaxLayerFront.getHeight()/6), this.parallaxLayerBackMid)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-1/2.0f, new Sprite(0, 0,this.parallaxLayerMid)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-3.0f, new Sprite(0, CAMERA_HEIGHT - this.parallaxLayerFront.getHeight(), this.parallaxLayerFront)));
scene.setBackground(autoParallaxBackground);
AnimatedSprite player = new AnimatedSprite(playerX, playerY, this.playerTextureRegion);
player.setScaleCenterY(this.playerTextureRegion.getTileHeight());
player.animate(new long[]{100, 100, 100},0 ,2, true);
scene.setOnSceneTouchListener(this);
scene.attachChild(player);
return scene;
}
#Override
public void onLoadComplete(){
}
#Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if (pSceneTouchEvent.isActionDown()) {
jump(); // this where I got an error
}
return false;
}
public boolean jump(AnimatedSprite player){
final MoveYModifier moveUpModifier = new MoveYModifier(jumpDuration /2, playerY, playerY + jumpHeight);
final MoveYModifier moveDownModivier = new MoveYModifier(jumpDuration /2, playerY + jumpHeight, playerY );
final SequenceEntityModifier modifier = new SequenceEntityModifier(moveUpModifier, moveDownModivier);
player.registerEntityModifier(new SequenceEntityModifier (modifier));
return true;
}
}
#Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent)
{
if (pSceneTouchEvent.isActionDown())
{
jump(player);
}
return false;
}
You can use the JumpModifier instead
public boolean jump(AnimatedSprite player){
//your innitial y-position
final float innitialYPosition = 120;
//-140 means jump upward, positive move downward
JumpModifier jumpModifier = new JumpModifier(1, fromX, toX, fromY, toY, -140, new IEntityModifier.IEntityModifierListener() {
#Override
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
animatedSprite.stopAnimation(0);
}
#Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
animatedSprite.animate(50);
animatedSprite.setY(innitialYPosition);
}
});
animatedSprite.registerEntityModifier(jumpModifier);
}

No able to capture image via Nokia C Series and send it to Web Server

I am making an Application in J2ME, with the use of this application user will be able to capture an image and at the same time upload that image to Web Server, but whenever I use this app in my Nokia C series I am not able to capture an image and whenever use this application via Computer able to capture an image but send command is not working please see the problem and sort out this problem, and guide what I need to do to make this app helpful and useful for me …………….Thanks Amit here
public class myMidlet extends MIDlet implements CommandListener{
private Display display;
private Form form;
private Command exit, back, capture, camera, send;
private Player player;
private VideoControl videoControl;
private Video video;
int status = 0;
byte localData[];
public myMidlet() {
display = Display.getDisplay(this);
form = new Form("My Form");
exit = new Command("Exit", Command.EXIT, 0);
camera = new Command("Camera", Command.SCREEN, 1);
back = new Command("Back", Command.BACK, 2);
capture = new Command("Capture", Command.SCREEN, 3);
send = new Command("Send", Command.OK, 1);
form.addCommand(camera);
form.addCommand(exit);
form.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command c, Displayable s){
String label = c.getLabel();
if (label.equals("Exit")){
destroyApp(true);
} else if (label.equals("Camera")) {
showCamera();
} else if (label.equals("Back"))
display.setCurrent(form);
else if (label.equals("Capture")) {
video = new Video(this);
video.start();
form.addCommand(send);
form.removeCommand(camera);
}
else if( label.equalsIgnoreCase("Send") ){
try {
startSendOperation();
} catch (Exception ex) {
}
}
}
public boolean uploadImage( String uri, byte[] rawImage)throws Exception
{
HttpConnection httpConnection;
OutputStream out;
// Open connection to the script
httpConnection = (HttpConnection)Connector.open( uri );
// Setup the request as an HTTP POST and encode with form data
httpConnection.setRequestMethod( HttpConnection.POST );
httpConnection.setRequestProperty( "Content-type", "application/
x-www-form-urlencoded" );
// Encode the imagedata with Base64
String encoded = Base64.encode( rawImage ).toString();
// Build the output and encoded string
String output = "imgdata=" + encoded;
// Set the content length header
httpConnection.setRequestProperty("Content-Length", Integer.toString
((output.getBytes().length)));
// Open the output stream and publish data
out = httpConnection.openOutputStream();
out.write( output.getBytes() );
// Flush the buffer (might not be necessary?)
out.flush();
// Here you might want to read a response from the POST to make
// sure everything went OK.
// Close everything down
if( out != null )
if( httpConnection != null )
httpConnection.close();
// All good
return true;
}
public void startSendOperation() throws Exception{
boolean res = uploadImage( "http://www.xxx.com/postFolder?", localData);
}
public void showCamera(){
try{
player = Manager.createPlayer("capture://video");
player.realize();
videoControl = (VideoControl)player.getControl("VideoControl");
Canvas canvas = new VideoCanvas(this, videoControl);
canvas.addCommand(back);
canvas.addCommand(capture);
canvas.setCommandListener(this);
display.setCurrent(canvas);
player.start();
} catch (IOException ioe) {} catch (MediaException me) {}
}
class Video extends Thread {
myMidlet midlet;
public Video(myMidlet midlet) {
this.midlet = midlet;
}
public void run() {
captureVideo();
}
public void captureVideo() {
try {
byte[] photo = videoControl.getSnapshot(null);
localData = photo;
Image image = Image.createImage(photo, 0, photo.length);
form.append(image);
display.setCurrent(form);
player.close();
player = null;
videoControl = null;
} catch (MediaException me) { }
}
};
}
class VideoCanvas extends Canvas {
private myMidlet midlet;
public VideoCanvas(myMidlet midlet, VideoControl videoControl) {
int width = getWidth();
int height = getHeight();
this.midlet = midlet;
videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
try {
videoControl.setDisplayLocation(2, 2);
videoControl.setDisplaySize(width - 4, height - 4);
} catch (MediaException me) {}
videoControl.setVisible(true);
}
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
g.setColor(255, 0, 0);
g.drawRect(0, 0, width - 1, height - 1);
g.drawRect(1, 1, width - 3, height - 3);
}
}
In ShowCamera method,Instead of
Manager.createPlayer("capture://video");
Try using
Manager.createPlayer("capture://image");

Why I am getting the bad length exception when I am running this application?

I want to communicate to a server from J2me app using UDP.However, when I am running the app, I am getting a bad length exception.My codes and output are given below.
client code
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.io.Connector;
import javax.microedition.io.Datagram;
import javax.microedition.io.DatagramConnection;
import java.io.IOException;
public class DatagramTest extends MIDlet
implements CommandListener, Runnable
{
private static final int BUF_SIZE = 1024;
private static Command exit = new Command("Exit", Command.EXIT, 1);
private static DatagramTest instance;
private Display display;
private TextBox dgramText;
private DatagramConnection conn;
private Datagram dgram;
private String address = "datagram://myip:9876";
public DatagramTest()
{
super();
instance = this;
}
public DatagramTest(String service)
{
this();
address = service;
}
/**
Returns the single instance of this class. Calling
this method before constructing an object will return
a null pointer.
#return an instance of this class.
*/
public static DatagramTest getInstance()
{
return instance;
}
public void startApp()
{
display = Display.getDisplay(this);
dgramText = new TextBox("Datagram contents",
null,
2048,
TextField.ANY);
dgramText.setCommandListener(this);
display.setCurrent(dgramText);
System.out.println("Starting run....");
run();
System.out.println("Stopping run....");
}
public void run()
{
System.out.println("In run....");
try
{
int maxLength;
conn = (DatagramConnection)Connector.open(address);
maxLength = conn.getMaximumLength();
dgram = conn.newDatagram(1024);
dgram.reset();
conn.send(dgram);
conn.receive(dgram);
byte[] data = dgram.getData();
// Extract the response string.
String str = new String(data);
System.out.println(str);
dgram.reset();
System.out.println("Exit run....");
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage());
ioe.printStackTrace();
quit();
}
return;
}
public void pauseApp()
{
}
void quit()
{
destroyApp(true);
notifyDestroyed();
}
public void destroyApp(boolean destroy)
{
try
{
conn.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
public void display()
{
Display.getDisplay(this).setCurrent(dgramText);
}
public void commandAction(Command c, Displayable d)
{
if (c == exit)
{
quit();
}
}
}
Server code
import java.io.*;
import java.net.*;
class UDPServer
{
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData());
System.out.println("RECEIVED: " + sentence);
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, port);
serverSocket.send(sendPacket);
}
}
}
Output at clientside
Starting run.... In run.... Bad
datagram length java.io.IOException:
Bad datagram length
at com.sun.midp.io.j2me.datagram.Protocol.receive(Protocol.java:367)
at hello.DatagramTest.run(DatagramTest.java:89)
at hello.DatagramTest.startApp(DatagramTest.java:69)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466)
at com.sun.midp.main.Main.main(Main.java:120)
Stopping run....
Why I am getting this bad length exception and how do I sort it out?
One thing you need to try is to send and receive datagrams in a separate thread.
The documentation for DatagramConnection.receive() says: "This method blocks until a datagram is received"
You are calling it from inside MIDlet.startApp().
Blocking the application management system thread that calls startApp() is bad practice.

displaying image in j2me application

How do I create and display an image in j2me application?
And in which folder can I put that image in my application?
This link has exactly what you are looking for to get started.
Basically, to create the image, you call upon Image.createImage();
Image img = Image.createImage("/imageName.png");
If it is in a sub-folder in the Jar:
Image img = Image.createImage("/subDir/imageName.png");
To display the image, you need to paint it to a Canvas through a Graphics instance that is tied to the Canvas (better visualized in the link above).
public void paint(Graphics g) {
...
g.drawImage(img, 0, 0, Graphics.TOP | Graphics.LEFT);
....
}
You could also use the Graphics.drawRegion function, but here is a link to the JavaDocs for J2ME for you to look through to see what is best for your needs.
To draw an Image on a JavaME MIDlet you need a Canvas to paint it on to. You can do as follow:
Firs you have to place the original image file inside your package (usually inside "res" or one of his subdirectories).
Secondly you need to create a class extending Canvas and implement the paint method:
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class MyCanvas extends Canvas {
private Image image;
public MyCanvas(){
try {
image = Image.createImage("picture.png");
} catch (IOException e) {
e.printStackTrace();
}
}
protected void paint(Graphics g) {
g.drawImage(image, 10, 10, Graphics.TOP | Graphics.LEFT);
}
}
Now you need to create an instance of this class and tell the MIDlet di display it, for example:
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MyMIDlet extends MIDlet {
public MyMIDlet(){
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(new MyCanvas());
}
}
Remember that this way the Canvas will be painted only one time and if you change something, you need to call the repaint() method.
This source code builds on previously posted comments:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImageLoader extends MIDlet
implements CommandListener, Runnable {
private Display mDisplay;
private Form mForm;
public ImageLoader() {
mForm = new Form("Connecting...");
mForm.addCommand(new Command("Exit", Command.EXIT, 0));
mForm.setCommandListener(this);
}
public void startApp() {
if (mDisplay == null) mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mForm);
Thread t = new Thread(this);
t.start();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
}
public void run() {
FileConnection fc = null;
DataInputStream in = null;
DataOutputStream out = null;
try {
fc = (FileConnection)Connector.open("file:///root1/i.PNG");
int length = (int)fc.fileSize();//possible loss of precision may throw error
byte[] data = null;
if (length != -1) {
data = new byte[length];
in = new DataInputStream(fc.openInputStream());
in.readFully(data);
}
else {
int chunkSize = 512;
int index = 0;
int readLength = 0;
in = new DataInputStream(fc.openInputStream());
data = new byte[chunkSize];
do {
if (data.length < index + chunkSize) {
byte[] newData = new byte[index + chunkSize];
System.arraycopy(data, 0, newData, 0, data.length);
data = newData;
}
readLength = in.read(data, index, chunkSize);
index += readLength;
} while (readLength == chunkSize);
length = index;
}
Image image = Image.createImage(data, 0, length);
ImageItem imageItem = new ImageItem(null, image, 0, null);
mForm.append(imageItem);
mForm.setTitle("Done.");
fc = (FileConnection)Connector.open("file:///root1/x.PNG");
if(!fc.exists()){
try{
fc.create();
}catch(Exception ce){System.out.print("Create Error: " + ce);}
}
out = new DataOutputStream(fc.openOutputStream());
out.write(data);
}
catch (IOException ioe) {
StringItem stringItem = new StringItem(null, ioe.toString());
mForm.append(stringItem);
mForm.setTitle("Done.");
}
finally {
try {
if (in != null) in.close();
if (fc != null) fc.close();
}
catch (IOException ioe) {}
}
}
}
The code is modified from the link Fostah provided here.
It opens an image, displays it, then saves it as x.PNG instead of i.PNG using FileConnection. The tricky thing to watch for is where the file is being saved/loaded from. If your using J2meWTK with Netbeans, then the folder will be displayed in the output window when you run the mobile app. The folder will be something like temp.DefaultColorPhone/filesystem/root1 . That is where you will have to have an image. I'm not sure how to have the temp environment created with the image by default. That means you have to start the mobile app, check where the temp root1/ is located, in your IDE, then drop the image into the folder, then proceed with running the ImageLoader application. I'll try to find out how to automate this by posting a question. Also, Start with a small image, 50x50 (bigger images may cause problems).

Resources