出错运行在BlackBerry模拟器Web服务 [英] Error while running web service on blackberry simulator

查看:219
本文介绍了出错运行在BlackBerry模拟器Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我公司开发的黑莓应用程序访问一个Web服务。

但是,在运行应用程序,我得到的时候。


  

应用程序错误104未捕获:NullPointerException异常


我无法调试,出于某种奇怪的原因,我的调试器,只要我开始调试自动关闭。

这可能是什么原因有什么建议?我想提一提,我从黑莓收到三个.CSI签名文件,但每当我尝试登录该应用程序失败:在code签字注册请求签名信息是适当的长度不。难道这个错误是由于签署应用程序?

这是我迄今所做的:

mypackage的包;进口java.io.DataInputStream中;
进口java.io.DataOutputStream中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.io.OutputStream中;
进口java.rmi.RemoteException异常;
进口的java.util.Hashtable;进口javacard.framework.UserException;进口javax.microedition.io.Connector;
进口javax.microedition.io.HttpConnection;
进口javax.microedition.location.Location;
进口javax.microedition.location.LocationProvider;进口org.kobjects.base64.Base64;
进口org.ksoap2.SoapEnvelope;
进口org.ksoap2.serialization.SoapObject;
进口org.ksoap2.serialization.SoapPrimitive;
进口org.ksoap2.serialization.SoapSerializationEnvelope;
进口org.ksoap2.transport.HttpTransport;
进口org.xmlpull.v1.XmlPullParserException;net.rim.device.api.system数据导入*。
进口net.rim.device.api.ui。*;
导入net.rim.device.api.ui.component。*;
进口net.rim.device.api.ui.component.pane.TitleView;
导入net.rim.device.api.ui.container *。
进口net.rim.device.api.ui.image.Image;
进口net.rim.device.api.xml.jaxp.SAXParserImpl;公共类LoginTest扩展的UIApplication
{    公共静态无效的主要(字串[] args)
    {
         //创建应用程序的新实例
         //并启动事件线程上的应用程序。        LoginTest应用=新LoginTest();
        app.enterEventDispatcher();
    }    公共LoginTest()
    {
         //显示一个新的屏幕。
         pushScreen(新LoginTestScreen());
    }}//创建一个扩展MainScreen,并提供一个新的屏幕
//类似于其他应用程序的行为。最后一类LoginTestScreen扩展MainScreen
{
   //声明供以后使用变量
   私人InfoScreen _infoScreen;
   私人ObjectChoiceField choiceField;
   私人诠释选择;
   BasicEditField用户名;
   PasswordEditField passwd文件;
   CheckBoxField字段checkBox1;
   ButtonField字段loginBtn;   公共LoginTestScreen()
   {
        //调用MainScreen构造函数。        超();        //添加屏幕标题。        的setTitle(Track24ELMS);        登录的LabelField =新的LabelField(ELMS登录,LabelField.FIELD_HCENTER);
        login.setFont(Font.getDefault()获得(Font.BOLD,30));
        login.setMargin(10,0,20,0); //从顶部和底部留有一定的空间        Horizo​​ntalFieldManager用户=新Horizo​​ntalFieldManager();
        user.setMargin(0,0,10,0);
        Horizo​​ntalFieldManager通=新Horizo​​ntalFieldManager();
        pass.setMargin(0,0,20,0);
        Horizo​​ntalFieldManager复选框=新Horizo​​ntalFieldManager();
        checkbox.setMargin(0,0,30,0);
        Horizo​​ntalFieldManager btns =新Horizo​​ntalFieldManager(Horizo​​ntalFieldManager.FIELD_HCENTER);        usernameTxt的LabelField =新的LabelField(用户名:);
        passwordTxt的LabelField =新的LabelField(密码:);        用户名=新BasicEditField();
        passwd文件=新PasswordEditField();        loginBtn =新ButtonField字段(登录,ButtonField.CONSUME_CLICK);
        loginBtn.setChangeListener(新LoginButtonListener());        checkBox1 =新CheckBoxField字段(记住我,FALSE);        user.add(usernameTxt);
        user.add(用户名);
        pass.add(passwordTxt);
        pass.add(passwd)的;
        //checkbox.add(checkBox1);
        btns.add(loginBtn);
        加(登录);
        添加(用户);
        加(PASS);
        加(checkBox1);
        加(btns);
   }   私有类LoginButtonListener实现FieldChangeListener {
       公共无效fieldChanged(场场,诠释上下文){
       //打开一个新的屏幕
       字符串的uname = username.getText();
       字符串PWD = passwd.getText();       //如果没有输入
       如果(uname.length()== 0 || pwd.length()== 0)
       Dialog.alert(一个文本字段是空的!);
       其他
       {
           最终字符串URL =htt​​p://xxx.xxx.com/xxx/xxx.asmx;
           最后弦乐METHOD_NAME =ValidateCredentials;
           最后弦乐NAMESPACE =htt​​p://tempuri.org/;
           最后弦乐SOAP_ACTION = NAMESPACE + METHOD_NAME;
           //最后字符串的URL =HTTP://$p$prel.track24elms.com/Android/T24AndroidLogin.asmx/ValidateCredentials           SoapObject resultRequestSOAP = NULL;
           的HttpConnection httpConn = NULL;
           HttpTransport httpt;
           的System.out.println(用户名+ +的uname密码+ PWD);
           SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);
           request.addProperty(用户名,ABC); //第一个参数是由Web服务提供的标签名
           request.addProperty(密码,XYZ);
           的System.out.println(请求是=======+ request.toString());
           SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
           envelope.bodyOut =请求;
           envelope.dotNet = TRUE;
           envelope.encodingStyle = SoapSerializationEnvelope.XSD;
           envelope.setOutputSoapObject(请求);
           的System.out.println(包络具有值+++++ envelope.toString());           / * URL +在这里,您可以添加放慢参数,这样就可以在设备上运行,模拟器等,这只会工作,支持WiFi * /
           httpt =新HttpTransport(URL +; deviceside = TRUE; ConnectionUID = S TCP-无线);
           httpt.setXmlVersionTag(&下; XML版本= \\1.0 \\编码= \\UTF-8 \\>);
           httpt.debug = TRUE;
           尝试
           {
               的System.out.println(SOAP_ACTION ==+ SOAP_ACTION);
               httpt.call(SOAP_ACTION,信封);
               的System.out.println(本tranport+ httpt.toString());
               resultRequestSOAP =(SoapObject)envelope.bodyIn;
               的System.out.println(结果==+ resultRequestSOAP);
           }
           赶上(IOException异常五){
               // TODO自动生成catch块
               的System.out.println(唯一的例外是IO ==+ e.getMessage());
           }赶上(XmlPullParserException E){               // TODO自动生成catch块
               的System.out.println(例外XML解析器的例子===
                       + e.getMessage());
           }
           的System.out.println(resultRequestSOAP);
           如果(resultRequestSOAP.equals(credentialaccepted))
           {
           。UiApplication.getUiApplication()pushScreen(新InfoScreen()); //打开一个新的屏幕
           }
           其他
           {
               的System.out.println(登录信息无效);
           }
         }
      }   };   //要显示一个对话框时,BlackBerry设备用户
   //关闭应用程序,重写的OnClose()方法。   公共布尔的OnClose()
   {
        Dialog.alert(再见!);
        System.exit(0);
        返回true;
   }   //创建一个菜单项,BlackBerry设备用户点击查看更多
   //有关他们选择城市的信息。   私人菜单项_viewItem =新菜单项(更多信息,110,10)
   {
        公共无效的run()
        {
             //存放城市BlackBerry设备用户选择的指数             选择= choiceField.getSelectedIndex();             //显示一个新的屏幕有关的信息
             //城市BlackBerry设备用户选择             _infoScreen =新InfoScreen();
             。UiApplication.getUiApplication()pushScreen(_infoScreen);
        }
   };   //创建一个菜单项,BlackBerry设备用户点击关闭
   //应用程序。   私人菜单项_closeItem =新菜单项(关闭,20万,10)
   {
        公共无效的run()
        {
             的OnClose();
        }
   };
   //一个新的屏幕,显示创建一个内部类
   //有关BlackBerry设备用户选择城市的信息。   私有类InfoScreen扩展MainScreen
   {
        公共InfoScreen()
        {
             超();             的setTitle(行程);
             登录的LabelField =新的LabelField(员工行程,LabelField.FIELD_HCENTER);             位图位图= Bitmap.getBitma $ P $的PSource(img1.jpg);
             EditField中statusMsg =新EditField中(状态信息,在这里更新状态);        }
   }
}


