I have a popup window on my fragment,i want to take drawing cache of popup window. I have tried this (below) but i got null pointer exception.I could'nt find the reason.Can anyone help?
LayoutInflater inflater2 = (LayoutInflater) obj.getSystemService(LAYOUT_INFLATER_SERVICE);
View customView_2 = inflater2.inflate(R.layout.share_lc_card, null);
// results_page_ = (RelativeLayout) v.findViewById(R.id.fragment_results_layout);
card_main_layout = (RelativeLayout) customView_2.findViewById(R.id.card_main_layout);
card_main_layout.invalidate();
card_main_layout.requestLayout();
card_main_layout.setDrawingCacheEnabled(true);
card_main_layout.buildDrawingCache(true);
Bitmap drawingCache_bitmap_card = card_main_layout.getDrawingCache();
// Bitmap drawingCache_bitmap_card = Bitmap.createBitmap(card_main_layout.getDrawingCache());
card_main_layout.setDrawingCacheEnabled(false);
Log.e("gu", "hghh");
My popup window xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="300dp"
android:layout_height="450dp"
android:layout_margin="4dp"
android:padding="30dp"
card_view:cardCornerRadius="26dp"
card_view:cardElevation="10sp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="450dp">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/lc_background" />
<TextView
android:id="@+id/first_name_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginStart="80dp"
android:layout_marginTop="30dp"
android:text="@string/romeo" />
<TextView
android:id="@+id/and_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginStart="130dp"
android:layout_marginTop="30dp"
android:text="@string/and" />
<TextView
android:id="@+id/second_name_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="145dp"
android:layout_marginStart="145dp"
android:layout_marginTop="30dp"
android:text="@string/juliet" />
<ImageView
android:id="@+id/small_heart_image_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:layout_marginStart="90dp"
android:layout_marginTop="50dp"
android:src="@drawable/heart_share_card" />
<TextView
android:id="@+id/result_message"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="120dp"
android:gravity="center"
android:lineSpacingExtra="-2dp"
android:text="WOW ! MADE FOR EACH OTHER"
android:textSize="25dp" />
<ImageView
android:id="@+id/small_heart_image_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="100dp"
android:layout_marginLeft="90dp"
android:layout_marginStart="90dp"
android:src="@drawable/heart_share_card" />
<TextView
android:id="@+id/score_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"
android:layout_marginLeft="110dp"
android:layout_marginStart="110dp"
android:text="90/100" />
</RelativeLayout>
</android.support.v7.widget.CardView>
I got NPE on this line
Bitmap drawingCache_bitmap_card = Bitmap.createBitmap(card_main_layout.getDrawingCache());
exception
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object refe at android.graphics.Bitmap.createBitmap(Bitmap.java:737)
at tech.a.com.x.LC_Fragments.ResultsFragment$4.onClick(ResultsFragment.java:207)
at android.view.View.performClick(View.java:5184)
at android.view.View$PerformClick.run(View.java:20910)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)