Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7721117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:50:35+00:00 2026-06-01T03:50:35+00:00

I’m trying to display a preferences screen if my saved preferences aren’t found. But

  • 0

I’m trying to display a preferences screen if my saved preferences aren’t found. But I seem to be running into a problem with my app crashing due to a Null Pointer Exception.

The code I am currently trying to use

public class MainActivity extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        SharedPreferences sharedPrefs = PreferenceManager
                .getDefaultSharedPreferences(this);
    } catch (Exception e) {
        // Preferences
        Intent prefsIntent = new Intent(MainActivity.this,
                Preferences.class);
        startActivity(prefsIntent);
    } finally {
        Intent loginIntent = new Intent(MainActivity.this,
                LoginForm.class);
        startActivity(loginIntent);
    }
  }

}

edit:

This is what I get from the Debug Console. http://pastebin.com/s0rEZEE9

The line 24 from LoginForm.Java is

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

edit 2:

This is the entire LoginForm which is what the debug console says is giving an error.

package com.smashedbits.livestreams;

import java.util.HashMap;
import java.util.Map;

import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class LoginForm extends Activity {

public AQuery aq;

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(LoginForm.this);
boolean autoLogin = sharedPrefs.getBoolean("remember_login", false);

EditText eUsername = (EditText) findViewById(R.id.usernameField);
EditText ePassword = (EditText) findViewById(R.id.passwordField);

@Override
public void onBackPressed() {
    super.onBackPressed();
    // return;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    aq = new AQuery(this);

    // Views
    final Button prefsButton = (Button) findViewById(R.id.prefsButton);
    final Button loginButton = (Button) findViewById(R.id.loginButton);

    // Check for saved data
    String usrn = sharedPrefs.getString("usr", "NULL");
    String pswd = sharedPrefs.getString("pwd", "NULL");
    if (autoLogin == true & usrn != "NULL") {
        eUsername.setText(usrn);
        ePassword.setText(pswd);
    }

    // Preferences
    prefsButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent prefsIntent = new Intent(LoginForm.this,
                    Preferences.class);
            startActivity(prefsIntent);
        }
    });

    // Login
    loginButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ls_login();
        }
    });

}

public void ls_login() {

      boolean autoLogin = sharedPrefs.getBoolean("remember_login", false);

      if (autoLogin == true) { saveLogin(); }

    String url = "http://{redacted}";
    EditText eUsername = (EditText) findViewById(R.id.usernameField);
    EditText ePassword = (EditText) findViewById(R.id.passwordField);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("log", eUsername.getText().toString());
    params.put("pwd", ePassword.getText().toString());
    params.put("rememberme", "forever");
    params.put("wp-submit", "Log In");
    params.put("redirect_to", "{redacted}");
    params.put("testcookie", "1");

    aq.ajax(url, params, String.class, new AjaxCallback<String>() {

        @Override
        public void callback(String url, String html, AjaxStatus status) {

            if (html.contains("LOG OUT")) {
                Intent guideIntent = new Intent(LoginForm.this,
                        ChannelGuide.class);
                startActivity(guideIntent);
            }

        }
    });
}

private void saveLogin() {
    SharedPreferences.Editor editor = sharedPrefs.edit();

    editor.putString("usr", eUsername.getText().toString());
    editor.putString("pwd", ePassword.getText().toString());

    editor.commit();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:50:37+00:00Added an answer on June 1, 2026 at 3:50 am

    I found out that I could only declare the variables once the activity is started and then assign them under oncreate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.