title image


Smiley J2ME - startApp threw an Exception: java.lang.NullPointerException
Hi Leute,

ich arbeite mich gerade in MIDP ein und habe schon Probleme bei einfachen Beispielen! ^^

Hab aus dem Buch J2ME in a Nutshell mal das 2te Beispiel rauskopiert und in dem Sony Ericsson Wireless Toolkit mit dem Emulator laufen lassen.



"Build" und "Run" funktionieren ja noch, aber sobald ich im Emu das Programm starten möchte mit "Launch" kommt es zu diesen Fehlern:



Project settings saved

Building "Test"

Build complete



Running with storage root SonyEricsson_Z520_Emu

startApp threw an Exception

java.lang.NullPointerException

java.lang.NullPointerException

at com.sun.cldc.i18n.Helper.getStreamReader(+15)

at com.sun.cldc.i18n.Helper.getStreamReader(+7)

at java.io.InputStreamReader.(+9)

at de.kayin.Test.startApp(+27)

at javax.microedition.midlet.MIDletProxy.startApp(+7)

at com.sun.midp.midlet.Scheduler.schedule(+270)

at com.sun.midp.main.Main.runLocalClass(+28)

at com.sun.midp.main.Main.main(+116)

Execution completed.

0 bytecodes executed

0 thread switches

779 classes in the system (including system classes)

0 dynamic objects allocated (0 bytes)

0 garbage collections (0 bytes collected)





Der Source-code aus dem Buch sieht so aus:



package de.kayin;



import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.IOException;

import javax.microedition.lcdui.Display;

import javax.microedition.lcdui.TextBox;

import javax.microedition.lcdui.TextField;

import javax.microedition.lcdui.Ticker;

import javax.microedition.midlet.MIDlet;



public class Test extends MIDlet {



// Maximum size of the text in the TextBox

private static final int MAX_TEXT_SIZE = 64;



// The TextBox

protected TextBox textBox;



// The MIDlet's Display object

protected Display display;



// Flag indicating first call of startApp

protected boolean started;



protected void startApp( ) {

if (!started) {



// First time through - initialize

// Get the text to be displayed

String str = null;

try {

InputStream is = getClass( ).getResourceAsStream(

"resources/text.txt");

InputStreamReader r = new InputStreamReader(is);

char[] buffer = new char[32];

StringBuffer sb = new StringBuffer( );

int count;

while ((count = r.read(buffer, 0, buffer.length)) > -1) {

sb.append(buffer, 0, count);

}

str = sb.toString( );

} catch (IOException ex) {

str = "Failed to load text";

}



// Create the TextBox

textBox = new TextBox("TextBox Example", str,

MAX_TEXT_SIZE, TextField.ANY);



// Create a ticker and install it

Ticker ticker = new Ticker("This is a ticker...");

textBox.setTicker(ticker);



// Install the TextBox as the current screen

display = Display.getDisplay(this);

display.setCurrent(textBox);

started = true;

}

}



protected void pauseApp( ) {



}



protected void destroyApp(boolean unconditional) {



}



}







Kann mir jemand sagen, woran es liegt?

Wo liegt der NullPointer-Fehler?



Danke schon mal im Voraus! :)



Greetz!

Kayin
いつでもどこでも頑張ってください! Egal wann, egal wo, gib immer dein Bestes!

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: