1
votes

I am working on a project with codename one, the project requires me to record a user voice and send it to the server, the record is working quite well, but i when it is time to send it to the server it gives an error. Does anyone has a solution to the error it gives. This is the code that does the recording.

Media media;
    String p;
    private void doRecord()
    {
        // initites devices microphone and do the recording until it is stopped.
        try{
            p = getTempFileName();
            media = MediaManager.createMediaRecorder(p,MediaManager.getMediaRecorderingMimeType());
            media.play();
        }catch (IOException ex) {
            ex.printStackTrace();
        }
    }


private String getTempFileName() {
        String[] roots = FileSystemStorage.getInstance().getRoots();
        // iOS doesn't have an SD card
        String root = roots[0];
        for (int i = 0; i < roots.length; i++) {
            if (FileSystemStorage.getInstance().getRootType(roots[i]) == FileSystemStorage.ROOT_TYPE_SDCARD) {
                root = roots[i];
                break;
            }
        }
        return root + FileSystemStorage.getInstance().getFileSystemSeparator() + "audioSample" + System.currentTimeMillis();
    }

public void stopRecord(boolean timeElapsed) { media.pause(); media.cleanup();

    sendToNetwork(timeElapsed);
}

private com.codename1.io.MultipartRequest request;
public void sendToNetwork(boolean timeElapsed)
{
   request = new com.codename1.io.MultipartRequest(){
   //action performed when response is read goes here
}
request.setUrl("https://theURL");
        request.setPost(true);
        request.addArgument("int_id ",mock_session);
        request.addArgument("quesID",question_id);
        request.addArgument("mock_session",mock_session);
        request.addArgument("mock_email",mock_email);
        request.addArgument("fname","");


                    //add the data image
        request.addData("data", p,MediaManager.getMediaRecorderingMimeType());

        request.setPriority(ConnectionRequest.PRIORITY_CRITICAL);
        NetworkManager.getInstance().addToQueue(request);

}

This is the error i get when run it...

java.lang.NUllPointerException: for URL https://theURL null.

What could be the cause, is there something i am not getting right.

1
You need to include the stack trace of the exception - Shai Almog

1 Answers

0
votes

thanks Shai the problem was from the server, the file was sent to server successfully but the error was coming from the response as i couldn't test it from the emulator because of the Media which does not work in emulator i could not see the stack trace. Already fixed it.