zoukankan      html  css  js  c++  java
  • findViewById返回null的原因

    最近做android项目,原来好好的程序突然运行不起来了,debug一下发现是findViewById方法返回null值,真是纳闷了。

    如下代码:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //取消标题
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.logo);
    System.out.println("findviewbyid="+findViewById(R.id.logo));
    ImageView iv = (ImageView)findViewById(R.id.logo);
    AlphaAnimation aa= new AlphaAnimation(0.1f, 1.0f);
    aa.setDuration(3000);
    iv.startAnimation(aa);
    aa.setAnimationListener(new AnimationListener() {

    @Override
    public void onAnimationStart(Animation animation) {
    // TODO Auto-generated method stub

    }
    ……

    ……

    ……
    }

    检查半天也没错,后来在网站看到,这种情况只有一种解释,就是Eclipse的问题。运行多了就要清空一下项目

    清空的方法是:在上侧的菜单栏中选中Project>>选择Clean>>选择项目就行了

    程序再次运行正常了

  • 相关阅读:
    body test
    menu
    Toolbutton test itk_component
    grid pack
    double inherit
    set font
    Activity test itk_component
    Activity test no class
    按键驱动调试总结
    system.img解包打包的方法
  • 原文地址:https://www.cnblogs.com/winxiang/p/win_xiang.html
Copyright © 2011-2022 走看看