解决方案

code签署

由于Th0rndike说,你并不需要签署code在模拟器中运行,所以这不是你的问题(在模拟器)。

获取调试工作再次

另外,如果你遇到了麻烦,甚至设置断点,或通过自己的Java源代码code步进,则:


  1. 模拟器里面,删除应用程序,就像一个正常的设备上。

  2. 重新启动模拟器。

  3. 尝试从Eclipse中重新运行。如果仍然不工作:

  4. 在Eclipse中,从黑莓菜单,选择清洁模拟器,然后将JRE程序包,其模拟器你使用(如5.0.0,6.0.0,等。)

  5. 尝试从Eclipse中重新运行。如果仍然不工作:

  6. 我会尝试重新安装Eclipse和黑莓的Java插件(一起 ...而不是安装一个非黑莓的Eclipse IDE,然后分别加入黑莓插件)。你可以从这个网站下载完整的Eclipse +插件黑莓

请记住,你的不可以能步骤的的Java的code这是Java运行时的一部分,和RIM库。您不必在Java的的那些,只是二进制类库。所以,如果你有code线:

 字符串S1 =afdafsdasdf;
字符串的子串= s1.substring(0,10); //< - 不能步调一致,可以跨过去
进myWidget MW =新进myWidget();
mw.foo(); //< - 可以介入,或者通过

您将无法步入第二行,因为子(INT,INT)不是你的code。但是,你应该能够进入 mw.foo()没有看到在源未找到错误,假设 MyWidget.java 是Java源文件中的一个。

查找哪里抛出异常

如果你正在运行,且很难找到在哪里未捕获的 NullPointerException异常(或其他异常)被抛出,的看到这个答案。基本上,只要把这个调试code在主程序(例如MyApp.java):

 公共静态无效的主要(字串[] args)
{
    尝试{
        应用该app =新MyApp的();
        theApp.enterEventDispatcher();
    }赶上(的Throwable t)的{
        t.printStackTrace();
    }
}

然后,在被捕获的Throwable 后,检查了Eclipse的控制台窗口堆栈跟踪信息,表示将异常是从哪里来的。然后,再调试,试图步入了code,看看什么是错的。

但是,让一个正常运作的调试器是促进生产力发展的绝对要求。不要与其他问题费心,直到调试工作适合你。

I am trying to access a webservice from a BlackBerry application that I developed.

However, when running the app I get

" App Error 104 Uncaught: NullPointerException "

I am unable to debug, for some strange reason my debugger auto-closes as soon as I start debugging.

Any suggestions on what could be the reason? I would like to mention that I have received the three .csi signature files from BlackBerry, but whenever I try to sign the application it fails: The Signature information in the code signing register request is not of appropriate length. Could this error be due to signing the application?

This is what I've done so far:

package mypackage;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.rmi.RemoteException;
import java.util.Hashtable;

import javacard.framework.UserException;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.location.Location;
import javax.microedition.location.LocationProvider;

import org.kobjects.base64.Base64;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.component.pane.TitleView;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.image.Image;
import net.rim.device.api.xml.jaxp.SAXParserImpl;

public class LoginTest extends UiApplication 
{

    public static void main(String[] args)  
    {
         //Create a new instance of the app
         //and start the app on the event thread.

        LoginTest app = new LoginTest();
        app.enterEventDispatcher();
    }

