Reputation: 897
I am trying to delete a blob and container from my azure mobile services storage and I keep getting an exception from the calls. My upload, geturi, download, getcontainers, etc. all work but neither delete blob or delete container work. I keep getting an exception. For the delete container I get:
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)
and for the delete blob I get:
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)
My code for the two calls are as follows:
DeleteContainer:
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();
}
});
}
DeleteBlob:
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);
}
});
}
Any help with this would be greatly appreciated.
Upvotes: 0
Views: 484
Reputation: 87228
The exception happens in the onCompleted
method, and the only way I can see of a null pointer exception happening is if the exception.getCause()
call returns null. Try rewriting your methods as follows:
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;
}
Upvotes: 2