+ 3

How to fix this error in fragment.... help :(

here's the code adapter = new ScanItemAdapter(ScanDatabase.get instance(this).getScans(), this); list.setAdapter(adapter); barcodeView.decode continuous(this); I got error on "this" inside getInsance() parameter... what should I do to fix this....?

3rd Feb 2018, 11:23 AM
Yen
Yen - avatar
9 Answers
+ 9
Sorry Bie I couldn't figure out the issue with the information provided. Perhaps you can give it a try on StackOverflow and all the best to you!
5th Feb 2018, 1:37 PM
Zephyr Koo
Zephyr Koo - avatar
+ 8
Can we know the exact error message you got? If you're unable to compile the code, then most likely it's because the getInstance method was expecting another data type besides the current context from "this".
3rd Feb 2018, 3:56 PM
Zephyr Koo
Zephyr Koo - avatar
+ 4
I think you have a custom class named Fragment_scan it is asking for its object.
4th Feb 2018, 10:11 AM
Saminjay Goel
Saminjay Goel - avatar
+ 3
It might be asking for context. try getContext(), getActivityContext() or getActivity(). It might work. If it doesn't solve the error then provide the error message.
3rd Feb 2018, 6:41 PM
Saminjay Goel
Saminjay Goel - avatar
+ 2
getContext(), getActivity(), getActivityContext() doesn't work.... but it work in statement below; private void addScanItem(String barcode) { adapter.addItem(ScansDatabase.getInstance(getContext()).addItem(barcode)); } here's the error message getInstance (Android.content.Context) in ScansDatabase cannot be applied to (com.name.scammer.Fragment_scan)
4th Feb 2018, 12:43 AM
Yen
Yen - avatar
+ 2
custom class means a class that you have created.
5th Feb 2018, 3:52 AM
Saminjay Goel
Saminjay Goel - avatar
+ 2
but I still don't understand, why only this line of code not working...(getContext(), getActivity(),...can't apply). adapter = new ScanItemAdapter(ScanDatabase.get instance(this).getScans(), this); list.setAdapter(adapter); barcodeView.decode continuous(this); but no error on this line... private void addScanItem(String barcode) { adapter.addItem(ScansDatabase.getInstance(getContext()).addItem(barcode));
5th Feb 2018, 4:23 AM
Yen
Yen - avatar
+ 2
Is ok Zephyr...thanks for trying to help.... I will try another way to do it....
5th Feb 2018, 1:41 PM
Yen
Yen - avatar
0
can i know what does "custom class" mean? :(
5th Feb 2018, 1:20 AM
Yen
Yen - avatar