我正在尝试为 Windows Phone 构建我的应用程序,但代号一个构建服务器给我构建错误。这是错误日志: https://s3.amazonaws.com/codenameone-build-response/7e34c6a4-f939-4044-8ab3-afbad45e7447-1450100218601-error.txt
当我为 Android 构建它时,一切都很好。
当我从 NetBeans 运行我的应用程序时,一切似乎也都很好,尽管控制台显示以下红色句子:
编译强制遵守受支持的 API/功能,以实现最大的设备兼容性。这允许更小的代码大小和更广泛的设备支持
注意:C:\Users\Andrius\Documents\NetBeansProjects\dogspuppiesforsaleApp\src\userclasses\StateMachine.java 使用或覆盖已弃用的 API。 注意:使用 -Xlint:deprecation 重新编译以了解详细信息。 注意:C:\Users\Andrius\Documents\NetBeansProjects\dogspuppiesforsaleApp\src\userclasses\StateMachine.java 使用未经检查或不安全的操作。 注意:使用 -Xlint 重新编译:未选中详细信息。
注意:C:\Users\Andrius\Documents\NetBeansProjects\dogspuppiesforsaleApp\src\userclasses\StateMachine.java 使用或覆盖已弃用的 API。 注意:使用 -Xlint:deprecation 重新编译以了解详细信息。 注意:C:\Users\Andrius\Documents\NetBeansProjects\dogspuppiesforsaleApp\src\userclasses\StateMachine.java 使用未经检查或不安全的操作。 注意:使用 -Xlint 重新编译:未选中详细信息。
2015 年 14 月 3:44:25 PM java.util.prefs.WindowsPreferences 警告:无法在根 0x80000002 处打开/创建首选项根节点 Software\JavaSoft\Prefs。 Windows RegCreateKeyEx(...) 返回错误代码 5。
一位代号管理员告诉我,Windows Phone 的 3d 数组存在问题。我在我的应用程序中使用 JSON 数据,所以问题可能就在这里?
protected void setCategories() {
JParser parser = new JParser("http://www.url.com/mobileApp/categories.php");
this.resultArray = parser.returnArray();
for (int i = 0; i < this.resultArray.length(); i++) {
try {
JSONObject jsonObject = this.resultArray.getJSONObject(i);
categories.add(new Category(jsonObject.getInt("id"), jsonObject.getString("title")));
} catch (JSONException ex) {
Dialog.show("Error", ex.toString(), "Ok", null);
}
}
}
JParser 类:
public class JParser {
public ConnectionRequest r;
public JSONArray jsonArray;
public String url;
public JParser(String url) {
this.jsonArray = new JSONArray();
this.url = url;
this.r = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
Hashtable h = p.parse(new InputStreamReader(input));
try {
String hashString = h.toString();
JSONObject entries = new JSONObject(hashString);
JSONArray rez = new JSONArray();
rez = entries.getJSONArray("root"); //musu JSON objektas visada prasides su root
setArray(rez);
} catch (JSONException ex) {
System.out.println(ex);
Dialog.show("Error", ex.toString(), "Ok", null);
}
}
};
this.r.setUrl(this.url);
this.r.setPost(false); //nieko nepostinam, tik pasiimam parsinti
InfiniteProgress prog = new InfiniteProgress(); //nesibaigiantis procesas
Dialog dlg = prog.showInifiniteBlocking(); //rodom dialoga su loading
this.r.setDisposeOnCompletion(dlg); //kai baigia krauti, isjungiam
NetworkManager.getInstance().addToQueueAndWait(this.r); //pridedam i eile
this.r.getResponseData(); //gaunam duomenis
}
public void setArray(JSONArray a) {
this.jsonArray = a;
}
public JSONArray returnArray() {
return this.jsonArray;
}
}
最佳答案
我无法真正判断您的错误来自何处,但您可以重写代码以在 readResponse()
中读取响应,在 postResponse()
中处理 json 响应,并且没有 JsonArray(),请尝试以下:
public class JParser {
public ConnectionRequest r;
public String url;
public JParser(String url) {
this.url = url;
InfiniteProgress prog = new InfiniteProgress();
Dialog dlg = prog.showInifiniteBlocking();
try {
this.r = new ConnectionRequest() {
Map response = null;
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser parser = new JSONParser();
response = parser.parseJSON(new InputStreamReader(input));
}
@Override
protected void postResponse() {
List responseList = (List) response.get("root");
if (responseList != null) {
// save or use your response as a list here, for exampple:
System.out.println(responseList.toString()); // output for debug
// Or even loop through the result:
for (Object resList : responseList) {
Map tempHash = (Map) resList;
String result = tempHash.get("anElementInsideRoot").toString();
System.out.println(result);
}
} else {
//It returns null value
}
}
};
this.r.setUrl(this.url);
this.r.setPost(false);
NetworkManager.getInstance().addToQueueAndWait(this.r);
} catch (Exception ex) {
System.out.println(ex.getMessage());
Dialog.show("Error", ex.getMessage(), "Ok", null);
} finally {
dlg.dispose();
}
}
}
同时删除不需要的 this.r.getResponseData();
。
关于java - 代号一个应用程序不适合 Windows 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34268727/