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 6325701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:56:46+00:00 2026-05-24T16:56:46+00:00

I want to inflate a Gallery and Text, so I creates a gallery.xml <?xml

  • 0

I want to inflate a Gallery and Text, so I creates a gallery.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout00"
android:layout_width="fill_parent" android:layout_height="wrap_content">

<TextView android:id="@+id/text" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_weight="1"
    android:layout_gravity="left|center_vertical" android:textSize="20dip"
    android:layout_marginLeft="10dip" />
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gallery" android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

I want to show multiple gallery , so i add galleries dynamically.
When I inflate it , I am getting null pointer exception.

    public class PayPerViewActivity extends Activity  implements OnItemClickListener{
GridView gridview  = null;
ImageAdapter imageAdapter = null;
private Gallery gallery[] ;
DataProvider dataProvider ;
LazyAdapter adapter[];
String[] values = null;
View view[];
static class ViewHolder extends LinearLayout{
    public ViewHolder(Context context) {
        super(context);
    }
    public Gallery g;
    public TextView text;
}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.galleris);

    final LayoutInflater  inflater =     (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int count = 1;
    gallery = new Gallery[Config.NO_OF_GALLERY];
    adapter = new LazyAdapter[Config.NO_OF_GALLERY];
    LinearLayout innerLayout =  (LinearLayout) findViewById(R.id.LinearLayout02);
    for(int i = 0 ; i < Config.NO_OF_GALLERY ; i++){
        values = new String[Config.IMAGES_PER_GALLERY]; 
        for(int j = 0 ; j<Config.IMAGES_PER_GALLERY ;j++){
            values[j]= Config.MOVIE_URL+count+Config.IMAGE_EXT;
            count++;
        }
        ViewHolder vi = new ViewHolder(this);
        view[i] = inflater.inflate(R.layout.gallery, null);// Null pointer exception on this line

        gallery[i] = (Gallery) view[i].findViewById(R.id.gallery);
        adapter[i] = new LazyAdapter(this,dataProvider.getInstance().getGallery().get(""+i).getData());
        gallery[i].setAdapter(adapter[i]);
        gallery[i].setOnItemClickListener(this);

        vi.g = gallery[i];
        TextView textView = (TextView)findViewById(R.id.text);
        textView.setText("kid");
        vi.text = textView;
        view[i].setTag(vi);
        innerLayout.addView(view[i]);
                }

}   @Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
    String tag =  (String) v.getTag();
    Intent i = new Intent(this, DetailedViewActivity.class);
    i.putExtra("url", tag);
    startActivity(i);
}

I am not able to debug why it giving null pointer exception.Please help me. Thanks.

  • 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-24T16:56:48+00:00Added an answer on May 24, 2026 at 4:56 pm

    Your view variable is null. You need to initialize it before setting view[i] to something, for example

    view = new View[Config.NO_OF_GALLERY];
    

    as you do it for gallery and adapter arrays.

    Or use collections for this (particularly List).

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

Sidebar

Related Questions

I want to inflate a XML-Layout-File in a custom ViewGroup Class, my Problem is
I have a Gallery whose Adapter creates several LinearLayout instances. Those linear layout instances
i want to inflate a expandable list with some different text and different images
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Want to send the text from my current vb application to the Active Window
I want to inflate a childView of ExpandableChildView component. Code: public View getChildView(int groupPosition,
I am trying to Build a gallery in Android ( Not exactly what is
I want to do a custom view coming from an XML. Here's my XML
So I can inflate a ViewStub at runtime. Let's say I want to make
I have a ListView that inflate for each row a xml that contain a

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.