Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 移动互联网  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [求助]Neteans 執行問題
w8217





发贴: 2
积分: 0
于 2008-10-15 10:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list

package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;

//CommandListener,

public class HelloMIDlet extends MIDlet implements ItemStateListener{

private boolean midletPaused = false;
private Display display;
private Form form;
private Command exitCommand;
private Command okCommand;
private Command a;
private Command b;
private Command c;
private Command d;
private StringItem stringItem;
private ChoiceGroup group;
private TextField textfield;
private TextField infor;
private TextField name;
private TextField book;
private TextField in;

public Form getForm() {
Image[] imageArray=null;
try {
Image duke=Image.createImage("/Icon.png");
imageArray=new Image[]{ duke,duke,duke,duke};
}catch(java.io.IOException err){}
if(form==null){
exitCommand = new Command("Exit", Command.EXIT, 1);
okCommand=new Command("send",Command.ITEM,1);
a=new Command("",Command.ITEM,1);
b=new Command("",Command.ITEM,1);
c=new Command("",Command.ITEM,1);
d=new Command("",Command.ITEM,1);
infor=new TextField("infor","text",18,TextField.ANY);
form.append(infor);
name=new TextField("name","text",18,TextField.ANY);
form.append(name);
book=new TextField("book","text",18,TextField.ANY);
form.append(book);
in=new TextField("in","text",18,TextField.ANY);
form.append(in);
textfield = new TextField("confirm item:","auto confirm",20,TextField.ANY);

form = new Form("Welcome", new Item[] {getStringItem()});
String[] stringArray={"a","b","query","continue out book" };
group =new ChoiceGroup("select item press enter",ChoiceGroup.POPUP,stringArray,imageArray);
form.append(group);
form.append(textfield);
form.addCommand(okCommand);
form.addCommand(exitCommand);
form.addCommand;
form.addCommand;
form.addCommand;
form.addCommand;
// form.setCommandListener(this);
form.setItemStateListener(this);
}
return form;
}

public void startApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {

}


public void callServlet() throws IOException {
HttpConnection http = null;
InputStream iStrm = null;
String infor1=infor.getString().trim();
String book2=book.getString().trim();
String name3=name.getString().trim();
String in4=in.getString().trim();


String url = "http://127.0.0.1/cellphone/servlet/SearchReaderInfo2" + "?" + "infor1="
+ infor1+"book2="
+book2+"name3="
+name3+"in4="
+in4;

try {
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.GET);
if (http.getResponseCode() == HttpConnection.HTTP_OK) {
iStrm = http.openInputStream();
int length = (int) http.getLength();
if (length > 0) {
byte servletData[] = new byte[length];
iStrm.read(servletData);
form.append("confirm ok : \n"
+ new String(servletData));
} else
form.append("no data");
}
} catch (Exception e) {
form.append("network error");
System.out.println(e.toString());
} finally {

if (iStrm != null)
iStrm.close();
if (http != null)
http.close();
}
}

public void updateServlet() throws IOException {

HttpConnection http = null;
InputStream iStrm = null;
String infor1=infor.getString().trim();
String book2=book.getString().trim();
String name3=name.getString().trim();
String in4=in.getString().trim();

String url = "http://127.0.0.1/cellphone/servlet/SearchReaderInfo2" + "?" + "infor1="
+ infor1+"book2="
+book2+"name3="
+name3+"in4="
+in4;

try {
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.GET);
if (http.getResponseCode() == HttpConnection.HTTP_OK) {
iStrm = http.openInputStream();
int length = (int) http.getLength();
if (length > 0) {
byte servletData[] = new byte[length];
iStrm.read(servletData);
form.append("confirm ok : \n"
+ new String(servletData));
} else
form.append("no data");
}
} catch (Exception e) {
form.append("network error");
System.out.println(e.toString());
} finally {

if (iStrm != null)
iStrm.close();
if (http != null)
http.close();
}
}

public void commandAction(Command a,Command b,Command c, Displayable s) {
if (form==s){
if (a == exitCommand) {
exitMIDlet();
}
if (a == okCommand ) {
System.out.println("123");
}
if (b == okCommand ) {
System.out.println("123");
}
if (c == okCommand ) {
System.out.println("123");
}

try{
System.out.println("error");
}
catch(Exception e ){
System.out.println("231");
}
}
}








public StringItem getStringItem() {
if (stringItem == null) {
// write pre-init user code here
stringItem = new StringItem("ksu libary", "please login:");
// write post-init user code here
}
return stringItem;
}

public void resumeMIDlet() {
}
private void initialize() {
}
public void startMIDlet() {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
// try {
// callServlet();
// } catch (Exception e) {
// System.out.println(e.toString());
// }
}
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {

Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}

}
public Display getDisplay () {
return Display.getDisplay(this);
}
public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}
public void itemStateChanged(Item item) {
if( item instanceof ChoiceGroup)
{
textfield.setString( group.getString(group.getSelectedIndex()));
}

}
}


編譯時會過 執行會發生錯誤
startApp threw an Exception
java.lang.NullPointerException
java.lang.NullPointerException
at hello.HelloMIDlet.getForm(HelloMIDlet.java:47)
at hello.HelloMIDlet.startMIDlet(HelloMIDlet.java:224)
at hello.HelloMIDlet.startApp(HelloMIDlet.java:78)
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)
請各位大大幫我看一下


w8217 edited on 2008-10-16 20:26

作者 Re:[求助]Neteans 執行問題 [Re:w8217]
junyuo





发贴: 95
积分: 0
于 2008-10-15 13:12 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
check line 47, maybe some object is null


OCAJ, SCJP, SCWCD, SCBCD, OCEJPA, OCUP Fundamental, OCA, BEA 8.1 Certified Administrator, IBM Certified SOA Solution Designer
作者 Re:[求助]Neteans 執行問題 [Re:w8217]
w8217





发贴: 2
积分: 0
于 2008-10-17 22:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Sorry 小弟看45行時 有執行到 所以不知道要怎樣改會 解決此錯誤 可以請前輩明示嘛



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923