G
Gast_User
Gast
hallo
ich versuche gerade ein bischen mit j2me "herumzuspielen" und möchte eigendlich "nur" eine textdatei einlesen und ausgeben sozusagen.
Hier mal mein code und darunter der fehler (NullPointerException)
einze zeile in dem code ist auskommentiert. die darüberliegende zeile wirft die exception.
ich versuche gerade ein bischen mit j2me "herumzuspielen" und möchte eigendlich "nur" eine textdatei einlesen und ausgeben sozusagen.
Hier mal mein code und darunter der fehler (NullPointerException)
Code:
package Text;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
public class Textreader extends MIDlet implements CommandListener {
private Command exitCommand;
private Command nextCommand;
private Form form;
private Display display;
private byte[] text_temp;
private int anfang = 50;
private String temp;
public void lesen() {
InputStream is = this.getClass().getResourceAsStream("/text.txt");
DataInputStream dis = new DataInputStream(is);
try {
dis.readFully(text_temp, 10, 10);
// System.out.println(dis.);
System.out.println(text_temp[1]);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void textauslesen() {
display = Display.getDisplay(this);
form = new Form("Texte");
exitCommand = new Command("Exit", Command.EXIT, 2);
nextCommand = new Command("weiter", Command.OK, 3);
form.addCommand(exitCommand);
form.addCommand(nextCommand);
form.setCommandListener(this);
}
protected void startApp() {
textauslesen();
display.setCurrent(form);
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (command == nextCommand) {
lesen();
}
}
}
Code:
java.lang.NullPointerException
at java.io.DataInputStream.read(DataInputStream.java:80)
at java.io.DataInputStream.readFully(+34)
at Text.Textreader.lesen(Textreader.java:34)
at Text.Textreader.commandAction(Textreader.java:69)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)