我正在开发一个代号为1的项目,该项目要求我录制用户语音并将其发送到服务器,该记录工作得很好,但是我什么时候将它发送到服务器它给出了一个错误。有没有人有解决它给出的错误。这是进行录制的代码。
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);
}
这是我在运行时得到的错误...
java.lang.NUllPointerException: for URL https://theURL null.
可能是什么原因,有什么我不对的。
答案 0 :(得分:0)
感谢Shai问题来自服务器,该文件已成功发送到服务器,但错误来自响应,因为我无法从模拟器测试它,因为Media无法在模拟器中工作我无法看到堆栈跟踪。已经修好了。