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

  • Home
  • SEARCH
  • 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 977683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:56:25+00:00 2026-05-16T03:56:25+00:00

for quite a while I have been trying to solve an issue with a

  • 0

for quite a while I have been trying to solve an issue with a Null Pointer Exception while populating a ViewStub. What I am trying to do is within a SlidingDrawer that contains some imageButtons and ViewStubs to fill in the ViewStubs when an ImageButton is pressed. I have been following the ViewStub Class Overview to create the ViewStubs, but I still get the Null Pointer Exception. If someone could help me out here, that would be great because I really don’t know anymore what I should do to solve this issue…I will post my code below

Thank you very much in advance!


Here is the part of my code causing the exception:

btnExposure = (ImageButton) findViewById(R.id.button_exposure);

        btnExposure.setOnClickListener(new OnClickListener()
        {

         @Override
   public void onClick(View v) {
          try{   
           ViewStub stub = (ViewStub) findViewById(R.id.stub_exposure);
           importStub = stub.inflate();
          }catch (Exception e){
                 Log.e("ERROR", "Error in Code:" +e.toString());}
   }
        });

This is the DrawingSlider XML file containing the ViewStub:

<?xml version="1.0" encoding="utf-8"?>

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent"
   android:background="@drawable/shape_background_gradient"
         >
     <LinearLayout
      android:layout_width="205px"
      android:layout_height="155px"
      android:background="#FFCCCCCC"
      android:id="@+id/VideoViewHolder"
      android:padding="2.5px"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="5px"
      android:layout_marginBottom="5px"
      >
  <VideoView
   android:layout_width="200px"
   android:layout_height="150px"
   android:id ="@+id/VideoViewEdit"
   android:layout_centerHorizontal="true"

   >
  </VideoView>
  </LinearLayout>
  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/VideoViewHolder">
   <TableLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:stretchColumns="0">
    <TableRow
      android:background="@drawable/shape_track_background"
      android:padding="5px"
      >
     <ImageView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_editor_videotrack"
          android:padding="5px"
          android:layout_gravity="left"/>

    </TableRow>
    <TableRow
      android:background="@drawable/shape_track_background"
      android:padding="5px"
      >
      <ImageView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_editor_audiotrack"
          android:padding="5px"
          android:layout_gravity="left"/>


    </TableRow>
    <TableRow
      android:background="@drawable/shape_track_background"
      android:padding="5px"
      >
     <ImageButton android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_editor_add_media"
          android:padding="5px"
          android:layout_gravity="left"
          />
    </TableRow>
   </TableLayout>
  </ScrollView>
 <SlidingDrawer
     android:id="@+id/drawer"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
  android:orientation="horizontal"
     android:handle="@+id/handle"
     android:content="@+id/content">

     <ImageView
         android:id="@id/handle"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/slider_handle"
         />

     <LinearLayout
         android:id="@id/content"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:orientation="vertical">
        <ImageButton 
         android:id="@+id/button_exposure"
         android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#77000000"
   android:src="@drawable/ic_slider_exposure"
   android:padding="5px"
   android:layout_marginBottom="1px"
   android:layout_gravity="left"/>
        <ImageButton 
         android:id="@+id/button_properties"
         android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#77000000"
   android:src="@drawable/ic_slider_properties"
   android:padding="5px"
   android:layout_marginBottom="1px"
   android:layout_gravity="left"/>
        <ImageButton 
         android:id="@+id/button_special_effects"
         android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#77000000"
   android:src="@drawable/ic_slider_special_effects"
   android:padding="5px"
   android:layout_marginBottom="1px"
   android:layout_gravity="left"/>
  <ImageButton 
         android:id="@+id/button_test1"
         android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#77000000"
   android:src="@drawable/ic_slider_exposure"
   android:padding="5px"
   android:layout_marginBottom="1px"
   android:layout_gravity="left"/>
        <ImageButton 
         android:id="@+id/button_test2"
         android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="#77000000"
   android:src="@drawable/ic_slider_exposure"
   android:padding="5px"
   android:layout_marginBottom="1px"
   android:layout_gravity="left"/>
     </LinearLayout>
     <ViewStub
      android:id="@+id/stub_exposure"
      android:inflatedId="@+id/stub_exposure_view"

      android:layout="@layout/exposureview"

      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#77000000">
     </ViewStub>
     <ViewStub
      android:id="@+id/stub_properties"
      android:inflatedId="@+id/stub_properties_view"

      android:layout="@layout/propertiesview"

      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#77000000">
     </ViewStub>
     <ViewStub
      android:id="@+id/stub_special_effects"
      android:inflatedId="@+id/stub_special_effects_view"

      android:layout="@layout/specialeffectsview"

      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#77000000">
     </ViewStub>
 </SlidingDrawer>
</RelativeLayout>

And this is the ViewStub layout xml (exposureview.xml), which is called to inflate the Stub:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@+String/hello"
 ></TextView>
 <SeekBar
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:thumb="@drawable/seek_thumb"
  android:progress="50"
  android:max="100">
 </SeekBar>

</RelativeLayout>
  • 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-05-16T03:56:26+00:00Added an answer on May 16, 2026 at 3:56 am

    Apparently findViewById(R.id.stub_exposure); returns null for you. Did you recompile your class properly to regenerate the R.java file?

    Also, I noticed you defined one of your text view’s text property in your view stub layout XML file as android:text="@+String/hello".

    Don’t know if it’s just a typo or not, but has the R.java been properly generated? If you have an existing value in strings.xml (notice not uppercase) then the compiler should complain.

    You should try to do a Project -> Clean to see if you get warnings or errors (if you’re using Eclipse).

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

Sidebar

Related Questions

No related questions found

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.