[Solved] Android code not working


Change your onCreate View like This:

TextView textView;
ImageView imageView;
Button eat;


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
imageView = (ImageView) findViewById(R.id.bc);
eat = (Button) findViewById(R.id.button);

eat.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      eat();

                    }
                });



// Calling member function

  uneat();

  }

  public void eat() {

  textView.setText(R.string.changed_shit);
  imageView.setImageResource(R.drawable.after_cookie);

    }

   public void uneat() {
   textView.setText(R.string.changed_again);
   imageView.setImageResource(R.drawable.before_cookie);
   }

5

solved Android code not working