我正在尝试使用Google Nexus 5在我的离子应用程序中添加我的图片库中的图像,但我一直在运行相同的错误消息
W/System.err( 2544): java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
W/System.err( 2544): at org.apache.cordova.file.ContentFilesystem.getFileMetadataForLocalURL(ContentFilesystem.java:130)
W/System.err( 2544): at org.apache.cordova.file.Filesystem.exists(Filesystem.java:130)
W/System.err( 2544): at org.apache.cordova.file.FileUtils.resolveLocalFileSystemURI(FileUtils.java:619)
W/System.err( 2544): at org.apache.cordova.file.FileUtils.access$400(FileUtils.java:51)
W/System.err( 2544): at org.apache.cordova.file.FileUtils$14.run(FileUtils.java:378)
W/System.err( 2544): at org.apache.cordova.file.FileUtils$25.run(FileUtils.java:561)
W/System.err( 2544): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err( 2544): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err( 2544): at java.lang.Thread.run(Thread.java:818)
我的angularjs代码
var options = {
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true
};
// 3
$cordovaCamera.getPicture(options).then(function(imageData) {
// 4
var imagetype;
onImageSuccess(imageData);
function onImageSuccess(fileURI) {
createFileEntry(fileURI);
}
function createFileEntry(fileURI) {
window.resolveLocalFileSystemURL(fileURI, copyFile, fail);
}
// 5
function copyFile(fileEntry) {
var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1);
var newName = (new Date()).getTime() + name;
halfthru(fileEntry, newName); //diff
getImageType(fileEntry); //diff
}
function getImageType(fileEntry) { //diff
var typeImage;
$scope.$evalAsync(function() {
fileEntry.file(function(file){
typeImage= file.type;
$scope.imagelist = typeImage;
imagetype = typeImage;
}, function(e){
});
})
}
function halfthru(fileEntry, newName) {
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) {
fileEntry.copyTo(
fileSystem2,
newName,
onCopySuccess,
fail
);
}, fail);
}
// 6
function onCopySuccess(entry) {
$scope.activeSlide = index;
if(modalExists === false) {
$ionicModal.fromTemplateUrl('image-modal.html', {
scope: $scope,
}).then(function(modal) {
$scope.modal1 = modal;
$scope.modal1.show();
modalExists = true;
$scope.$evalAsync($scope.images.push({file: entry.nativeURL, type: $scope.imagelist}));
imagesModalCount = $scope.images.length;
attachedImageCount = $scope.imagesAttached.length;
});
}
else {
$scope.modal1.show();
$scope.$evalAsync($scope.images.push({file: entry.nativeURL, type: $scope.imagelist}));
imagesModalCount = $scope.images.length;
attachedImageCount = $scope.imagesAttached.length;
}
$scope.$on('$destroy', function() {
$scope.modal1.remove();
});
}
function fail(error) {
}
}, function(err) {
});
我知道这个问题与cordova插件文件和一些android 5问题有关但是如何解决这个问题?
答案 0 :(得分:0)
切换到NativeURL似乎可以解决问题