13,100
社区成员
发帖
与我相关
我的任务
分享
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
//以下三个为调用webservice的包
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class Hello extends MIDlet implements CommandListener{
public void commandAction(Command c, Displayable d) {
if(c==comm){
//调用webservice,测试数据是可以得到结果的数据
String[] s=call("2010-4-5", "2010-6-3", "1587");
if(s.length>0){
textbox1.setString(s[0]);
System.out.println(s[0]);
}
}
}
private TextBox textbox1;
private Command comm=new Command("TEST",Command.SCREEN,1);
public Hello() {
super();
textbox1=new TextBox("测试","textbox1",20,0);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(textbox1);
textbox1.addCommand(comm);
textbox1.setCommandListener(this);
}
//调用函数,已通过测试函数本身没问题
public String[] call(String startDate,String endDate,String cardid){
try
{
String endpoint ="http://localhost:8080/Axis/foodWebService.jws";
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
call.setOperationName(new QName("http://localhost:8080/Axis/foodWebService.jws",
"function"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));
String[] ret = (String[]) call.invoke(new Object[]{startDate,endDate,cardid});
return ret;
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
return null;
}
}
}
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class callService {
public String[] call(String startDate,String endDate,String cardid){
try
{
String endpoint ="http://localhost:8080/Axis/foodWebService.jws";
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
call.setOperationName(new QName("http://localhost:8080/Axis/foodWebService.jws",
"function"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));
String[] ret = (String[]) call.invoke(new Object[]{startDate,endDate,cardid});
return ret;
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
return null;
}
}
public static void main(String[] args)
{
callService call=new callService();
String[] ret =call.call("2010-4-5", "2010-6-3", "1587");
for(int i=0;i<ret.length;i+=4){
System.out.println(ret[i]);
System.out.println(ret[i+1]);
System.out.println(ret[i+2]);
System.out.println(ret[i+3]);
}
}
}
单独运行此文件可以正确得到结果。
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import callService;
public class Hello extends MIDlet implements CommandListener{
private TextBox textbox1;
private Command comm=new Command("TEST",Command.SCREEN,1);
public Hello() {
super();
textbox1=new TextBox("测试","textbox1",20,0);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(textbox1);
textbox1.addCommand(comm);
textbox1.setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c==comm){
//调用webservice,测试数据是可以得到结果的数据
callService ca=new callService();
String[] s=ca.call("2010-4-5", "2010-6-3", "1587");
if(s.length>0){
textbox1.setString(s[0]);
System.out.println(s[0]);
}
}
}
}
运行此程序,然后单击手机右上角按钮之后显示下面错误