    public LoginTest()
    {
         //Display a new screen.
         pushScreen(new LoginTestScreen());
    }

}

//Create a new screen that extends MainScreen and provides
//behaviour similar to that of other apps.

final class LoginTestScreen extends MainScreen
{
   //declare variables for later use
   private InfoScreen _infoScreen;
   private ObjectChoiceField choiceField;
   private int select;
   BasicEditField username;
   PasswordEditField passwd;
   CheckboxField checkBox1;
   ButtonField loginBtn;

   public LoginTestScreen()
   {
        //Invoke the MainScreen constructor.

        super();

        //Add a screen title.

        setTitle("Track24ELMS");

        LabelField login = new LabelField("ELMS Login", LabelField.FIELD_HCENTER); 
        login.setFont(Font.getDefault().derive(Font.BOLD, 30));
        login.setMargin(10, 0, 20, 0); //To leave some space from top and bottom

        HorizontalFieldManager user = new HorizontalFieldManager();
        user.setMargin(0, 0, 10, 0);
        HorizontalFieldManager pass = new HorizontalFieldManager();
        pass.setMargin(0, 0, 20, 0);
        HorizontalFieldManager checkbox = new HorizontalFieldManager();
        checkbox.setMargin(0, 0, 30, 0);
        HorizontalFieldManager btns = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);

        LabelField usernameTxt = new LabelField("Username :");
        LabelField passwordTxt = new LabelField("Password :");

        username = new BasicEditField();
        passwd = new PasswordEditField();

        loginBtn = new ButtonField("Login", ButtonField.CONSUME_CLICK); 
        loginBtn.setChangeListener(new LoginButtonListener());

        checkBox1 = new CheckboxField("Remember me",false);

        user.add(usernameTxt);
        user.add(username);
        pass.add(passwordTxt);
        pass.add(passwd);
        //checkbox.add(checkBox1);
        btns.add(loginBtn);
        add(login);
        add(user);
        add(pass);
        add(checkBox1);
        add(btns);
   }

   private class LoginButtonListener implements FieldChangeListener {
       public void fieldChanged(Field field, int context) {
       //Open a new screen
       String uname = username.getText();
       String pwd = passwd.getText();

       //If there is no input
       if (uname.length() == 0 || pwd.length()==0)
       Dialog.alert("One of the textfield is empty!");
       else 
       {
           final String URL = "http://xxx.xxx.com/xxx/xxx.asmx";
           final String METHOD_NAME = "ValidateCredentials";
           final String NAMESPACE = "http://tempuri.org/";
           final String SOAP_ACTION = NAMESPACE+METHOD_NAME;
           //final String URL = "http://prerel.track24elms.com/Android/T24AndroidLogin.asmx/ValidateCredentials";

           SoapObject resultRequestSOAP = null;
           HttpConnection httpConn = null;
           HttpTransport httpt;
           System.out.println("The username" + uname + "password" + pwd );
           SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
           request.addProperty("Username", "abc");//First parameter is tag name provided by web service
           request.addProperty("Password", "xyz");
           System.out.println("The request is=======" + request.toString());
           SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
           envelope.bodyOut = request;
           envelope.dotNet = true;
           envelope.encodingStyle = SoapSerializationEnvelope.XSD;
           envelope.setOutputSoapObject(request);
           System.out.println("The envelope has the value++++"+ envelope.toString());

           /* URL+  Here you can add paramter so that you can run on device,simulator etc. this will work only for wifi */
           httpt = new HttpTransport(URL+ ";deviceside=true;ConnectionUID=S TCP-WiFi");
           httpt.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
           httpt.debug = true;
           try
           {
               System.out.println("SOAP_ACTION    ==   " + SOAP_ACTION);
               httpt.call(SOAP_ACTION, envelope);
               System.out.println("the tranport" + httpt.toString());
               resultRequestSOAP = (SoapObject) envelope.bodyIn;
               System.out.println("result    ==   " + resultRequestSOAP);            
           }
           catch (IOException e) {
               // TODO Auto-generated catch block
               System.out.println("The exception is IO==" + e.getMessage());
           } catch (XmlPullParserException e) {

               // TODO Auto-generated catch block
               System.out.println("The exception xml parser example==="
                       + e.getMessage());
           }
           System.out.println( resultRequestSOAP);
           if(resultRequestSOAP.equals("credentialaccepted"))
           {
           UiApplication.getUiApplication().pushScreen(new InfoScreen()); //Open a new Screen
           }
           else
           {
               System.out.println("Login details not valid");
           }
         }
      }

   };

   //To display a dialog box when a BlackBerry device user
   //closes the app, override the onClose() method.

   public boolean onClose()
   {
        Dialog.alert("Goodbye!");
        System.exit(0);
        return true;
   }

   //Create a menu item for BlackBerry device users to click to see more 
   //information about the city they select.

   private MenuItem _viewItem = new MenuItem("More Info", 110, 10) 
   {
        public void run() 
        {
             //Store the index of the city the BlackBerry device user selects

             select = choiceField.getSelectedIndex();

             //Display a new screen with information about the
             //city the BlackBerry device user selects

             _infoScreen = new InfoScreen();
             UiApplication.getUiApplication().pushScreen(_infoScreen);
        }
   };

   //Create a menu item for BlackBerry device users to click to close 
   //the app.

   private MenuItem _closeItem = new MenuItem("Close", 200000, 10) 
   {
        public void run()
        {
             onClose();
        }
   };


   //Create an inner class for a new screen that displays
   //information about the city a BlackBerry device user selects.

   private class InfoScreen extends MainScreen
   {
        public InfoScreen() 
        {
             super();

             setTitle("Itinerary");


             LabelField login = new LabelField("Employee Itinerary", LabelField.FIELD_HCENTER); 

             Bitmap bitmap = Bitmap.getBitmapResource("img1.jpg");
             EditField statusMsg = new EditField("Status Message", "Update status here");

        }
   }
}

