Attempt to invoke interface method 'java.lang.String.facebook.react.bridge.readablemap.getstring(java.lang.string) on a null object reference
Opened this issue · 8 comments
export function createUser (user, callback) {
const fs = RNFetchBlob.fs
const Blob = RNFetchBlob.polyfill.Blob
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
window.Blob = Blob
const mime = 'application/octet-stream';
const sessionId = new Date().getTime();
let image = user.image;
let rnfbURI = RNFetchBlob.wrap(image);
const imageRef = storage
.ref('images')
.child(user.uid);
// create Blob from file path
fs.readFile(image, 'base64')
.then((data) => {
return Blob.build(data, { type: `${mime};BASE64` })
})
.then((blob) => {
// upload image using Firebase SDK
return imageRef
.put(blob, { contentType : mime })
})
.then((blob) => {
imageRef.getDownloadURL().then(function(url) {
user.image = url
database.ref('users').child(user.uid).update({ ...user })
.then(() => callback(true, null, null))
.catch((error) => callback(false, null, {message: error}));
})
})
}
help, i can't find the null things.
@aloptrbl have you find any solution? i'm having this same issue.
@aloptrbl I am not a maintainer for this project, I only made a PR to fix an iOS bug that was relevant to my work. But inferring from the title of this post, I would guess the null ref you're looking for is in the java source, probably in the key-val object (a readablemap probably?) used to construct the callback parameters for the javascript you are invoking. You're going to need to debug the java code you're ultimately calling to find the source of the error, as it is not likely to be on the javascript side.
Hey plz help me. I'm also getting the same error. my code is given below.
uploadImage(uri, mime = "application/octet-stream") {
return new Promise((resolve, reject) => {
const uploadUri =
Platform.OS === "ios" ? uri.replace("file://", "") : uri;
let uploadBlob = null;
const imageRef = db
.storage()
.ref("images")
.child("image_001");
fs.readFile(uploadUri, "base64")
.then(data => {
return Blob.build(data, { type: `${mime};BASE64` });
})
.then(blob => {
uploadBlob = blob;
return imageRef.put(blob, { contentType: mime });
})
.then(() => {
uploadBlob.close();
return imageRef.getDownloadURL();
})
.then(url => {
resolve(url);
})
.catch(error => {
reject(error);
});
});
}
getImage() {
ImagePicker.showImagePicker(options, response => {
console.log("Response = ", response);
if (response.didCancel) {
console.log("User cancelled image picker");
} else if (response.error) {
console.log("ImagePicker Error: ", response.error);
} else if (response.customButton) {
console.log("User tapped custom button: ", response.customButton);
} else {
// let source = { uri: response.uri };
// this.setState({image_uri: response.uri})
// You can also display the image using data:
// let image_uri = { uri: 'data:image/jpeg;base64,' + response.data };
this.uploadImage(response.uri)
.then(url => {
alert("uploaded");
// let dbCon = db.database().ref("/test");
// let orderID = this.state.basicInfo.orderID;
// let orderID = this.state.order.orderID;
// dbCon.push({ image_uri: url });
this.setState({ image_uri: url });
})
.catch(error => console.log(error));
}
});
}
thanks in advance
+1 I'm getting the same error. I've also seen several posts on stackOverflow reference the same library and code.
This seems to occur for me when RNFetchBlob gets used in the background instead of the built-in whatwg-fetch fetch.
I have encountered this issue took me awhile to solve it. I used an npm library called React Native Restart (you can find it here: https://github.com/avishayil/react-native-restart) right after the image is uploaded to firebase to just restart the whole app before the error came, and so far I had no issues with it. Also set a timer before you execute the restart, as it might skip some code and go straight to it.