Previous Article Next Article Android Volley Tutorial (Android PHP MySQL) – JSON, Custom Adapter (Part 3)
Posted in Php

Android Volley Tutorial (Android PHP MySQL) – JSON, Custom Adapter (Part 3)

Android Volley Tutorial (Android PHP MySQL) – JSON, Custom Adapter (Part 3) Posted on April 18, 201824 Comments

Best Tutorial on How to Connect Android with PHP and MySQL using Volley (Part 2) worked on any Android Phone. Please subscribe

Android Volley Tutorial (Android PHP MySQL) – JSON, Custom Adapter (Part 3). In this part of this series Android Volley Tutorial, firstly I will start from PHP and MySQL. You first need to have a database and a table and of course some records too. Then write some PHP code to get a connection and read the data from the table. Once you get the data, you can use json_encode function to encode the array data into json objects.

Please note that this tutorial may work on your older Samsung Galaxy, LG, Oppo, Huawei, Sony or Nokia Android phones which run Android Operating Systems depended on their API version.

Source Code:


Part 1 is at
Part 2 at
Part 3 is at
Part 4.1 is at
Part 4.2 is at

Secondly, I will teach you how to read the Json objects by using Volley and convert it into ArrayList by using my own library KGJsonConverter from

Lastly, I will teach you how to use Fundapter from to bind data into a custom ArrayAdapter and set it into a ListView. Plus use Picasso to display a nice image in the ListView.

In Android, connecting android with PHP & MySQL is not always easy. In the early version of Android (before Android 3.0 API 11), you could connect to network in the main thread. However, it caused tremendous problems including memory leaks and ANR.

Since Android 3.0 API 11, Android released a library called AsyncTask which let you run the networking connection in a separate thread. I made a generic library for that which you can find at at and many video tutorials about it such as

However, the library was not enough because it followed the First In First Out (FIFO) rule. What if you had a long queues of tasks to be completed at the same time? Therefore Android just released Volley in Google I/O 2013. It is a promised to overcome the FIFO and became a real library for multitasking. It is faster and cached everything.

Where to find me:

Photo Credit:
The photo ( used in my video cover is copyright (c) by 王馬文 ( made it available under Creative Commons (


  1. sir i i have json file and i cant use php file…. so when i pass url… and i get correct responce back like the whole json data, but when i convert into arrayList ..( ArrayList<Actooors> modl=new JsonConverter<Actooors>().toArrayList(respnse,Actooors.class);)… then error shows in this line with this lines (FATAL EXCEPTION: main java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2………)

  2. Sir, I got an error after android icon, it says I should also add replace for label but when I try to change icon into label, it wants to change again the Icon. What should I do, Sir?

  3. Sir, after I fix the issue of fundapter with Android Manifest by adding xmnls tools and icon replace. a new error in building come out again saying I should replace label also because it already present in fundapter library android manifest..

    What should I do?

  4. An other thing is how can I do to pass int variables from the data base to android because I use this!!

    dictionary.addStringField(, new StringExtractor<lista_cornisas>() {
    public String getStringValue(lista_cornisas lista_cornisas, int position) {

    return lista_cornisas.Disponibles;

    And in lista_cornisas I declare Disponibles like int but it give me an error and I dont know what Im doing wrong

  5. hi!! your video is excelent!! The thing is that I just see that when I put just one image to the directory and save the link into the respective line, the same image apeare every 5 rows when the app is running, but when I put an other image into the place that appeares that image, appeares the other every 5 rows and I want to know if you know the solution of that bug or something like that!!

  6. hello Oum, and i have done this tutorial in my case i have table mysql called user have two atributes (name and password) so i make the project customized for this table and the list view have only these layouts(name and password) i am using xamp for local server ,when i run the app and price the button viewalluser (button that open subActivity and show the users in listview) when i click on it the app crash and in debug there is this: (when i press viewallusers)
    Disconnected from the target VM, address: 'localhost:8725', transport: 'socket'

  7. Hi, I subscribe your channel and your tuts are the best 🙂 Just one question. From this video I learned how to grab data from server, parse them and put in listView. How to get "setOnItemClickListener" and to pass single data from item to another activity?

    if it is easier send me reply on mail:

    best regards.

  8. I am getting this error pointing to the last line:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference

    Any ideas??

  9. Hi , Sir i have some problem with the php file "index", i copy your code and the error is "Call to undefined function mysql_query() in C:xampphtdocsDogmatelog.php ", i have another code for login that i made from a past web proyect, but well the purpouse to read this php file from android its to get the match and the message "succes" right? for login

  10. I am having the same problem: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

    Don't know how to fix it. I research UTF-8, but don't how to.
    After spending a couple of days in this tutorial and now finding out I have error that I can't solve. I guess that's the price of learning

  11. Sir whenever i try to send an image or video more than 2 MB its failed. I searched about that someone tell me it because server timeout . can u tell me please how to fix it.

Leave a Reply

Your email address will not be published. Required fields are marked *