I am creating an Android application that captures a user's email using the displayEmailCaptureFragment () method. If I have already registered a userโs email, I donโt want to prompt the user to enter their email address again.
I declare the line customerEmailAddress immediately after my MainActivity, but before the onCreate method:
public class MainActivity extends FragmentActivity implements View.OnClickListener, BillingProcessor.IBillingHandler,
EmailCapturedListener {
private MyPagerAdapter pageAdapter;
private Button mDownloadResumeButton;
private ImageButton mRightArrow, mLeftArrow;
private static final String EMAILKEY = "email_key";
public static final String EDITSKU = "professional_editing_service_1499";
public static final String EMAILSKU = "resume_template_pro_99";
private static final String RBPEMAIL = "rbproeditor@gmail.com";
private static final String RBPPASSWORD = "Redhawks123";
public String customerEmailAddress;
Then I have the OnClick () method based on the response action of the user in the application. Essentially, I am trying to allow a specific action after onClick if the user has already entered their email address. If they have not provided their email address, I suggest that they enter their email and save it in the general settings. I use the basic if-else statement, however, I still throw a null pointer exception, even if I assign the line customerEmailAddress:
@Override
public void onClick(View v) {
int currentPosition = pager.getCurrentItem();
switch (v.getId()) {
case R.id.right_arrow:
pager.setCurrentItem(currentPosition + 1);
break;
case R.id.left_arrow:
pager.setCurrentItem(currentPosition - 1);
break;
case R.id.download_resume_button:
customerEmailAddress = mPrefs.getString(EMAILKEY, null);
if (customerEmailAddress.equals(null)){
displayEmailCaptureFragment();
}
else {
showPurchaseDialog();
}
break;
}
}
Any help is appreciated!
source
share