android - NullpointerException while initializing variables in contentprovider -
hi trying solve quite sometime not able success
i trying initialize variables in content provider below
public static string rb_radio ; public static string im_radio ; static { rb_radio = context.getresources().getstring(r.string.kgs); im_radio = context.getresources().getstring(r.string.grams); } public aerprovider(context ctx) { super(ctx); context = ctx; i setting rb_radio values resource folder can see getting null pointer exception,below stack trace
10-09 16:38:40.265: e/androidruntime(4114): caused by: java.lang.nullpointerexception 10-09 16:38:40.265: e/androidruntime(4114):at com.in.android.aer.contentprovider.aerprovider.<clinit>(aerprovider.java:49) any help appreciated
when rb_radio initialized in static way, context not have value yet value in constructor, when object instantiated.
try :
public static string rb_radio = null; public static string im_radio = null; public aerprovider(context ctx) { super(ctx); context = ctx; if (rb_radio == null) rb_radio = context.getresources().getstring(r.string.kgs); if (im_radio == null) im_radio = context.getresources().getstring(r.string.grams); } android android-contentprovider
No comments:
Post a Comment