在j2me中调用库jar文件时出错

时间:2011-12-27 05:40:05

标签: 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;
        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();
            }
            }




        }

我导入了jar文件并调用了Library类。但我仍然得到错误。

我的错误是

Starting emulator in execution mode
Installing suite from: http://127.0.0.1:49412/WebApplication.jad
TRACE: <at java.lang.Error: ClassFormatError:  56>, Exception caught in Display class
java.lang.Error: ClassFormatError:  56
    at com.web.application.Login.commandAction(Login.java:95)
    at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
    at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
    at com.sun.midp.chameleon.layers.SoftButtonLayer.commandSelected(), bci=11
    at com.sun.midp.chameleon.layers.MenuLayer.pointerInput(), bci=170
    at com.sun.midp.chameleon.CWindow.pointerInput(), bci=76
    at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handlePointerEvent(), bci=19
    at com.sun.midp.lcdui.DisplayEventListener.process(), bci=296
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:722)

0 个答案:

没有答案