0

What am i doing wrong below in the code the code compiles but when installed gives an error

  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
  • What error does it give? Please include a stacktrace / logcat output. Commented Jun 23, 2011 at 7:17
  • com.app.newapp closed... Commented Jun 23, 2011 at 7:19
  • That really doesn't help. As I said in my previous comment, you'll need to include a stacktrace or logcat output if you want anyone to help you with this. Commented Jun 23, 2011 at 7:22

3 Answers 3

1

Yes, it is normal to get an error.

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

What about the image view? Do you have any instance of this? Or is null reference?

Sign up to request clarification or add additional context in comments.

Comments

0

Please try below things

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

Comments

0

You did two mistakes 1) initialize image view 2) set the visibility to the imageview objects only.

Try with the following code

 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);
              }

          }
      });
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.