I have been looking all over stackoverflow to find a solution, but I haven’t found it. So now I want to say sorry if duplicate is found. Now that I have said that, let’s get some code and problems:
I am trying to load an ImageView into my Activity, but I keep getting a nice blue debug log in my logcat saying "imageview == null"
if (imageview == null) {
Log.d(TAG, "imageview == null");
} else {
imageview.setImageBitmap(bm); }`
which just checks if my ImageView is null or not (and sets an image into it if not null). I try load it in the onCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.confirmpicture);
String str = getIntent().getStringExtra("GalleryImage");
Log.i(TAG, "Got " + str + " from the intent");
Bitmap bm = BitmapFactory.decodeFile(str);
imageview = (ImageView) findViewById(R.id.galleryPicture);
if (bm != null) {
if (imageview == null) {
Log.d(TAG, "imageview == null");
} else {
imageview.setImageBitmap(bm);
}
} else {
Log.d(TAG, "Bitmap not decoded");
}
My head keeps asking me: “Did you declare the ImageView in the xml file, you fool?” and I keep checking the xml file which contains
<ImageView
android:name="@+id/galleryPicture"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@id/confirmText"
android:contentDescription="description comes here...." />
I am targetting API 8 (Android 2.2) and I have been trying to fix this problem about loading the ImageView for days now. Fixed now
You should write
android:id="@+id/galleryPicture"in the xml file, notandroid:name="@+id/galleryPicture". There is no view with id galleryPicture in the layout file you created.