在黑莓模拟器上运行Web服务时出错

我正在尝试从我开发的BlackBerry应用程序访问Web服务。

但是,当我运行应用程序时,我得到了

“App Error 104 Uncaught:NullPointerException”

我无法调试,因为一些奇怪的原因我的调试器在我开始调试时自动关闭。

关于可能是什么原因的任何建议? 我想提一下,我收到了来自BlackBerry的三个.csi签名文件,但每当我尝试签署该应用程序时,它都会失败: 代码签名注册请求中的签名信息的长度不合适 。 这个错误可能是由于签署申请?

这是我到目前为止所做的:

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://sofzh.miximages.com/java/ends 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"); } } } 

代码签名

正如Th0rndike所说,你不需要签署代码来在模拟器中运行,所以这不是你的问题(在模拟器中)。

让调试器再次工作

此外,如果您在设置断点或单步执行自己的Java源代码时遇到问题,那么:

  1. 在模拟器内部,像在普通设备上一样删除应用程序。
  2. 重启模拟器。
  3. 尝试再次从Eclipse运行。 如果它仍然不起作用:
  4. 在Eclipse中,从BlackBerry菜单中选择Clean Simulator ,然后选择您正在使用其模拟器的JRE包(例如5.0.0,6.0.0等)
  5. 尝试再次从Eclipse运行。 如果它仍然不起作用:
  6. 我会尝试重新安装Eclipse和BlackBerry Java插件( 一起 ……而不是安装非BlackBerry Eclipse IDE,然后单独添加BlackBerry插件)。 您可以从此站点下载完整的Eclipse + BlackBerry插件。

请记住,您将无法 进入 Java运行时和RIM库的Java代码。 您没有Java 源代码 ,只有二进制库。 所以,如果你有代码行:

 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 

你将无法进入第二行,因为substring(int,int)不是你的代码。 但是,假设MyWidget.java是您的Java源文件之一,您应该能够进入mw.foo()而不会看到“Source Not Found”错误。

查找exception被抛出的位置

如果您正在运行,并且无法找到抛出未捕获的NullPointerException (或其他exception)的位置, 请参阅此答案 。 基本上,只需将此调试代码放在主程序中(例如MyApp.java):

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

然后,在捕获Throwable之后,检查Eclipse Console窗口中的堆栈跟踪信息,显示exception的来源。 然后,再次调试,尝试进入该代码,看看有什么问题。

但是,获得一个正常运行的调试器是生产开发的绝对要求。 在调试适合您之前,请不要理会其他问题。