views:

60

answers:

2

Hello, I'd like to make a Gallery in android. In order to set the adapter in need to get the gallery which I defined in my xml file. Im doing that as: Gallery g = (Gallery) findViewById(R.id.gallery1); But with this code I can't compile my project, since I get the Error "Cannot cast from View to Gallery". My xml-file looks like this: "

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

Anybody knows how to solve my problem? Thanks a lot

A: 

Your code looks fine. Check if you have the correct import for Gallery

import android.widget.Gallery;
Pentium10
aahhh..ok. I figured my error. I named my class Gallery as well, and so I had a name-conflict. Thank you
meio
Important on SO, you have to mark accepted answers by using the tick on the left of the posted answer, below the voting. This will increase your rate.
Pentium10
A: 

I think you just created the Object instance for Gallery. Gallery is a AdapterView. So you must set Adapter for the Content. please check this sample

Praveen Chandrasekaran