Android: Sqlite Database Crashes On Returning A Quantity
Database holds name and quantity of medication... what is required to be returned is the quantity corresponding to the medication which is scanned. code for database: public class
Solution 1:
QRcodeReturn()
as it is now will only work correctly if it has a proper Context
(it needs it for getSharedPreferences()
metod to work). It won't work from class `ToolDB.
You should :
- either pass a
Context
parameter to it - or alternatively run this method from your activity before using
ToolDB
class and pass the obtained value toToolDB
class.
For example:
publicStringQRcodeReturn(Context context){
SharedPreferences codeHack = context.getSharedPreferences(SCAN_RESULT,0);
String QRcode = codeHack.getString("entry", "unregistered");
return QRcode;
}
You can then use it from the activity:
Stringcode= QRcodeReturn(this);
and from QuantReturn()
:
public String QuantReturn(Context context){
...
Stringy= x.QRcodeReturn(context);
...
}
Post a Comment for "Android: Sqlite Database Crashes On Returning A Quantity"