Android的:不能投从View图库 [英] Android: Cannot cast from View to Gallery

查看:142
本文介绍了Android的:不能投从View图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使Android的画廊。为了设置需要转接器来获得我在XML文件中定义的画廊。林这样做的:
画廊G =(图库论坛)findViewById(R.id.gallery1);
但有了这个code我不能编译我的项目,因为我得到错误无法从View转换到画廊。我的XML文件看起来是这样的:

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

推荐答案

您code看起来不错。
检查您是否有正确的进口图库

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

import android.widget.Gallery;

这篇关于Android的:不能投从View图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