Android程序运行时错误

时间:2011-06-23 07:15:37

标签: android android-widget

我在代码编译的代码中出错了,但是在安装时出错了

  package com.app.newapp;

  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.TextView;

  public class NewappActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      ImageView.setVisibilty(View.INVISIBLE);
      Button btn=(Button) findViewById(R.id.enter);
      btn.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String pwd="pd";
              EditText  et=(EditText) findViewById(R.id.pwd);
              if(et.getText().toString().equalsIgnoreCase(pwd))
              {
                  ImageView iv=(ImageView) findViewById(R.id.im1);
                  ImageView.setVisibilty(View.VISIBLE);
              }

          }
      });
  }

3 个答案:

答案 0 :(得分:1)

是的,收到错误是正常的。

super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
**ImageView.setVisibilty(View.INVISIBLE);**

图像视图怎么样?你有这个例子吗?或者是空引用?

答案 1 :(得分:0)

请尝试下面的事情

setContentView(R.layout.main);
ImageView imagvw1=(ImageView) findViewById(R.id.Imageviewname);
imagvw1.setVisibilty(View.INVISIBLE);

答案 2 :(得分:0)

你犯了两个错误 1)初始化图像视图 2)仅设置imageview对象的可见性。

尝试使用以下代码

 import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.TextView;

  public class NewappActivity  extends Activity {
      ImageView iv= null;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      iv=(ImageView) findViewById(R.id.im1);
      iv.setVisibility(View.INVISIBLE);
      Button btn=(Button) findViewById(R.id.enter);
      btn.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String pwd="pd";
              EditText  et=(EditText) findViewById(R.id.pwd);
              if(et.getText().toString().equalsIgnoreCase(pwd))
              {

                  iv.setVisibility(View.VISIBLE);
              }

          }
      });
  }