When ever im calling fromcheckpass(mcontext)
im getting nullpointerexception. Where imdoing wrong. Help me out!
From onClick()
i'm calling fromcheckpass(mcontext)
.
public void onClick(View v) {
InboxActivity inboxActivity = new InboxActivity();
inboxActivity.fromcheckpass(CheckPass.this);
}
How can I call fromcheckpass(mcontext)
method ?
public void fromcheckpass(Context mcontext) {
Toast.makeText(mcontext, "WEL COME", Toast.LENGTH_LONG).show();
Db = new MySQLiteHelper(this);
String DbInsert = Utils.getPreferences("DbInsert", this);
if (!DbInsert.equalsIgnoreCase("Inserted")) {
SaveDataInDB();
}
MessageListView = (ListView) findViewById(R.id.lvInbox);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0154A4")));
bar.setTitle(R.string.app_name);
bar.setTitle(Html.fromHtml("<font color='#ffffff'>WeText </font>"));
bar.setIcon(R.drawable.icon_top);
Utils.getOverflowMenu(this);
attachListeners();
dataList = Utils.getLatestMessageOfAllContacts(InboxActivity.this);
if (dataList.isEmpty()) {
Toast.makeText(getApplicationContext(), "NO MESSAGES", Toast.LENGTH_LONG).show();
} else {
iAdapter = new Adapter(InboxActivity.this, dataList);
MessageListView.setAdapter(iAdapter);
}
}
Whenever I call fromCheckpass(mcontex) method the app crashes. Here is my logcat:
Process: com.futureappspk.WeTextFree, PID: 29065
java.lang.NullPointerException
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:186)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at com.futureappspk.WeTextFree.Utils.getPreferences(Utils.java:432)
at com.futureappspk.WeTextFree.InboxActivity.fromcheckpass(InboxActivity.java:130)
at com.futureappspk.WeTextFree.CheckPass$1.onClick(CheckPass.java:40)
Here is my util class method which is calling fromcheckpass(mcontext)
public static String getPreferences(String key, Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String userName = sharedPreferences.getString(key, "UserName");
return userName;
}