Azure / azure-storage-android

Microsoft Azure Storage Library for Android
Apache License 2.0
81 stars 47 forks source link

container.CreateIfNotExists() throws NullReferenceException #13

Closed ketansciter closed 9 years ago

ketansciter commented 9 years ago

Hi,

Downloaded latest code. Trying to run sample with my Azure account and getting following error.

Caused by: java.lang.NullPointerException at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:632) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:136) at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:76) at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:267) at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:747) at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:358) at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:334) at com.azures.AzureActivity$AzureCreateTask.doInBackground(AzureActivity.java:41) at com.azures.AzureActivity$AzureCreateTask.doInBackground(AzureActivity.java:33)

emgerner-msft commented 9 years ago

I haven't seen this before -- it's pretty odd since the NullPointer is inside the HttpURLConnection code. Could you give more information about your application setup (Android target version, etc) and where in the sample this is throwing?

ketansciter commented 9 years ago

Hi,

\ Error Log Updated

Supported Version(s): 4.3 + Tested Version: 5.0.1, 4.4.4

import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import com.microsoft.azure.storage.CloudStorageAccount; import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.blob.CloudBlobClient; import com.microsoft.azure.storage.blob.CloudBlobContainer; import com.microsoft.azure.storage.blob.CloudBlockBlob; import java.net.URISyntaxException; import java.security.InvalidKeyException;

public class AzureActivity extends Activity {

private static final String CONNECTION = "DefaultEndpointsProtocol=https;"
    + "AccountName=[MY_ACCOUNT];"
    + "AccountKey=[MY_KEY]";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

public void getInformation(View view) {
    new AzureCreateTask().execute();
}

private class AzureCreateTask extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(final Void... params) {
        try {
            CloudStorageAccount account = CloudStorageAccount.parse(CONNECTION);
            CloudBlobClient blobClient = account.createCloudBlobClient();
            CloudBlobContainer container = blobClient.getContainerReference("development");
            container.createIfNotExists();
        } catch(URISyntaxException | InvalidKeyException | StorageException e) {
            AzureStorageAccess.printDebugLog(5, e.toString());
        }
        return null;
    }
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    finish();
}

}

emgerner-msft commented 9 years ago

I just ran your code on both a 4.x and 5.x device. I was not able to reproduce the issue on either. My guess from a little searching and general Android experience would be that you're having an internet issue. Check some of the following:

  1. You have an active internet connection.
  2. Your account name is correct. If not, you will be accessing the wrong URL.
  3. Your manifest has internet permissions.
ketansciter commented 9 years ago

Hi,

I am having all permissions in manifest with correct account name. Issue was different. Solved. Thanks.