java - 读取自定义 JAD 属性时出现空值

标签 java jsp blackberry

我有一个黑莓应用程序。它是从提供动态 JAD 文件内容的网页下载的。 JSP 打印这些:

out.println("Appid: " + appid);
out.println("Ip: " + user.getIp());
out.println("Servicename: " + service);
out.println("MIDlet-Version: 1.0.0");
out.println("MIDlet-Jar-URL: MyApp.jar");
out.println("MIDlet-Jar-Size: 91633");
out.println("MicroEdition-Profile: MIDP-2.0");
     (and other attributes goes on like that..)

我需要获取“Ap​​pid”等自定义属性,但它有时会获取空值。用户可以下载并运行该应用程序,但其中一些无法获取我的自定义属性。我不知道这与手机型号或操作系统的当前状态有关,但根据我的日志,此问题主要出现在这些设备上:

9800,操作系统 6.0.0.546

9300,操作系统 6.0.0.570

9300,操作系统 6.0.0.668

9320,操作系统为 7.1.0.398

我的获取属性的代码:

    CodeModuleGroup cmg = null;
    CodeModuleGroup[] allGroups = CodeModuleGroupManager.loadAll();
    String moduleName = ApplicationDescriptor
            .currentApplicationDescriptor().getModuleName();

    for (int i = 0; i < allGroups.length; i++) {
        if (allGroups[i].containsModule(moduleName)) {
            cmg = allGroups[i];
            break;
        }
    }

    if (cmg != null) {

        AppData.firstPageURL = cmg.getProperty("Firstpage");

        AppData.appId = cmg.getProperty("Appid");
        AppData.firstIp = cmg.getProperty("Ip");
        AppData.firstSubServiceName = cmg.getProperty("Servicename");

        for (Enumeration e = cmg.getPropertyNames(); e.hasMoreElements();) {

            String name = (String) e.nextElement();
            String value = cmg.getProperty(name);
            AppData.errorStep += "-" + name + ":" + value + "-";
        }
    }

顺便说一句,我确定上面的 for 循环中的代码在这些情况下永远不会运行。

有什么想法吗?

最佳答案

有时,ApplicationDescriptor.currentApplicationDescriptor().getModuleName() 给出同级 cod 文件的名称,而不是主 cod 文件的名称。因此,如果您的模块名称是 MyApp,该函数可能会返回 MyApp-1

要解决此问题,您必须去掉连字符后面的数字。

String moduleName = ApplicationDescriptor.currentApplicationDescriptor()
         .getModuleName();
if(moduleName.indexOf('-') > 0) {
    moduleName = moduleName.substring(0, moduleName.indexOf('-');
}

关于java - 读取自定义 JAD 属性时出现空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17005508/

相关文章:

java - 如何解析具有相同名称但不同级别的标签的 XML?

java - 黑莓编程——创建无边框弹出屏幕

java - 将 JSONObject 从 java web 服务传递到 JSP 页面

java - Spring 的安全。授权不适用于jsp

jsp - 亮点@Renderer.LayoutPath

java - 如何检测黑莓应用程序何时处于 Activity 状态?

黑莓现场事件未启动?

java - ListSelectionListener 接口(interface)中的 valueChanged 方法存在问题

Java 服务器和 socket.io

java - 了解为什么出现 "Array required, but string found"错误