Use this
public class CoverFlowExample extends Activity implements OnItemClickListener {
/** Called when the activity is first created. */
int imageCount = 0;
Cursor cur;
String toastResult;
String pathName;
ArrayList<String> list1 = new ArrayList<String>();
private int blocker = 0;
private int imagePosition;
private int pathIndex;
private int indexer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Use this if you want to use XML layout file
setContentView(R.layout.activity_coverflow);
CoverFlow coverFlow;
coverFlow = (CoverFlow) findViewById(R.id.coverflow);
/* CoverFlow coverFlow;
coverFlow = new CoverFlow(this); */
Bundle extras = getIntent().getExtras();
if(extras !=null) {
imagePosition = extras.getInt("imagePosition");
}
String[] proj2 = {MediaStore.Images.Media.DATA};
Cursor cur2 = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj2, MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'", null, null);
imageCount = cur2.getCount();
cur2.close();
coverFlow.setAdapter(new ImageAdapter(this));
ImageAdapter coverImageAdapter = new ImageAdapter(this);
coverFlow.setAdapter(coverImageAdapter);
coverFlow.setSpacing(-10);
coverFlow.setSelection(imageCount, true);
coverFlow.setOnItemClickListener(this);
coverFlow.setSelection(imagePosition);
// centers the image on coverflow to the same image selected in the previous activity
coverFlow.setBackgroundResource(R.drawable.blanklarge);
basically the issue is that once you declare the things in xml, the opbjects are created automatically once you inflate them using setCOntentView. You can get those already created objects using findViewById and no need to create them again using "x = new x()"