after I launch netbeans' mobile phone emulator and choose the middlet to execute in the emulator screen I got a question if I wish to execute a 'reading' operation on file. When I click 'Yes' the program instead of reading the file - immidiately ends working and comes back to midlet list... and the requested read of file and printing its conent doesn work...
below is the code:
/*
* live.java
*
* Created on 12 styczeń 2008, 02:18
*/
package futbol24;
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.io.*; // do laczenia sie z serwerem
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.sun.midp.io.j2me.storage.File;
import com.sun.perseus.platform.BufferedInputStream;
import java.io.*;
import javax.microedition.io.file.*;
/**
*
* @author bart
* @version
*/
public class live extends MIDlet implements CommandListener {
public live() {
}
private Form helloForm;
private TextBox helloTextBox;
private StringItem helloStringItem;
private Command exitCommand;
private void initialize() throws IOException {
getDisplay().setCurrent(get_helloForm());
}
public void commandAction(Command command, Displayable displayable) {
if (displayable == helloForm) {
if (command == exitCommand) {
exitMIDlet();
}
}
}
public Display getDisplay() {
return Display.getDisplay(this);
}
public void exitMIDlet() {
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
static String getLine(InputStream is) {
String linijka = "";
try {
byte b[] = new byte[1];
int koniec;
koniec = is.read(b);
if( koniec != -1 ) {
while((new String(b).equals("\r")==false) && koniec!=-1) //wczytuje cala linijke
{
linijka+=new String(b);
koniec = is.read(b);
}
} else if(koniec==-1) {
return "EOF";
}
} catch (IOException ex) {
ex.printStackTrace();
}
return linijka;
}
public TextBox get_helloForm() throws IOException {
if (helloForm == null) {
HttpConnection sc = (HttpConnection)Connector.open("http://kolos.math.uni.lodz.pl/~bart/tekstowy.txt");
InputStream is = sc.openInputStream();
boolean flaga = true;
String linijka;
int a=0;
while(flaga) {
linijka = this.getLine(is);
if(linijka.equals("EOF")) {
System.out.println("koniec pliku");
flaga = false;
break;
} else {
helloTextBox.insert(linijka,helloTextBox.size());
}
}
}
return helloTextBox;
}
public Command get_exitCommand() {
if (exitCommand == null) {
exitCommand = new Command("Exit", Command.EXIT, 1);
}
return exitCommand;
}
public void startApp() {
try {
initialize();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}