Uploading Recorded File to server

31 views
Skip to first unread message

john david

unread,
Jul 28, 2014, 10:08:37 AM7/28/14
to codenameone...@googlegroups.com
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();
    }

ublic 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

Sadart Abukari

unread,
Jul 28, 2014, 11:26:07 AM7/28/14
to codenameone...@googlegroups.com
Is https://theURL just a placeholder for your post? If so then a variable somewhere used in theURL has not been initialized.
Anyway I have seen this bug too which might crop up after theURL issue is solved. I got haunted by it so I noted it down.
                // Strict Note on this addData comes before setFilename and they should have the same key
        request.addData("data", p,MediaManager.getMediaRecorderingMimeType());
must be followed by
        request.setFilename("data", yourfilename);

Shai Almog

unread,
Jul 28, 2014, 11:32:05 AM7/28/14
to codenameone...@googlegroups.com
What's the stack on the null pointer exception, it will point you to the exact line that fails.
Reply all
Reply to author
Forward
0 new messages