I am trying to retrieve images from SQLite database (I saved the images as String
path ) to an ImageView
, using this method:
Load method
public Bitmap Load(String path, BitmapSize bitmapSize) {
BitmapFactory.Options options = SetBitmapOptions(bitmapSize);
Context ctx = getContext();
if (ctx == null) {
throw new IllegalStateException("Fragment " + this + " not attached to a
context.");
} else {
Bitmap placeholder = decodeResource(ctx.getResources(),
R.drawable.placeholder, options);
try {
if (path.isEmpty()) {
return placeholder;
}
return decodeFile(path, options);
} catch (Exception e) {
Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
return placeholder;
}
}
}
This method is inside the Fragment FreezerUp
, and I am calling this method from a ListViewAdapter implements ListAdapter
class its method: getView
getView method
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
FreezerUpFragment fuf = new FreezerUpFragment();
Product prd = mArrList.get(position);
if (convertView == null) {
LayoutInflater li = LayoutInflater.from(mContext);
convertView = li.inflate(R.layout.list_row, null);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
convertView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
TextView prdName = convertView.findViewById(R.id.productName);
ImageView image = convertView.findViewById(R.id.img);
TextView prdDesc = convertView.findViewById(R.id.productDesc);
prdName.setText(prd.getProduktName());
prdDesc.setText(prd.getProduktDesc());
String s = FreezerUpFragment.imgPath;
FreezerUpFragment.BitmapSize bs = FreezerUpFragment.BitmapSize.ListView;
fuf.Load(s, bs);
image.setImageBitmap(fuf.Load(s, bs));
}
return convertView;
I am using a TabLayout
with PagerAdapter extends FragmentStateAdapter
class for 2 fragments FreezerUpFragment
and FreezerDownFragment
.
My app starts showing FreezerUpFragment
in the first tab
containing a ListView
(product names, product description and product images).
After a debug
I noticed that ctx: null
in Load
method.
Any help to suggest or point me to why the Context
is null
is very appreciated.