Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:57:29+00:00 2026-06-12T16:57:29+00:00

I am getting the null pointer exception error while saving the layout : My

  • 0

I am getting the null pointer exception error while saving the layout :

My Code for creating the image is :

private void mSavePhoto()
            {
            String str=mGetTime1();
            str1="/"+str+".png";
            Log.e("str1", str1);
            mLinLayMain = (LinearLayout)findViewById(R.id.xLinLayMain);
            mLinLayMain.setDrawingCacheEnabled(true);
            mLinLayMain.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            mLinLayMain.layout(0, 0, mLinLayMain.getMeasuredWidth(), mLinLayMain.getMeasuredHeight()); 
            mLinLayMain.buildDrawingCache(true);

                    Bitmap mBitMap = Bitmap.createBitmap(mLinLayMain.getDrawingCache());
                     mBitMap=mLinLayMain.getDrawingCache();


             file = new File(Environment.getExternalStorageDirectory().getPath() + str1);
            try 
                {
                    file.createNewFile();
                    FileOutputStream ostream = new FileOutputStream(file);
                    mBitMap.compress(CompressFormat.PNG, 90, ostream);
                    ostream.close();
                    if(flag==1) // if Created image is to be saved in gallery
                        {
                            MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
                            flag=0;
                        }
                    else if(flag==2) // if created image is to be sent as attachment with mail then there is no need of saving it to gallery.
                        {
                            flag=0;
                        }
                    mLinLayMain.setDrawingCacheEnabled(false); // clear drawing cache
                } 
            catch (Exception e) 
                {
                    e.printStackTrace();
                    flag=0;
                }

            }// END mSavePhoto()

My xml code for the layout is :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/img_background"
    android:id="@+id/xRelLay"
    android:visibility="gone">
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/topbar"
        android:layout_alignParentTop="true"
        android:id="@+id/rel">
<ImageView android:id="@+id/xIvLogo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/topbar_logo"
                    android:layout_centerInParent="true"/>

    </RelativeLayout>
<ImageView android:id="@+id/xIvBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/back"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="10dip"
        android:layout_below="@+id/rel"/>
    <TextView android:id="@+id/xTvComingSoon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Coming Soon"
        android:textSize="60dip"
        android:textColor="#ffff00"
        android:layout_centerInParent="true"/>
</RelativeLayout>
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/img_background"
    android:id="@+id/xLinLayMain"
    android:visibility="visible">
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/topbar"
        android:orientation="horizontal"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip">
      <ImageView android:id="@+id/xIvLogo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/topbar_logo"
                    android:layout_centerInParent="true"/>
    </RelativeLayout>
<LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="4dip">
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView android:id="@+id/xTvLblLineSec"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Line Section"
                android:textColor="#ffff00"
                android:textSize="13dip"
                />
            <TextView android:id="@+id/xTvLblLineName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Line Name"
                android:textColor="#ffff00"
                android:textSize="13dip"
                />
             <TextView android:id="@+id/xTvLblBaseRef"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Base Ref."
                android:textColor="#ffff00"
                android:textSize="13dip"
               />
        </LinearLayout>
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="5dip">
            <TextView android:id="@+id/xTvLblLineSec_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"/>
            <TextView android:id="@+id/xTvLblLineName_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                />
             <TextView android:id="@+id/xTvLblBaseRef_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                />
        </LinearLayout>
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="5dip">
            <TextView android:id="@+id/xTvLblLineSec_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"

                android:visibility="visible"/>
            <TextView android:id="@+id/xTvLblLineName_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
                  android:visibility="visible"/>
             <TextView android:id="@+id/xTvLblBaseRef_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
                android:visibility="visible"/>
        </LinearLayout>
    </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView android:id="@+id/xTvLblKilometerage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="KILOMETRAGE"
            android:textColor="#ffff00"
            android:textSize="30dip"
            android:layout_gravity="center_horizontal"
           />
        <TextView android:id="@+id/xTvMeterage_Val"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textColor="#ffff00"
            android:textSize="45dip"

            android:layout_gravity="center_horizontal"
            android:visibility="visible"
            />
         </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
        <TextView android:layout_width="fill_parent"
            android:layout_height="1dip"
            android:background="#ed9043"
            android:layout_marginLeft="4dip"
            android:layout_marginRight="4dip"/>
        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"> 
            </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="8dip"
        android:layout_marginRight="4dip">
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView android:id="@+id/xTvLblLatitue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Latitude"
                android:textColor="#ffff00"
                android:textSize="13dip"
                  />
            <TextView android:id="@+id/xTvLblLongitude"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Longitude"
                android:textColor="#ffff00"
                android:textSize="13dip"
               />
             <TextView android:id="@+id/xTvLblDate_Now"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date NOW"
                android:textColor="#ffff00"
                android:textSize="13dip"
             />
             <TextView android:id="@+id/xTvLblDate_Last"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Date LAST"
                android:textColor="#ffff00"
                android:textSize="13dip"
                 />
              <TextView android:id="@+id/xTvLblSpeed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Speed"
                android:textColor="#ffff00"
                android:textSize="13dip"
                 />
              <TextView android:id="@+id/xTvLblOffSet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Offset"
                android:textColor="#ffff00"
                android:textSize="13dip"
                 />
        </LinearLayout>
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="5dip">
            <TextView android:id="@+id/xTvLblLatitue_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                 />
            <TextView android:id="@+id/xTvLblLongitude_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                />
             <TextView android:id="@+id/xTvLblDate_Col_Now"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                  />
             <TextView android:id="@+id/xTvLblDate_Col_Last"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                 />
              <TextView android:id="@+id/xTvLblSpeed_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                 />
              <TextView android:id="@+id/xTvLblOffSet_Col"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=":"
                android:textColor="#ffff00"
                android:textSize="13dip"
                  />
        </LinearLayout>
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="5dip">
             <TextView android:id="@+id/xTvLatitue_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
                android:visibility="visible"/>
            <TextView android:id="@+id/xTvLongitude_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
               android:visibility="visible"/>
            <LinearLayout android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
             <TextView android:id="@+id/xTvDate_Now_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
               android:visibility="visible"/>
             <DigitalClock
                android:id="@+id/digitalClock1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="DigitalClock" 
                android:textColor="#ffff00"
                android:textSize="13dip"
                android:layout_marginLeft="5dip"
                />
              <TextView android:id="@+id/xTvDigClk_Text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
             android:visibility="gone"/>
             </LinearLayout>
             <TextView android:id="@+id/xTvDate_Last_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
android:visibility="visible"/>
              <TextView android:id="@+id/xTvSpeed_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
              android:visibility="visible"/>
              <TextView android:id="@+id/xTvOffSet_Val"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffff00"
                android:textSize="13dip"
             android:visibility="visible"/>
        </LinearLayout>
    </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
<LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bottombar"
        android:orientation="horizontal"
        android:layout_marginLeft="4dip"
        android:layout_marginRight="4dip">
        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
       <RelativeLayout android:id="@+id/xRelLayContacts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dip">
         <ImageView android:id="@+id/xIvContact"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/contact_normalicon"
                    android:visibility="visible"
                    android:layout_centerHorizontal="true"/>
         <TextView android:id="@+id/xTvContact"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@+id/xIvContact"
             android:text="CONTACTS"
             android:textColor="#ffff00"
             android:textSize="12dip"
            android:layout_marginTop="2dip"
             android:layout_centerHorizontal="true"/>
         </RelativeLayout>
       <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
        <RelativeLayout android:id="@+id/xRelLayInfo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        android:layout_marginTop="4dip">
         <ImageView android:id="@+id/xIvInfo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/info_normalicon"
                    android:visibility="visible"
                    android:layout_centerHorizontal="true"/>
         <TextView android:id="@+id/xTvInfo"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@+id/xIvInfo"
             android:text=" INFO "
             android:textColor="#ffff00"
             android:textSize="12dip"
                android:layout_marginTop="2dip"
            android:layout_centerHorizontal="true"/>
         </RelativeLayout>
        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
        <ImageView android:id="@+id/xIvStart"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/start_2"
                    android:layout_gravity="center_vertical"
                    android:visibility="visible"/>

        <ImageView android:id="@+id/xIvStop"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/stop_2"
                    android:layout_gravity="center_vertical"
                    android:visibility="gone"/>
          <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
       <RelativeLayout android:id="@+id/xRelLayEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          android:layout_marginTop="4dip">
         <ImageView android:id="@+id/xIvEmail"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/email_normalicon"
                    android:visibility="visible"
                    android:layout_centerHorizontal="true"/>
         <TextView android:id="@+id/xTvEmail"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@+id/xIvEmail"
             android:text=" E-MAIL "
             android:textColor="#ffff00"
             android:textSize="12dip"
              android:layout_marginTop="2dip"
         android:layout_centerHorizontal="true"/>
         </RelativeLayout>
        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
        <RelativeLayout android:id="@+id/xRelLayPhoto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
          android:layout_marginTop="4dip">
        <ImageView android:id="@+id/xIvPhotos"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/photo_normalicon"
                    android:layout_centerHorizontal="true"/>
        <TextView android:id="@+id/xTvPhotos"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@+id/xIvPhotos"
             android:text=" PHOTO "
             android:textColor="#ffff00"
             android:textSize="12dip"
              android:layout_marginTop="2dip"
       android:layout_centerHorizontal="true"/>
          </RelativeLayout>
        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        </LinearLayout>
    </LinearLayout>
    </LinearLayout>
</LinearLayout>

I am setting the typeface for all the textviews.

My Logcat :

10-10 19:12:34.560: W/System.err(12434): java.lang.NullPointerException
10-10 19:12:34.565: W/System.err(12434):    at android.graphics.Bitmap.createBitmap(Bitmap.java:455)
10-10 19:12:34.565: W/System.err(12434):    at org.abc.artc.ARTCActivity.mSavePhoto(ARTCActivity.java:434)
10-10 19:12:34.565: W/System.err(12434):    at org.abc.artc.ARTCActivity.onClick(ARTCActivity.java:343)
10-10 19:12:34.565: W/System.err(12434):    at android.view.View.performClick(View.java:3591)
10-10 19:12:34.565: W/System.err(12434):    at android.view.View$PerformClick.run(View.java:14263)
10-10 19:12:34.565: W/System.err(12434):    at android.os.Handler.handleCallback(Handler.java:605)
10-10 19:12:34.570: W/System.err(12434):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-10 19:12:34.570: W/System.err(12434):    at android.os.Looper.loop(Looper.java:137)
10-10 19:12:34.570: W/System.err(12434):    at android.app.ActivityThread.main(ActivityThread.java:4507)
10-10 19:12:34.575: W/System.err(12434):    at java.lang.reflect.Method.invokeNative(Native Method)
10-10 19:12:34.575: W/System.err(12434):    at java.lang.reflect.Method.invoke(Method.java:511)
10-10 19:12:34.575: W/System.err(12434):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
10-10 19:12:34.580: W/System.err(12434):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
10-10 19:12:34.580: W/System.err(12434):    at dalvik.system.NativeStart.main(Native Method)

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:57:32+00:00Added an answer on June 12, 2026 at 4:57 pm

    Thanx all of you for quick responses.. The above code works fine for 2.3 but throws NPE in 4.0 and above.. It is because I have set the margin for child layouts due to which it returns null. In 2.3 also once saving of the image is done then the device’s screen blinks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam getting a null pointer exception while sending some string text as an sms
i'm getting a weird null pointer exception in the last line of this code:
I am getting null pointer exception while trying to add anything in my solrQueue.
I am getting same null pointer exception while running integration test in eclipse .while
I'm getting a really annoying error, saying I'm getting a null pointer exception but
I am getting a Null Pointer Exception Error at line 23 and line 78
Hi i am reading inbox using service but i m getting null pointer exception
I am getting a null pointer exception report in the android developer console. I
Does anyone know why I am getting a null pointer error when I call
I am getting this error when i use a string array java.lang.NullPointerException The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.