CodeNameOne使用StateMachine问题将图像上传到servlet

时间:2016-01-31 03:18:44

标签: java servlets codenameone

我一周前开始使用CodeNameOne,所以我非常认真地使用这些类型的框架,而且我试图使用demo UploadServlet将图像上传到servlet,我已经使用了PhotoShare演示虽然我发现很难上传我使用CodeNameOne GUI Designer和StateMachine类构建的应用程序。

任何人都可以指出我需要对这里的代码做些什么,如果我排队等待或者不等postResponse似乎立刻开火,那么这似乎并不重要。

提前致谢

错误:

Done probably too early
[EDT] 0:0:0,0 - Exception: java.lang.NullPointerException - null
java.lang.NullPointerException
    at userclasses.StateMachine$2.postResponse(StateMachine.java:756)
    at com.codename1.io.ConnectionRequest$1.run(ConnectionRequest.java:459)
    at com.codename1.ui.Display.processSerialCalls(Display.java:1149)
    at com.codename1.ui.Display.edtLoopImpl(Display.java:1093)
    at com.codename1.ui.Display.invokeAndBlock(Display.java:1203)
    at com.codename1.ui.Display.invokeAndBlock(Display.java:1241)
    at com.codename1.io.NetworkManager.addToQueueAndWait(NetworkManager.java:596)
    at userclasses.StateMachine.onRecordStyle_CaptureImagesAction(StateMachine.java:772)
    at generated.StateMachineBase.handleComponentAction(StateMachineBase.java:1478)
    at com.codename1.ui.util.UIBuilder$FormListener.actionPerformed(UIBuilder.java:2831)
    at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:345)
    at com.codename1.ui.Button.fireActionEvent(Button.java:397)
    at com.codename1.ui.Button.released(Button.java:428)

代码:

// Record Style Form - Capture Images Button -- WIP
@Override
protected void onRecordStyle_CaptureImagesAction(Component c, ActionEvent event) {

    // Clear out the existing imageList 
    //imageList = null;

    // Loop over the number of photos allowed for each record
    for (int i=0; i < maxImageUploads; i++) {

        // Capture and add
        String picture = Capture.capturePhoto(1024, -1);

        System.out.println(picture);

        if (picture != null) {

            MultipartRequest mp = new MultipartRequest() {
                private long key;

                @Override
                protected void readResponse(InputStream input) throws IOException {
                    DataInputStream di = new DataInputStream(input);
                    System.out.println("Done, probably too early!! :(");
                    key = di.readLong();
                }

                @Override
                protected void postResponse() {
                    imageList.addImageId(key);                    
                }

            };

            try {
                String uuid = WebServiceProxy.getUUID();
                mp.setUrl(apiURL + "/upload");
                mp.addData(uuid + ".jpg", picture, "image/jpeg");
                mp.addArgument("p", uuid + ":" + Preferences.get("clientUUID", "") + ":" + Preferences.get("companyUUID", ""));
                //mp.addArgument("UUID", uuid);
                //mp.addArgument("Client", Preferences.get("clientUUID", ""));
                //mp.addArgument("Company", Preferences.get("companyUUID", ""));
                InfiniteProgress prog = new InfiniteProgress();
                Dialog dlg = prog.showInifiniteBlocking();
                mp.setDisposeOnCompletion(dlg);
                NetworkManager.getInstance().addToQueueAndWait(mp);

                System.out.println("Added to queue");

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                   

        }
        // After capture ask to take another other than the last time
        if ( i < maxImageUploads - 1) {
            if (!Dialog.show("QR", "Capture image #" + (i + 2) + " ?" , "OK", "Finished")) {
                // Break out of loop if user decides 
                i = maxImageUploads;    
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您的imageList变量为空,您可以在postResponse中添加该变量。

从堆栈跟踪中可以清楚地看到它。

未来参考的FYI通常有助于从与堆栈跟踪中的行号匹配的代码中注释行号。例如。说出类似的话:

  

第756行是:

imageList.addImageId(key);