Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2008, 01:58 AM
Member
 
Join Date: Jan 2008
Posts: 1
bartosz666 is on a distinguished road
J2ME and files
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:

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) { } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-26-2008, 01:21 PM
Member
 
Join Date: Nov 2007
Posts: 5
hobbyist is on a distinguished road
I just had a quick read of your code and I do not see an instantiation of a TextBox object. So I guess the problem is that your TextBox object is null being returned from get_helloForm() method. In fact you are returning the global object helloTextBox which has not been instantiated. I think you should look to see if you are getting a nullPointerException.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-26-2008, 07:36 PM
Member
 
Join Date: Nov 2007
Posts: 5
hobbyist is on a distinguished road
Somewhere in your code you need:
helloTextBox = new TextBox(String title, String contents, int size, int type);

In your initialise() method you are:
getDisplay().setCurrent(get_helloForm());

I think that a null is being returned from get_helloForm() so a nullPointerException will be thrown when you try to setDisplay() in your initialize() method.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
J2me kuttyniti@gmail.com Sun Java Wireless Toolkit 0 11-24-2007 07:27 AM
J2ME Webcam 0.1 JavaBean Java Announcements 0 10-31-2007 06:25 PM
J2ME ChartComponent 1.5 JavaBean Java Announcements 0 07-01-2007 10:20 AM
Servlets with J2ME Daniel CLDC and MIDP 1 06-25-2007 06:26 AM
Fire j2me 1.2 JavaBean Java Announcements 0 06-22-2007 12:46 AM


All times are GMT +3. The time now is 02:11 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org