解决方案

Code Signing

As Th0rndike said, you don't need to sign code to run in the simulator, so that's not your problem (in the simulator).

Getting the Debugger Working Again

Also, if you're having trouble even setting breakpoints or stepping through your own Java source code, then:

  1. Inside the simulator, delete the application as you would on a normal device.
  2. Restart the simulator.
  3. Try running from Eclipse again. If it still doesn't work:
  4. Inside Eclipse, from the BlackBerry menu, choose Clean Simulator and then the JRE package whose simulator you're using (e.g. 5.0.0, 6.0.0, etc.)
  5. Try running from Eclipse again. If it still doesn't work:
  6. I would try reinstalling Eclipse and the BlackBerry Java plugin (together ... rather than installing a non-BlackBerry Eclipse IDE, and then adding the BlackBerry plugin separately). You can download the full Eclipse + BlackBerry plugin from this site.

Keep in mind that you will not be able to step into Java code that's part of the Java runtime, and RIM libraries. You do not have the Java source for those, only the binary libraries. So, if you have the line of code:

String s1 = "afdafsdasdf";
String substring = s1.substring(0, 10);  // <- can not step IN, can step OVER
MyWidget mw = new MyWidget();
mw.foo();                                // <- can step IN, or OVER

you would not be able to step into the second line, because substring(int,int) is not your code. But, you should be able to step into mw.foo() without seeing the "Source Not Found" errors, assuming MyWidget.java is one of your Java source files.

Finding Where Exceptions are Thrown

If you're running, and having trouble finding out where an uncaught NullPointerException (or other exception) is being thrown, see this answer. Basically, just put this debug code in your main program (e.g. MyApp.java):

public static void main(String[] args)
{
    try {
        Application theApp = new MyApp();
        theApp.enterEventDispatcher();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

And then, after the Throwable is caught, check the Eclipse Console window for stack trace information, showing where the exception came from. Then, debug again, trying to step into that code, and see what's wrong.

But, getting a functioning debugger is an absolute requirement for productive development. Don't bother with other problems until debugging works for you.

这篇关于出错运行在BlackBerry模拟器Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