android - Uploading image to Firebase: Null pointer Exception(bitmap.compress) -


since firebase documentation not begginers, can hard , complex beginners.

i want upload image storage of firebase. read documentation , tried gives nullpointerexception.

i think null pointer exception imageview. there abc.jpg image in drawable folder.

there no maintains.jpg file on firebase side. should there maintains.jpg file on firebase? couldn't understand here

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/activity_main"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="gc.imageuploader.mainactivity">       <imageview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/imageview"         android:layout_gravity="center_horizontal"         android:src="@drawable/abc"/>  </linearlayout> 

main activity:

public class mainactivity extends appcompatactivity {      private static final string tag = mainactivity.class.getsimplename();       imageview imageview;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          firebasestorage storage = firebasestorage.getinstance();          // create storage reference our app         storagereference storageref = storage.getreferencefromurl("(mybucketnamehere)");          storagereference mountainsref = storageref.child("mountains.jpg");          imageview = (imageview)findviewbyid(r.id.imageview);             imageview.setdrawingcacheenabled(true);         imageview.builddrawingcache();         bitmap bitmap = imageview.getdrawingcache();         bytearrayoutputstream baos = new bytearrayoutputstream();         bitmap.compress(bitmap.compressformat.jpeg, 100, baos);//error line         byte[] data = baos.tobytearray();          uploadtask uploadtask = mountainsref.putbytes(data);         uploadtask.addonfailurelistener(new onfailurelistener() {             @override             public void onfailure(@nonnull exception exception) {                 // handle unsuccessful uploads             }         }).addonsuccesslistener(new onsuccesslistener<uploadtask.tasksnapshot>() {             @override             public void onsuccess(uploadtask.tasksnapshot tasksnapshot) {                 // tasksnapshot.getmetadata() contains file metadata such size, content-type, , download url.                 uri downloadurl = tasksnapshot.getdownloadurl();             }         }); } 

finally, how solve?


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -