android - Opening a screenshot image in another activity -


i created application take screen shot of current screen , open image in new activity. reason application crashes when want open new activity view picture. here's code:

public static bitmap getscreenshot(view view) {     view screenview = view.getrootview();     screenview.setdrawingcacheenabled(true);     bitmap bitmap = bitmap.createbitmap(screenview.getdrawingcache());     screenview.setdrawingcacheenabled(false);     return bitmap; } 

this onsave method gets image , meant set , display image in activity:

 public void onsave(view view){    bitmap bm = getscreenshot(view);      imageview view= (imageview) findviewbyid(r.id.newview);     view.setimagebitmap(bm);     intent saveintent = new intent(this, savepicture.class);    startactivity(saveintent);  }   

this saveintent activity xml code:

 <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">  <imageview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centervertical="true"     android:layout_centerhorizontal="true"     android:id="@+id/saveview"     android:contentdescription=""     tools:ignore="contentdescription" /> </relativelayout> 

and manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.krypttech.gallery"> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage"/>  <application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:supportsrtl="true"     android:theme="@style/apptheme">     <activity android:name=".mainactivity">         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <activity android:name=".savepicture">      </activity> </application>  </manifest> 

it seems, code crashes

  imageview view= (imageview) findviewbyid(r.id.newview);     view.setimagebitmap(bm); 

reason: view null.

comment

previously said application may crash due bm null. @greenapps in comments said wrong. that's why i've changed post , removed 'possible' choice.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -