2021年1月18日星期一

Rest API throws JSON parsing error: Exception during JSON parsing at row: 1 column: 1 buffer

I am using Rest API and when I use Rest.put(), it throws an error. It does not even reach the server at all. I don't know where I am going wrong. Here is my code:

Response<String> res = Rest.put(URLLinks.getMainBackend() + "items")                          .body(reqJson.toString())                          .jsonContent()                          .bearer(initForm.data.getString("jwt"))                          .header("token", initForm.data.getString("token"))                          .pathParam("id", item.getId())                          .onErrorCodeJSON((errorData) -> {                              if (errorData.getResponseCode() == 404) {                                  Dialog dlg = rich.Dialog("Not found!");                                    Button yes = new Button("Close");                                  yes.addActionListener(ev -> {                                      dlg.dispose();                                  });                                    dlg.add(new SpanLabel("//////!"));                                  dlg.add(FlowLayout.encloseRight(yes));                                  dlg.showPacked(BorderLayout.CENTER, true);                              }else if (errorData.getResponseCode() == 402){                                                               }                          })                          .getAsString();  

It throws an error:

java.io.IOException: Stream closed  [Network Thread] 0:0:12,855 - Codename One revisions: 4afb54f6a5cecd2b6fbee170262d5c3c8d9431f9    [Network Thread] 0:0:12,855 - Exception: java.io.IOException - Stream closed  [Network Thread] 0:0:12,858 - Exception during JSON parsing at row: 1 column: 1 buffer:   [EDT] 0:0:12,874 - Exception: java.lang.NullPointerException - null      at com.codename1.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:140)      at com.codename1.io.BufferedInputStream.read1(BufferedInputStream.java:338)      at com.codename1.io.BufferedInputStream.read(BufferedInputStream.java:445)      at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)      at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)      at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)      at java.base/java.io.InputStreamReader.read(InputStreamReader.java:185)      at com.codename1.io.JSONParser$ReaderClass.read(JSONParser.java:124)      at com.codename1.io.JSONParser.parse(JSONParser.java:188)      at com.codename1.io.JSONParser.parseJSON(JSONParser.java:475)      at com.codename1.io.rest.RequestBuilder$Connection.readUnzipedResponse(RequestBuilder.java:683)      at com.codename1.io.gzip.GZConnectionRequest.readResponse(GZConnectionRequest.java:67)      at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:809)      at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)      at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)  java.lang.NullPointerException      at java.base/java.lang.String.<init>(String.java:537)      at com.codename1.io.rest.RequestBuilder.getAsString(RequestBuilder.java:361)      at com.falcontechnology.items.NewItem.backendItem(NewItem.java:425)      at com.falcontechnology.items.NewItem.lambda$itemFields$7(NewItem.java:296)      at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)      at com.codename1.ui.Button.fireActionEvent(Button.java:570)      at com.codename1.ui.Button.released(Button.java:604)      at com.codename1.ui.Button.pointerReleased(Button.java:708)      at com.codename1.ui.Form.pointerReleased(Form.java:3356)      at com.codename1.ui.Component.pointerReleased(Component.java:4552)      at com.codename1.ui.Display.handleEvent(Display.java:2080)      at com.codename1.ui.Display.edtLoopImpl(Display.java:1052)      at com.codename1.ui.Display.mainEDTLoop(Display.java:970)      at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)      at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)  

The null pointer on line NewItem.java:425 points at the line where there is .getAsString(). What could i be doing wrong?

EDIT

I have updated my project libraries which solved the null pointer exception on .getAsString() but it still leaves another error which is:

    java.io.IOException: Stream closed  [Network Thread] 0:0:54,316 - Exception: java.io.IOException - Stream closed  [Network Thread] 0:0:54,344 - Exception during JSON parsing at row: 1 column: 1 buffer:       at com.codename1.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:140)      at com.codename1.io.BufferedInputStream.read1(BufferedInputStream.java:338)      at com.codename1.io.BufferedInputStream.read(BufferedInputStream.java:445)      at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)      at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)      at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)      at java.base/java.io.InputStreamReader.read(InputStreamReader.java:185)      at com.codename1.io.JSONParser$ReaderClass.read(JSONParser.java:191)      at com.codename1.io.JSONParser.parse(JSONParser.java:278)      at com.codename1.io.JSONParser.parseJSON(JSONParser.java:568)      at com.codename1.io.rest.RequestBuilder$Connection.readUnzipedResponse(RequestBuilder.java:785)      at com.codename1.io.gzip.GZConnectionRequest.readResponse(GZConnectionRequest.java:67)      at com.codename1.io.ConnectionRequest.performOperationComplete(ConnectionRequest.java:1002)      at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:340)      at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)  
https://stackoverflow.com/questions/65780291/rest-api-throws-json-parsing-error-exception-during-json-parsing-at-row-1-colu January 19, 2021 at 02:41AM

没有评论:

发表评论