java.lang.NoClassDefFoundError: org/apache/axis/client/Service

fight_flight 2010-06-12 11:10:28
我要做一个在手机上调用webservice的程序(使用wsdl),调用的程序在webProject中可以正常完成。但我建立一个J2me的J2ME Midlet Suite时把调用的项关代码考入Midlet中,并已把相应jar包导入工程,但运行是提示错误:
java.lang.NoClassDefFoundError: org/apache/axis/client/Service
at Hello.call(+4)
at Hello.commandAction(+18)
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.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
Execution completed.
请问高手要怎样解决呢?
Midlet程序如下:

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;
}
}
}

...全文
5040 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
limwz 2010-06-12
  • 打赏
  • 举报
回复
喔又改了一下。j2me里面有两个文件
callService.java 代码

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]);
}
}
}

单独运行此文件可以正确得到结果。
另一个文件为Hello.java代码

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]);
}
}
}
}

运行此程序,然后单击手机右上角按钮之后显示下面错误
java.lang.NoClassDefFoundError: org/apache/axis/client/Service
at callService.call(+4)
at Hello.commandAction(+26)
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.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
Execution completed.
yojiwei 2010-06-12
  • 打赏
  • 举报
回复
如果类似的包有多个,也会起冲突的,你只需要确定它需要的包,导入即可。
导入的时候请注意,版本。。。
zijing660 2010-06-12
  • 打赏
  • 举报
回复
J2ME不用那些包吧?

你的服务器才需要啊
fight_flight 2010-06-12
  • 打赏
  • 举报
回复
我在这个工程中新建了另一个普通的类
再类中调用call函数,输出
- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
(是返回的结果)
canteen1
10
5.3
2010-5-20 20:37:10
可以返回结果,但上面会输出一行,怎么回事啊
fight_flight 2010-06-12
  • 打赏
  • 举报
回复
包加了啊我也不知道具体加那些,所以把相关的都添加了。
axis.jar
axis-ant.jar
commons-discovery-0.2.jar
....
但问题依旧???
Java技术栈 2010-06-12
  • 打赏
  • 举报
回复
java.lang.NoClassDefFoundError: org/apache/axis/client/Service
at Hello.call(+4)

很明显 你apache axis2相关包没有加入进来

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