Android:无法从View投射到图库

mei*_*eio 2 android view gallery android-gallery

我想在android中创建一个Gallery.为了设置适配器需要获取我在我的xml文件中定义的库.我这样做:画廊g =(画廊)findViewById(R.id.gallery1); 但是使用这段代码我无法编译我的项目,因为我得到错误"无法从视图转换为图库".我的xml文件看起来像这样:"

<?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>
Run Code Online (Sandbox Code Playgroud)

谁知道如何解决我的问题?非常感谢

Pen*_*m10 6

你的代码看起来很好.检查您是否具有正确的导入 Gallery

import android.widget.Gallery;
Run Code Online (Sandbox Code Playgroud)

  • aahhh..ok.我想出了我的错误.我也把我的班级画廊命名为,所以我有一个名字冲突.谢谢 (4认同)