Error calling RCTDeviceEventEmitter.emit failed to create value from json
Closed this issue · 3 comments
NarendraSingh88 commented
Here is my file downloading code as below -
async downloadFile(fileURL) {
const timeout = new Promise((resolve, reject) => {
setTimeout(reject, 5000, "Request timed out");
});
**_const request = fetch(fileURL);_**
return Promise.race([timeout, request])
.then(response => {
// alert(JSON.stringify(response, null, 4));
if (response.status !== 404) {
var filename = fileURL.substring(fileURL.lastIndexOf("/") + 1);
const { config, fs } = RNFetchBlob;
let DownloadDir = fs.dirs.DownloadDir;
let options = {
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true, // setting it to true will use the device's native download manager and will be shown in the notification bar.
notification: false,
path: DownloadDir + "/MyApp/" + filename, // this is the path where your downloaded file will live in
description: "Downloading Payslip."
}
};
RNFetchBlob.config(options)
.fetch("GET", fileURL, {})
.then(res => {
// the path should be dirs.DocumentDir + 'path-to-file.anything'
alert("The file saved to " + res.path());
})
.catch((errorMessage, statusCode) => {
// This is never hit for a server 404 error
console.log(errorMessage, statusCode);
Alert.alert(
"MyApp",
"Payslip not available.",
[{ text: "OK" }],
{ cancelable: true }
);
});
} else {
Alert.alert(
"MyApp",
"Payslip not available.",
[{ text: "OK" }],
{ cancelable: true }
);
}
})
.catch(error => {
Alert.alert(
"MyApp",
"Payslip not available.",
[{ text: "OK" }],
{
cancelable: true
}
);
});
return;
}
I am getting the above error on the highlighted line , i.e, as below
const request = fetch(fileURL);
The error, I am getting in log is as follow -
07-25 10:44:15.128 9695-9732/com.MyApp E/unknown:ReactNative: Exception in native call
java.lang.RuntimeException: Error calling RCTDeviceEventEmitter.emit
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.facebook.jni.CppException: Failed to create Value from JSON:
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)
I double-checked the url and it seems fine, and file is getting downloaded as well.
zolaahihi commented
ibrhmckc commented
i get this error only when i disable debug mode. There is no error on debug mode on android emulator . So i cannot find where is the error. somebody can help?
witalobenicio commented
@NarendraSingh88 how did you fixed it?
