我一直在寻找所有的stackoverflow找到解决方案,但我还没有找到它。所以,现在我想说如果发现重复,我很抱歉。现在,我已经说,让我们得到一些代码和问题:Android:ImageView将不会被加载
我想一个ImageView
加载到我的活动,但我不断收到一个不错的蓝色调试日志我的logcat说"imageview == null"
if (imageview == null) {
Log.d(TAG, "imageview == null");
} else {
imageview.setImageBitmap(bm); }`
它只是检查我的ImageView
是否为空(并且如果不为空则将图像置入它中)。我尝试加载它在onCreate
方法:
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");
}
我的头一直问我:“你在XML文件中声明ImageView的,你这个傻瓜?”我继续检查其包含
<ImageView
android:name="@+id/galleryPicture"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@id/confirmText"
android:contentDescription="description comes here...." />
我靶向API 8 XML文件(Android 2.2的),我一直在试图解决关于现在加载ImageView
几天这个问题。现在修复
你确定你在这里加载正确的布局(的setContentView(R.layout.confirmpicture );)? – Nermeen
请检查str对象或getIntent()。getStringExtra(“GalleryImage”)可能是其中一个给你null – Pratik
是Nunu,我正在加载正确的布局文件。 – Zuenonentu