app crashes on adding image in android studio

By | October 30, 2018
Questions:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/pod" />

<Button
    android:id="@+id/btnChangeImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Change Image" />

1.and java file is here

2.it does’nt show any error just few warnings

  1. app crashes on phone

4.logcat is not available
5.without the @drawable/image_name it works well on other apps, im not checked this one ,also what should i see in the logcat as;-error or warn or verbose or assert i’m new to android studio and the addng image is not working.

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

public class photo extends Activity {

Button button;
ImageView image;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo);

    addListenerOnButton();

}

public void addListenerOnButton() {

    image = (ImageView) findViewById(R.id.imageView1);

    button = (Button) findViewById(R.id.btnChangeImage);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            image.setImageResource(R.drawable.index);
        }

    });

}

}

Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *