-1

I have resolved this before but I can't remember what I did. Basically its a simple EditText and finding it's view by id but i get the error messagejava.lang.NullPointerException when running the app.

public class MainActivity extends Activity {

CallbackManager callbackManager;
public static final String SECRET_KEY = "65EB1D3A-F8D8-D6DC-FF21-E111F9409600";
public static final String APP_ID = "F5931D23-2392-1B65-FF65-BC4256BB9300";
RegisterAccount register;
EditText mName = (EditText) findViewById(R.id.userName);
EditText mEmail = (EditText) findViewById(R.id.userEmail);
EditText mPassword = (EditText) findViewById(R.id.userPassword);
EditText mConfirmPassword = (EditText) findViewById(R.id.userConfirmPassword);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this.getApplicationContext());
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);
    Backendless.initApp(MainActivity.this, APP_ID, SECRET_KEY, "v1");

    BackendlessUser user = new BackendlessUser();
    user.setEmail(mEmail.getText().toString());
    user.setPassword(mPassword.getText().toString());

    Backendless.UserService.register(user, new AsyncCallback<BackendlessUser>() {
        @Override
        public void handleResponse(BackendlessUser backendlessUser) {

            Intent logIntent = new Intent(MainActivity.this, ContentActivity.class);
            logIntent.putExtra("Name", mEmail.getText().toString());
            startActivity(logIntent);
        }

        @Override
        public void handleFault(BackendlessFault backendlessFault) {
            // On failure
        }

});

root92
  • 15
  • 7
  • I have tried to clean the project and rebuilt it but still nothing. Really cant remember what I did. Would someone be able to help me please. :( – root92 Mar 25 '16 at 13:14
  • Show the all error message please – Raphael Teyssandier Mar 25 '16 at 13:15
  • Please share your code .... – Tabish Hussain Mar 25 '16 at 13:17
  • Do your class extends from AppCompatActivity or Activity? – Manuel Pamplona Mar 25 '16 at 13:17
  • id is same your are getting R.id.username ??? – Khizar Hayat Mar 25 '16 at 13:21
  • 1
    Either 'R' is null or 'R.id' is null. Do you debug your code? It's amazing how much faster it is to run your application in an IDE with a debugger will solve your issue vs. writing an unclear question on SO and expecting people to 'guess' at the issue. I would go the debugging route. @MikeM These types of questions will put you in a bad mood - flagged :) – pczeus Mar 25 '16 at 13:43
  • What approach would you take to debug? I just used the android studio logcat to which indicated the EditText was null, infact to all my EditText's – root92 Mar 25 '16 at 13:49

1 Answers1

0

Put the following lines:

EditText mName = (EditText) findViewById(R.id.userName);
EditText mEmail = (EditText) findViewById(R.id.userEmail);
EditText mPassword = (EditText) findViewById(R.id.userPassword);
EditText mConfirmPassword = (EditText) findViewById(R.id.userConfirmPassword);

below: setContentView(R.layout.activity_main); in your onCreate() method.

You first load your XML view using setContentView() method and than you instantiate your view objects.

Community
  • 1
  • 1
Prerak Sola
  • 9,517
  • 7
  • 36
  • 67