Java me 在j2me中调用库jar文件时出错
我已经用j2me中的webservice创建了一个登录页面。但在运行时,我遇到了错误。有人能帮忙吗?我的代码是:Java me 在j2me中调用库jar文件时出错,java-me,Java Me,我已经用j2me中的webservice创建了一个登录页面。但在运行时,我遇到了错误。有人能帮忙吗?我的代码是: public class Login extends MIDlet implements CommandListener { //the main form Form mainForm = null; //the text-boxes for the input TextField txtBoxA = null;
public class Login extends MIDlet implements CommandListener {
//the main form
Form mainForm = null;
//the text-boxes for the input
TextField txtBoxA = null;
TextField txtBoxB = null;
//the result label
//the Exit command
Command cmdExit = null;
Command cmdAdd = null;
//the Display reference
Display display = null;
public Login() {
{
//construct the main form
mainForm = new Form("kSOAP Example");
//construct the controls
txtBoxA = new TextField("UserName:", null, 50, TextField.ANY);
txtBoxB = new TextField("Password:", null, 50, TextField.ANY);
// result = new StringItem("Result:", null);
//add controls to the form
mainForm.append(txtBoxA);
mainForm.append(txtBoxB);
// mainForm.append(result);
//construct commands
cmdExit = new Command("Exit", Command.EXIT, 1);
cmdAdd = new Command("Add", Command.SCREEN, 1);
//add commands
mainForm.addCommand(cmdAdd);
mainForm.addCommand(cmdExit);
}
}
public void startApp() {
if (display == null) {
display = Display.getDisplay(this);
}
//display the main form
display.setCurrent(mainForm);
//register the command listener
mainForm.setCommandListener(this);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == cmdExit) {
this.destroyApp(false);
this.notifyDestroyed();
} else if (c == cmdAdd) {
//callWebServiceMethod();
Library lib=new Library();
lib.init();
}
}
我的jar文件编码是library.jar
public class Library {
String METHOD_NAME = "ValidateLogin_M";
String SOAP_ACTION ="http://64.244.69.235:81/MobileApp/ValidateLogin_M";
String NAMESPACE ="http://64.244.69.235:81/MobileApp/";
String URL ="http://64.244.69.235:81/MobileApp/service1.asmx";
public Library() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Library lib=new Library();
lib.init();
}
public void init()
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String user= "gsrtestnew@gmail.com";
String password= "123456";
request.addProperty("UserID",user);
request.addProperty("Password",password);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransport j2meHttpTransport = new HttpTransport(URL);
try {
j2meHttpTransport.call(SOAP_ACTION, envelope);
SoapObject content = (SoapObject) envelope.bodyIn;
String sum = content.getProperty(0).toString();
// result.setText(sum);
System.out.println("##########"+sum);
JSONArray jsonobj = new JSONArray(sum.toString());
System.out.println("Json obj length:: " + jsonobj.length());
if(jsonobj.length() == 0)
{
}
for(int i=0; i<jsonobj.length(); i++)
{
JSONObject jobj = jsonobj.getJSONObject(i);
String CustID = jobj.getString("CustID");
System.out.println("CustID is :: "+CustID);
String Email = jobj.getString("Email");
System.out.println("Email is :: "+Email);
String FirstName = jobj.getString("FirstName");
System.out.println("FirstName is :: "+FirstName);
String LastName = jobj.getString("LastName");
System.out.println("LastName is :: "+LastName);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
公共类库{
字符串方法\u NAME=“ValidateLogin\u M”;
字符串SOAP_ACTION=”http://64.244.69.235:81/MobileApp/ValidateLogin_M";
字符串命名空间=”http://64.244.69.235:81/MobileApp/";
字符串URL=”http://64.244.69.235:81/MobileApp/service1.asmx";
公共图书馆(){
//TODO自动生成的构造函数存根
}
/**
*@param args
*/
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
库lib=新库();
lib.init();
}
公共void init()
{
SoapObject请求=新的SoapObject(名称空间、方法名称);
字符串用户=”gsrtestnew@gmail.com";
字符串密码=“123456”;
request.addProperty(“UserID”,用户);
request.addProperty(“密码”,Password);
SOAPSerialization信封=
新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
HttpTransport j2meHttpTransport=新的HttpTransport(URL);
试一试{
调用(SOAP_操作,信封);
SoapObject内容=(SoapObject)信封.bodyIn;
String sum=content.getProperty(0.toString();
//result.setText(总和);
System.out.println(“+sum”);
JSONArray jsonobj=新的JSONArray(sum.toString());
System.out.println(“Json obj长度::”+jsonobj.length());
if(jsonobj.length()=0)
{
}
对于(int i=0;i这已经得到了回答-由于版本不同,jvm无法加载类-cf-
重新编译
javac -target 1.4 ...
已回答cf
javac -target 1.4 ...