读取自定义JAD属性时的java空值
我有一个黑莓应用程序。它是从提供动态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..)
我需要获取像“Appid”这样的自定义属性,但它有时会获取空值。用户可以下载并运行该应用程序,但其中一些用户无法获取我的自定义属性。我不知道这与手机型号或操作系统的当前状态有关,但根据我的日志,这个问题主要出现在那些设备上:
9800和OS 6.0.0.546
9300和OS 6.0.0.570
9300和OS 6.0.0.668
9320和OS 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循环中的代码永远不会在这些情况下运行
知道吗
# 1 楼答案
有时,
ApplicationDescriptor.currentApplicationDescriptor().getModuleName()
给出同级cod文件的名称,而不是主cod文件的名称。因此,如果模块名为MyApp
,则函数可能返回MyApp-1
要解决这个问题,你必须去掉连字符后面的数字