首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅在单个设备上使用NullPointException (三星Galaxy选项卡)

仅在单个设备上使用NullPointException (三星Galaxy选项卡)
EN

Stack Overflow用户
提问于 2012-09-10 16:58:55
回答 1查看 140关注 0票数 0

所以我尝试通过findViewById()获得一个视图。它在模拟器4.0和41上的效果很好。在android 2.3智能手机上,但当在三星galaxy标签上尝试时,变量始终为空。

HomeActivity.java

代码语言:javascript
复制
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.start_new_user);
    ViewFlipper vf = (ViewFlipper) findViewById(R.id.viewFlipper1_newuser);

在galaxy-tab上,vf始终为空。如果我尝试用它做一些事情,比如vf.getContext(),我会得到一个NPE。

start_new_user.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tV_new_user"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp"
        android:background="@drawable/roundedcorner"
        android:padding="15dp"
        android:text="@string/start_new_user" />


  <LinearLayout
      android:id="@+id/rl_calendar_newuser"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:orientation="vertical" >

        {...}
    </LinearLayout>




    <ViewFlipper
        android:id="@+id/viewFlipper1_newuser"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    </ViewFlipper>

</LinearLayout>
</LinearLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-10 17:04:41

检查是否在所有布局版本中都定义了该视图。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12348345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档