gazzler gazzler - 4 months ago 21
MySQL Question

Android Login not connecting with DB

I'm using this tutorial to make an Android login application. I have followed all his steps and successfully am able to load the application on the emulator or my phone, however when I try and create an account I get an error - I followed the instructions he provided stating how to test the system, referencing to here:

  1. Testing the App

For a beginner it will be always difficult to run this project for the first time. But don’t worry, the following steps will helps you testing this app. (The ip address looks like

Make sure that both devices (the device running the PHP project and the android device) are on the same wifi network.

Give correct username , password and database name of MySQL in Config.php

Replace the URL ip address of URL_LOGIN and URL_REGISTER in with your machine ip address. You can get the ip address by running ipconfig in cmd

my IPv4 address is,
So I added that to the AppConfig file as follows:


public class AppConfig {
// Server user login url
public static String URL_LOGIN = "";

// Server user register url
public static String URL_REGISTER = "";


I am using Android Studio's built in emulator so both devices are on the same network.

I am using Lampp and I'm under the assumption by default this is the username and password:

define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "android_api");

I started the local servers and tested to make sure they were running by loading up a demo page.

I've already also created the MySQL database and table as shown in his example.

My file structure for the server side is shown in this picture

But when I try create a User I get this crash:

beginning of crash

06-26 19:12:13.205 2668-2668/ E/AndroidRuntime: FATAL EXCEPTION: main
Process:, PID: 2668
java.lang.NullPointerException: Attempt to invoke virtual method 'void, java.lang.String)' on a null object reference
at android.view.View.performClick(
at android.view.View$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)

I am unable to find any obvious error and was wondering if someone could help!


You didn't add the AppController to the application tag in the AndroidManifest.xml as explained in the tutorial. Your AppController now doesn't get called during the initialization of your app and isn't initialized. When you call AppController.getInstance().addToRequestQueue(strReq, tag_string_req); inside your registerUser method AppController.getInstance() returns null. This causes your nullpointerException. Add the AppController to the manifest and your code should be working.

Your application tag should look like this:

    android:theme="@style/AppTheme" >