java - container.createIfNotExists() 上出现空对象引用错误;

标签 java azure-blob-storage

我正在尝试通过以下链接将 Azure Blob 存储用于 Android 应用程序: http://azure.microsoft.com/en-in/documentation/articles/storage-java-how-to-use-blob-storage/

我正在使用 Android Studio

我一切顺利,直到我在行中遇到异常:

container.createIfNotExists();

这一行给出了错误:

Attempt to invoke interface method 'void com.android.okhttp.internal.http.Transport.writeRequestHeaders(com.android.okhttp.Request)' on a null object reference

以下是我的导入:

import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.blob.*;

java代码:

try{
            System.out.print("Code Progess 2 ");
            CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
            System.out.print("Code Progess 3 ");
            CloudBlobClient serviceClient = account.createCloudBlobClient();
            System.out.print("Code Progess 4 ");

            // Container name must be lower case.
            CloudBlobContainer container = serviceClient.getContainerReference("myimages");
            System.out.print("Code Progess 5 ");
            container.createIfNotExists();
            System.out.print("Code Progess 6 ");

            // Upload an image file.
            CloudBlockBlob blob = container.getBlockBlobReference("image1.jpg");
            System.out.print("Code Progess 7 ");
            File sourceFile = new File("<Path to local image storage>");
            System.out.print("Code Progess 8 ");
            blob.upload(new FileInputStream(sourceFile), sourceFile.length());
            System.out.print("Code Progess 9 ");

            // Download the image file.
            File destinationFile = new File(sourceFile.getParentFile(), "image1Download.tmp");
            System.out.print("Code Progess 10 ");
            blob.downloadToFile(destinationFile.getAbsolutePath());
            System.out.print("Code Progess 11 ");
        }

catch (Exception e) {
            System.out.print("Exception encountered: ");
            System.out.println(e.getMessage());
            System.exit(-1);
        }

logcat如下:

01-09 20:54:02.072    2271-2287/com.rollcall.blob W/art﹕ Verification of void com.microsoft.azure.storage.blob.CloudBlobContainer.create(com.microsoft.azure.storage.blob.BlobRequestOptions, com.microsoft.azure.storage.OperationContext) took 334.218ms
01-09 20:54:02.140    2271-2287/com.rollcall.blob W/art﹕ Unresolved exception class when finding catch block: javax.xml.stream.XMLStreamException
01-09 20:54:02.141    2271-2287/com.rollcall.blob I/System.out﹕ Code Progess 1 Code Progess 2 Code Progess 3 Code Progess 4 Code Progess 5 Exception encountered: Attempt to invoke interface method 'void com.android.okhttp.internal.http.Transport.writeRequestHeaders(com.android.okhttp.Request)' on a null object reference

谁能告诉我哪里出错了?

谢谢

最佳答案

您引用的入门指南是专门针对 Java 的。您的示例是否使用 Java 或 Android Azure 存储客户端库?您应该使用一个单独的 Android Azure 存储客户端库来构建 Android 应用程序。

您可以查看readme document在 Github 存储库上开始。有关使用 blob 的示例代码也可以在存储库 here 中找到。

关于java - container.createIfNotExists() 上出现空对象引用错误;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27864612/

相关文章:

java - 可以看到用java发送一个数据包花了多长时间

java - 导出 Runnable jar 会丢失目录结构

java - 两个 Spring WebFlow 项目共享数据的最佳方式

python - Azure Blob 查询文档

JavaScript Azure Blob 存储移动 Blob

java - JSOUP - 从先前抓取的页面上找到的 URL 抓取图像和文本

java - 如何防止 Spring Tool Suite maven JVM 进程将 java 图标放置在 Mac 的 Dock 上?

ios - Azure Blob 授权 header

azure - 如何使用逻辑应用标准获取 blob URL

azure - 我们可以像文件共享一样在 Azure Blob 存储中上传包含文件的文件夹吗?