我正在尝试从我的 azure 移动服务存储中删除 blob 和容器,但我不断收到调用异常。我的上传、geturi、下载、getcontainers 等都可以工作,但删除 blob 或删除容器都不起作用。我不断遇到异常(exception)。对于删除容器,我得到:
Process: com.w9jds.myglassshare, PID: 504
java.lang.NullPointerException
at com.w9jds.myglassshare.Classes.StorageService$2.onCompleted(StorageService.java:117)
at com.microsoft.windowsazure.mobileservices.MobileServiceTableBase.delete(MobileServiceTableBase.java:218)
at com.microsoft.windowsazure.mobileservices.MobileServiceJsonTable.delete(MobileServiceJsonTable.java:1)
at com.w9jds.myglassshare.Classes.StorageService.deleteContainer(StorageService.java:110)
at com.w9jds.myglassshare.MainActivity$2.onClick(MainActivity.java:116)
at android.view.View.performClick(View.java:4442)
at android.view.View$PerformClick.run(View.java:18423)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5083)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)
对于删除 blob,我得到:
01-01 23:00:47.561 1457-1457/com.w9jds.myglassshare E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.w9jds.myglassshare, PID: 1457
java.lang.RuntimeException: Error receiving broadcast Intent { act=blob.delete flg=0x10 } in com.w9jds.myglassshare.MainActivity$3@41f34b50
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5083)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.w9jds.myglassshare.Classes.StorageService$4.onCompleted(StorageService.java:198)
at com.microsoft.windowsazure.mobileservices.MobileServiceTableBase.delete(MobileServiceTableBase.java:218)
at com.microsoft.windowsazure.mobileservices.MobileServiceJsonTable.delete(MobileServiceJsonTable.java:1)
at com.w9jds.myglassshare.Classes.StorageService.deleteBlob(StorageService.java:191)
at com.w9jds.myglassshare.MainActivity$3.onReceive(MainActivity.java:187)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5083)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)
我的两个调用的代码如下:
删除容器:
public void deleteContainer(String containerName)
{
//Create the json Object we'll send over and fill it with the required
//id property - otherwise we'll get kicked back
JsonObject container = new JsonObject();
container.addProperty("id", 0);
//Create parameters to pass in the container details. We do this with params
//because it would be stripped out if we put it on the container object
List<Pair<String,String>> parameters = new ArrayList<Pair<String, String>>();
parameters.add(new Pair<String, String>("containerName", containerName));
mTableContainers.delete(container, parameters, new TableDeleteCallback()
{
@Override
public void onCompleted(Exception exception, ServiceFilterResponse response)
{
if (exception != null)
{
Log.e(TAG, exception.getCause().getMessage());
return;
}
//Refetch containers from the server
//Intent broadcast = new Intent();
//broadcast.setAction("blob.deleted");
//mContext.sendBroadcast(broadcast);
getContainers();
}
});
}
删除Blob:
public void deleteBlob(final String containerName, String blobName)
{
//Create the json Object we'll send over and fill it with the required
//id property - otherwise we'll get kicked back
JsonObject blob = new JsonObject();
blob.addProperty("id", 0);
//Create parameters to pass in the blob details. We do this with params
//because it would be stripped out if we put it on the blob object
List<Pair<String,String>> parameters = new ArrayList<Pair<String, String>>();
parameters.add(new Pair<String, String>("containerName", containerName));
parameters.add(new Pair<String, String>("blobName", blobName));
mTableBlobs.delete(blob, parameters, new TableDeleteCallback()
{
@Override
public void onCompleted(Exception exception, ServiceFilterResponse response)
{
if (exception != null)
{
Log.e(TAG, exception.getCause().getMessage());
return;
}
//Refetch the blobs from the server
//getBlobsForContainer(containerName);
}
});
}
任何有关此问题的帮助将不胜感激。
最佳答案
异常发生在 onCompleted
方法中,我可以看到发生空指针异常的唯一方法是 exception.getCause()
调用返回 null。尝试按如下方式重写您的方法:
public void onCompleted(Exception exception, ServiceFilterResponse response)
{
if (exception != null)
{
Log.e(TAG, exception.getMessage();
Throwable t = e.getCause();
while (t != null)
{
Log.e(TAG, " Cause: " + t.getMessage());
t = t.getCause();
}
return;
}
关于Android 使用 Azure 移动服务删除 Null 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20876690/