Reputation: 51
<?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
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);
}
});
}
}
Upvotes: 1
Views: 5104
Reputation: 51
1.sometimes it happens that all your code is right and you were getting app crash due to you've put the images in drawable v24or v21 not in drawable so change it to drawable as i've done in my case so go and check whether it is v24 or not
2.you can check it in sort your project is with project>app>build>src>main>drawable drawable v24
3.you've to put the image from drawable v24 to drawable and now you're done
4.go run and check
Upvotes: 4
Reputation: 235
This can happen when your picture resolution is too big. Also try to create an image for each screen density (hdpi, xhdpi, xxhdpi ...). You can use this link => http://nsimage.brosteins.com
Upvotes: 3