0
   holder.txtTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) 
        {
            System.out.println("hhhhhhhhhhhhhhhhhhhh");

          Intent i2 = new Intent(this,ImageSelection.class);
          startActivity(i2);      


        }
  });

This triggers.. But i cant call an Intent from here. Getting null pointer exception.. anybody has got the same?

AshMv
  • 392
  • 2
  • 12

3 Answers3

2

You are using this into listener then it will belongs to listener object. But you need Context object to declare the Intent. So you need to change this with YOUR_ACTIVITY_NAME.this.


Change

Intent i2 = new Intent(this,ImageSelection.class);
startActivity(i2);

to

Intent i2 = new Intent(YOUR_ACTIVITY.this,ImageSelection.class);
YOUR_ACTIVITY.this.startActivity(i2); 

Ohh yes you are trying to start activity from adapter.

Then it should be

Intent i2 = new Intent(context_object_which_is_in_adapter, ImageSelection.class);
context_object_which_is_in_adapter.startActivity(i2); 
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
1

You are trying to start another activity from your Custom ListView Adapter, right?

Than do this:

     Intent i2 = new Intent(mContext ,ImageSelection.class);
     mContext.startActivity(i2);

where mContext is the Context of the calling activity.

ClaireG
  • 1,244
  • 2
  • 11
  • 23
1

Try this..

Intent i2 = new Intent(YOUR_ACTIVITY.this,ImageSelection.class);
YOUR_ACTIVITY.this.startActivity(i2);

Best Wishes

Amresh
  • 2,098
  • 16
  • 20