Пользователь выбирает изображения из галереи и те выбранные изображения, которые я загружаю на хранение в окнах azure blob. Но при загрузке я получаю исключение нулевого указателя.nullpointerexception при загрузке изображений в хранилище azure blob в android
Я не нашел никаких проблем в Интернете. Выбранный 'ArrayList<String>
' состоит из путей выбранных изображений. Пути отображаются в этом формате в LogCat: mnt/sdcard/Pictures/image1.jpg
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
selected = new ArrayList<String>();
try {
// Retrieve storage account from connection-string.
storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container.
// The container name must be lower case
blobContainer = blobClient.getContainerReference("mycontainer");
// Create the container if it does not exist.
// Create a blob container using the createIfNotExist method that
// checks whether a container exists with the same name. The method
// creates the blob container only if a container with the same name
// does not exist. Otherwise, no operation is performed.
blobContainer.createIfNotExists();
// Create a permissions object.
containerPermissions = new BlobContainerPermissions();
// Include public access in the permissions object.
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
// Set the permissions on the container.
blobContainer.uploadPermissions(containerPermissions);
} catch (InvalidKeyException e1) {
e1.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
public void onCreateOptionsMenu(Menu menu,MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
// Inflate the menu items for use in the action bar
inflater.inflate(R.menu.mymenu, menu);
// Here we get the action view we defined
myActionMenuItem = menu.findItem(R.id.my_action);
View actionView = myActionMenuItem.getActionView();
// We then get the button view that is part of the action view
if(actionView != null) {
myActionButton = (Button) actionView.findViewById(R.id.action_btn);
myActionButton.setText(R.string.txt_submit);
if(myActionButton != null) {
// We set a listener that will be called when the return/enter key is pressed
myActionButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
myActionButton.setEnabled(false);
myActionButton.setText("Submitting..");
try {
for(int i = 0; i <selected.size();i++){
String filePath = selected.get(i).sdcardPath;
File source = new File(filePath);
String absoluteFilePath = source.getAbsolutePath();
Log.d("personal", absoluteFilePath);
CloudBlockBlob blob = blobContainer.getBlockBlobReference(source.getName());
Log.d("personal", source.getName());
//Log.d("personal", imageName.get(i));
blob.upload(new FileInputStream(absoluteFilePath), source.length());
//blob.uploadFromFile(filePath);
Log.d("personal", "Image Uploaded");
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}
StackTrace:
10-09 15:50:27.168: W/System.err(1451): java.lang.NullPointerException
10-09 15:50:27.168: W/System.err(1451): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:784)
10-09 15:50:27.168: W/System.err(1451): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
10-09 15:50:27.168: W/System.err(1451): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
10-09 15:50:27.178: W/System.err(1451): at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:145)
10-09 15:50:27.178: W/System.err(1451): at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:252)
10-09 15:50:27.178: W/System.err(1451): at com.microsoft.azure.storage.blob.CloudBlockBlob.commitBlockList(CloudBlockBlob.java:242)
10-09 15:50:27.178: W/System.err(1451): at com.microsoft.azure.storage.blob.BlobOutputStream.commit(BlobOutputStream.java:321)
10-09 15:50:27.178: W/System.err(1451): at com.microsoft.azure.storage.blob.BlobOutputStream.close(BlobOutputStream.java:285)
10-09 15:50:27.178: W/System.err(1451): at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:582)
10-09 15:50:27.199: W/System.err(1451): at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:499)
10-09 15:50:27.199: W/System.err(1451): at com.jbandroid.fragment.PersonalInfoFragment$2.onCompleted(PersonalInfoFragment.java:273)
10-09 15:50:27.199: W/System.err(1451): at com.jbandroid.fragment.PersonalInfoFragment$2.onCompleted(PersonalInfoFragment.java:1)
10-09 15:50:27.199: W/System.err(1451): at com.microsoft.windowsazure.mobileservices.MobileServiceTable$ParseResultOperationCallback.onCompleted(MobileServiceTable.java:103)
10-09 15:50:27.199: W/System.err(1451): at com.microsoft.windowsazure.mobileservices.MobileServiceJsonTable$2.onCompleted(MobileServiceJsonTable.java:249)
10-09 15:50:27.199: W/System.err(1451): at com.microsoft.windowsazure.mobileservices.MobileServiceJsonTable$4.onPostExecute(MobileServiceJsonTable.java:389)
10-09 15:50:27.199: W/System.err(1451): at com.microsoft.windowsazure.mobileservices.MobileServiceJsonTable$4.onPostExecute(MobileServiceJsonTable.java:1)
10-09 15:50:27.199: W/System.err(1451): at android.os.AsyncTask.finish(AsyncTask.java:602)
10-09 15:50:27.199: W/System.err(1451): at android.os.AsyncTask.access$600(AsyncTask.java:156)
10-09 15:50:27.199: W/System.err(1451): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
10-09 15:50:27.199: W/System.err(1451): at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 15:50:27.208: W/System.err(1451): at android.os.Looper.loop(Looper.java:137)
10-09 15:50:27.208: W/System.err(1451): at android.app.ActivityThread.main(ActivityThread.java:4340)
10-09 15:50:27.208: W/System.err(1451): at java.lang.reflect.Method.invokeNative(Native Method)
10-09 15:50:27.208: W/System.err(1451): at java.lang.reflect.Method.invoke(Method.java:511)
10-09 15:50:27.208: W/System.err(1451): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-09 15:50:27.208: W/System.err(1451): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-09 15:50:27.208: W/System.err(1451): at dalvik.system.NativeStart.main(Native Method)
Спасибо ... это сработало для меня .. –
@ pooh1527 Мы выпустили новую версию лазурной библиотеки (0.3.1) специально для решения этой проблемы. Вы можете получить код здесь. Теперь вы должны получить правильное сообщение об ошибке. –
Благодарим за обновление .. Обновит мои библиотеки как можно скорее .. –