Advertisement

Android JSON Parse Images and Texts Tutorial

Advertisement
  • Sheggz

    Nice tutorial, thanks a lot.

  • zac

    getting null pointer exception because of get count please help

  • Sheggz

    I’m having a little problem, only the stub_id image is showing, and it’s not showing my images i’m loading, because bitmap is returning null. can you please help me on that

    • Hi Sheggz, I assume there are no errors showing in your logcat. Show us your MainActivity.java and ListViewAdapter.java. Paste it on http://pastebin.com/ .

      • Sheggz

        I was able to solve it. Thanks again!

        • Derek Eminence Lombela

          i am experiencing the same issue no errors on the logCat , please can you tell me how you did solve the issue ??

          • Hi Derek, could you show me your JSON file? I need to check if it is formatted correctly. For privacy concern you can email to admin@androidbegin.com

          • Nagmani Sinha

            Hi AndroidBegin,
            You tutorial is awesome. I imported your source code and faced an issue.
            I am getting error while clicking on the list view that appears on app launch. it shows the list of countries in perfectly fine manner but when I click on any of those records it stops and throws below error.

      • Derek Eminence Lombela

        Hi , im experiencing the same issue with sheggz , i am wondering how he managed to solve the issue can you help ? note : by the way the Jsons are not the same , there is no problem with the json as i am being able to view the image path when i debugged …Thank you

  • Ram

    Hi,nice tutorial.But why it’s loading only ten? i added more than 10 images but it’s showing only 10. will you please explain?

  • Hari Kishan

    Really an inspiring tutorial, the way logic in been implemented is awesome, Your hard work is very much appreciated. 🙂

  • Saad

    OOOOOOOOOOOOOOOOOOPS….AWSOME…DAMN…Gr8 *

  • Smart guy

    image will not display only Loader image display nothing else no image will show from url

    • Hi there, have you tried the sample app? Is it working for you?

  • Rohit Behl

    force close

    • Hi Rohit, could you show us your logcat in pastebin.com ?

      • Rohit Behl

        done

        Error in jason page

      • Rohit Behl

        ?? am waiting for reply

        • Rohit, you need to paste your pastebin link here. 🙂

          • Rohit Behl
          • Hi Rohit, did you declare permission Internet?

          • Rohit Behl

            I just downloaded the code

          • Rohit Behl

            yes it is present

          • Thats weird, I’m not having any issues at all. Are you using an AVD or a phone to debug? Just make sure you are not having issues with your Internet connection.

          • Rohit Behl

            Actually when i started my AVD , it was showing no DNS server so i restarted it .. now all well .. thanks

          • Thanks Rohit

          • Farhal Ansari

            The app force closes if there is no network connection. Any chance you
            could fix this to show a network error dialogue or a Toast instead of it
            force closing?

          • Rohit Behl

            problem solved

  • Gonzalo Polo Muñoz

    Hello I want to know where I can save my document .txt cause I save it on dropbox and having your code and only changing the url direcction for this other https://www.dropbox.com/s/qyv9r2hdmy5zniv/prueba.txt it makes an error and close the application

  • Gonzalo Polo Muñoz

    Hello,

    I need your help again, what I must add to see if the phone has (in the moment of going to my server) internet and if the phone doesn’t have internet say to the user “You don’t have internet connection, try it later” or something like that.

    So what I want is the code to see if the phone has internet connection. Its a project to a club and I need this!!!!

    Thank youuuuu 😀

  • Harikishan

    Hi , I am facing a NULL POINTER EXCEPTION. Could you help me out.

    • Hi, Harikishan. Please ask your question in our Android Developers Forum. 🙂

      • Harikishan

        Hi , Can you let me know where to post exactly after creating an account ?

        • Just post under help and troubleshooting. Show us your logcat too 🙂

          • Harikishan

            I have posted along with logcat, kindly guide me with valuable response. 🙂

  • Lakhan Singh

    Sir i want to take image from an another url so please send the code

  • Aditya Hari Kishan

    Nice Tutorial Example is working fine when i am trying with another json url its not executing only plain surface is displaying though all of my declarations are declared properly can you help me in fixing the issue

    Thanks in Advance
    Aditya

  • Hi Aditya, try scaling down your JSON file to a single JSON object. Then test it with your application. This could take hours for me to check your JSON file.

  • Rathurocks

    hi.. can u do the same thing with ArrayAdapter

  • Yulius Ardian Febrianto

    Hi… when i tap chine i get error LogCat showing error like this

    09-07 08:28:20.938: E/AndroidRuntime(844): FATAL EXCEPTION: main
    09-07 08:28:20.938: E/AndroidRuntime(844): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidbegin.jsonparsetutorial/com.androidbegin.jsonparsetutorial.SingleItemView}: java.lang.NullPointerException
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.ActivityThread.access$600(ActivityThread.java:141)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.os.Handler.dispatchMessage(Handler.java:99)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.os.Looper.loop(Looper.java:137)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.ActivityThread.main(ActivityThread.java:5103)
    09-07 08:28:20.938: E/AndroidRuntime(844): at java.lang.reflect.Method.invokeNative(Native Method)
    09-07 08:28:20.938: E/AndroidRuntime(844): at java.lang.reflect.Method.invoke(Method.java:525)
    09-07 08:28:20.938: E/AndroidRuntime(844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    09-07 08:28:20.938: E/AndroidRuntime(844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-07 08:28:20.938: E/AndroidRuntime(844): at dalvik.system.NativeStart.main(Native Method)
    09-07 08:28:20.938: E/AndroidRuntime(844): Caused by: java.lang.NullPointerException
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.content.ContextWrapper.getCacheDir(ContextWrapper.java:214)
    09-07 08:28:20.938: E/AndroidRuntime(844): at com.androidbegin.jsonparsetutorial.FileCache.(FileCache.java:18)
    09-07 08:28:20.938: E/AndroidRuntime(844): at com.androidbegin.jsonparsetutorial.ImageLoader.(ImageLoader.java:34)
    09-07 08:28:20.938: E/AndroidRuntime(844): at com.androidbegin.jsonparsetutorial.SingleItemView.(SingleItemView.java:16)
    09-07 08:28:20.938: E/AndroidRuntime(844): at java.lang.Class.newInstanceImpl(Native Method)
    09-07 08:28:20.938: E/AndroidRuntime(844): at java.lang.Class.newInstance(Class.java:1130)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
    09-07 08:28:20.938: E/AndroidRuntime(844): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
    09-07 08:28:20.938: E/AndroidRuntime(844): … 11 more

    • Sorry for the late reply, are you still having issues?

  • Guido Zito

    Hi, the application start correctly but when I tap an image the application crash…can you help me?thanks

    • Hi Guido, please show me your logcat. 🙂

      • Guido Zito

        here it is 🙂 :

        09-11 09:42:16.733: E/AndroidRuntime(332): FATAL EXCEPTION: main

        09-11 09:42:16.733: E/AndroidRuntime(332): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidbegin.jsonparsetutorial/com.androidbegin.jsonparsetutorial.SingleItemView}: java.lang.NullPointerException

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.ActivityThread.access$1500(ActivityThread.java:117)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.os.Handler.dispatchMessage(Handler.java:99)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.os.Looper.loop(Looper.java:123)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.ActivityThread.main(ActivityThread.java:3683)

        09-11 09:42:16.733: E/AndroidRuntime(332): at java.lang.reflect.Method.invokeNative(Native Method)

        09-11 09:42:16.733: E/AndroidRuntime(332): at java.lang.reflect.Method.invoke(Method.java:507)

        09-11 09:42:16.733: E/AndroidRuntime(332): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

        09-11 09:42:16.733: E/AndroidRuntime(332): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

        09-11 09:42:16.733: E/AndroidRuntime(332): at dalvik.system.NativeStart.main(Native Method)

        09-11 09:42:16.733: E/AndroidRuntime(332): Caused by: java.lang.NullPointerException

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.content.ContextWrapper.getCacheDir(ContextWrapper.java:188)

        09-11 09:42:16.733: E/AndroidRuntime(332): at com.androidbegin.jsonparsetutorial.FileCache.(FileCache.java:18)

        09-11 09:42:16.733: E/AndroidRuntime(332): at com.androidbegin.jsonparsetutorial.ImageLoader.(ImageLoader.java:34)

        09-11 09:42:16.733: E/AndroidRuntime(332): at com.androidbegin.jsonparsetutorial.SingleItemView.(SingleItemView.java:16)

        09-11 09:42:16.733: E/AndroidRuntime(332): at java.lang.Class.newInstanceImpl(Native Method)

        09-11 09:42:16.733: E/AndroidRuntime(332): at java.lang.Class.newInstance(Class.java:1409)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)

        09-11 09:42:16.733: E/AndroidRuntime(332): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)

        09-11 09:42:16.733: E/AndroidRuntime(332): … 11 more

        • I just tested it, I can’t seem to get the error. Are you testing it with an AVD or an Android device?

          • Guido Zito

            I’ve changed but it doesn’t work. I’m testing it with an AVD

  • Vikas Dhiman

    Hi, First of all thanks a lot for such a useful tutorial. Its is very easy to understand and its working perfectly. In this tutorial you have used Http Post method. Could you please send me only JSONFunctions class with Http Get method WITH Headers. it would be a great help to have Http Get with adding Headers.

    Thanks in Advance!

  • alex

    Hi,

    Thanks for great tutorial, everything working perfect!

    I have one question about JSON file. How can I use special character
    in JSON object? Where end how to put encoding for special character in JSON file?

    Thanks

    Alex

  • Sanjay Mangroliya

    Thanks sir very very helpfully……….

  • md.red

    great tutorial

  • Henry Wilson

    i’m facing this error “error parsing data org.json.jsonexception end of input at character 0 of”

  • Toshi

    Thanks a lot for this tutorial. I will try it now I hope everything works fine. I will post again to seek help. 🙂

  • Toshi

    What is this error sir? Please Help.

  • Guido Zito

    Hi, I’m testing it with an Android Device and work fine, but now I have another problem: I added two activities at this code but when I return on MainActivity it start to download Json again

  • Anas

    Hi , The app work fine in 4.0 android version , but don’t work in 4.3 android version ??? Please Help Me ):

    • Baxitoo

      Not sure if you managed to find a solution, but I removed android:targetSdkVersion, not good practice but don’t know of other solutions

  • Jeramba Duak

    application is not running in my avd (api level 18). here is my log cat

    • I’ll recheck the code again. At the meantime, please try with a lower API and let me know if you encounter the same issue. Thanks

      • Jeramba Duak

        all my project got nullpointerexception when i try load image with imageloader. ty anyway.

        • Hi Jeramba, I just tried running with the latest API 18, still no issues for me. Try running on your Android Device and let me know then. 🙂

          • Jeramba Duak

            you have any idea whats wrong with my avd?

          • I’m sure it has nothing to do with your AVD. I’ll have to test it on other API’s. Thanks .

  • Javier

    Hi, this project get crash when screen rotate

  • Usanka Ranasinghe

    Excellent post AndroidBegin. However, I came across several errors all of which due to my bad. I post them in case any of you finds it useful.

    1. If you get a NullPointerException somewhere in FileCache.java when you try to access SingleItemView activity, it may be because either you don’t have a SD card mounted on your device (or your AVD) or you haven’t granted permission to write to external storage in AndroidManifest.xml (the permission is “android.permission.WRITE_EXTERNAL_STORAGE”).

    2. I customized the project in order to retrieve images from different urls (in the localhost) and came to know that you have to give the url as “http://10.0.2.2/your_project_name/your_file_name” instead of “http://localhost/……”. Found that out the hard way..o_O
    cheers!!

    • Thanks Usanka, finally solved the NullPointerException for the SingleItemView activity.

      • Usanka Ranasinghe

        I’m really glad that you found it useful :))

      • Farhal Ansari

        The app force closes if there is no network connection. Any chance you
        could fix this to show a network error dialogue or a Toast instead of it
        force closing?AAA

  • Nirshad

    no image found after click singleitemview please get solution

  • Shivanand

    sir i am not getting the listview_main.xml file in java file .its showing an error and also i have created this xml file in layout folder

  • Andrés DeLa Riva Lamas

    Thaks very good tutorial, other question how converted MainActivity from Activity to Fragment, i dont know 🙁 gives me errors : ( helpme please!!!

  • Diego

    Great work Men!!!!

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?SDSD

  • Vignesh

    I pass the postion of OnClickListener adapter from a Gridview through Intents

    /**
    * On Click event for Single Gridview Item
    * */
    gridView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView parent, View v,
    int position, long id) {

    // Sending image id to MainActivity
    Intent i = new Intent(AndroidGridLayoutActivity.this,MainActivity.class);
    // passing array index
    i.putExtra(“id”, position);
    startActivity(i);
    Log.d(“tag***********”, String.valueOf(position));

    to this MainActivity.class

    // Get the view from listview_main.xml
    setContentView(R.layout.listview_main);
    Intent i = getIntent();
    // Selected image id
    position = i.getExtras().getInt(“id”);
    jsonobject = JSONfunctions.getJSONfromURL(“http://localhost/projects/slidemovieapp1 /stories.php?catid=”+position);

    When i click on the Gridimage i get the index value like 1,2,3,4,5 and that is appended to the json link and activity is created but crashes immediately. pls guide me.

    Thank you

  • guytrx

    Hi- again thanks for your tutorial its very helpfull
    i have a troble with the LAYOUTINFLATER – every time i scroll the list view its show me a deferent rows in the scale
    it seems that it NOT RECYCLING WELL
    i try it in my personal JSON, as well with my PARSE.COM server – ther i have the same issue!

    please help me
    if its needed – i will send you my url for the JSON

  • Pradeep Sharma

    Hello sir thanks for this awesome tutorial
    i want to show this data in gridview, how it is possible?
    please give some suggestion.

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?

  • Thank you very much. Great tutorial.

  • Akshay Gangurde

    Thank you so much for such a valuable post…

  • Ren

    The app force closes if there is no network connection. Any chance you could fix this to show a network error dialogue or a Toast instead of it force closing?

    Apart from that it works great, thank you for the tutorial.

    • Vinayak Parab

      Here I Am Also Having Same Issue Can Anyone Help Me.

  • I appreciate you dude.
    I have 2 question one is how can I insert search function in it?
    and other one is how can I show some information in listview_item ?

  • Guest

    大大好人一生平

  • 哈哥 哈

    大大好人,一生平安。

  • arpit

    no activity found after click singleitemview …force clost after click on itemitems…please give me solution…

  • WhatIs YourNeed

    Hello, why only temp_img is loaded and no flags?
    Solved. Didn’t add write rights in manifest

  • riri

    sir,i use same code like you.
    but i have problem when i run my apps.
    can you help me to solve that problem.

    this is my log cat.

    07-21 11:30:06.609: W/System.err(19109): java.io.FileNotFoundException: http://databudaya.net/images/1428-Monumen dan Museum Peta_FU.PNG
    07-21 11:30:06.609: W/System.err(19109): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
    07-21 11:30:06.609: W/System.err(19109): at com.budayaku.riri.ImageLoader.getBitmap(ImageLoader.java:77)
    07-21 11:30:06.609: W/System.err(19109): at com.budayaku.riri.ImageLoader.access$0(ImageLoader.java:61)
    07-21 11:30:06.609: W/System.err(19109): at com.budayaku.riri.ImageLoader$PhotosLoader.run(ImageLoader.java:154)
    07-21 11:30:06.609: W/System.err(19109): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
    07-21 11:30:06.609: W/System.err(19109): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    07-21 11:30:06.609: W/System.err(19109): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    07-21 11:30:06.609: W/System.err(19109): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    07-21 11:30:06.609: W/System.err(19109): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    07-21 11:30:06.609: W/System.err(19109): at java.lang.Thread.run(Thread.java:1019)

  • Russcal

    Thank you for this is it possible to use this within a fragment ?

  • no no

    click on the item of list – give null pointer exception in emulator

    • saish neugi

      @disqus_02ARTGRy2v:disqus did you got any solution for the same?. . . kindly reply

  • Prem Tammina

    Please help image are not displaying in the mobile… please give me a suggection

    • Hi, could you please share a link of your image? Example : http://www.androidbegin.com/tutorial/flag/russia.png

      • Prem Tammina

        http://app.talkfusion.com/members/1/001/589/1407/23150759a.png and i have added more than 95 items.. but when i am scrolling down the list items are change their position… example i have order of items like 1234 upto 95 items when i am scrolling down and coming back to top the items are changing like 1 3 7 9 2 5 4 .. why its was happening.

        • Hi, your image link is working fine. Unfortunately, I can’t fix your coding but I will give you some advice. Its up to you to listen it. Cheers

          1. Try to reduce your items to 10 or less. Then test it again.

          2. Double check your ListViewAdapter and MainActivity, slightest mistake will mess up your ListView.

          3. Try to understand the code in the sample app provided.

          If all of the above doesn’t work for you, please open a question in StackOverFlow. You must show them your attempt and issue to get better response from the experts. Good Luck buddy.

    • juned

      hi,you have forget to add this permission in AndroidMenifest.xml file.

      • arpit

        Thanks man its work

  • keith

    how do i retrieve an image from the database thats a blob data?

  • Rabii Haj Youssef

    and if the json file do not containe a jason array name what should i do 🙂

  • Ion Pana

    Hi! Thx for the tut, is great. I would like to implement a showErrorDialog at the openning of the app in case of no internet connection.
    I’ve created the functions isNetworkAvailable and showErrorDialog, than in onCreate class in MainActivity I inserted if (isNetworkAvailable()==false) {
    this.ShowErrorDialog();
    }.
    Added also permission in manifest access_network_state.
    Still, app force closes if no internet connection. What should I do. Where should I insert the functions and the if statement? Thank you a lot!

  • Mohammadreza Salari

    you used the Universal Image Loader ? if it isn’t please make a tut for UIL and use the LazyLoading by Scrolling . 🙂

  • Ashwin H

    nice tutorial….:)

  • sandeep singh

    Hi thanks for great tutorial How to implement search on this type list .thanks in advance

  • saish neugi

    hello, the tutorial works perfectly at my first attempt.
    Only problem that occured was wen i click on the item it gave an RuntimeException saying cannot instantiate activity singleitemview.

    What might be the reason?

    • Urnish Makwana

      define your single view activity in menifest file.

  • gonza28

    You can do this on an activity and navigation fragmetos drawer? Can you explain a little about this case as you do?

    The dialogue could be replaced with a splash right? as sacaria dialogue about the activity? where I can start the kind of splash?

    thank you very much

  • Edwin Moguel Morales

    how to implement endless listview in this code?

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?

      • Here is the code for checking network connection:

        @Override

        public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

        if (isNetworkAvailable()) {

        Toast.makeText(getActivity(), “Network is available!”, Toast.LENGTH_LONG).show();

        //mProgressBar.setVisibility(View.VISIBLE);

        GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();

        getBlogPostsTask.execute();

        }

        else {

        Toast.makeText(getActivity(), “Network is unavailable!”, Toast.LENGTH_LONG).show();

        //Toast.makeText(this, “Network is unavailable!”, Toast.LENGTH_LONG).show();

        }

        Now you need to add the function given below as well

        private boolean isNetworkAvailable() {

        ConnectivityManager manager = (ConnectivityManager)

        getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo networkInfo = manager.getActiveNetworkInfo();

        boolean isAvailable = false;

        if (networkInfo != null && networkInfo.isConnected()) {

        isAvailable = true;

        }

        return isAvailable;

        }

        Hope this helps.

        • Vinayak Parab

          Can You Give Me The Full Code

  • Rose Caz

    Ahmmm its working on me , however when i replace the imageurl with a localhost url.. its not displaying anymore.. sir any suggestion? do i need to lower the resolution of the pictures ?

    • Benson T

      hi rose, have found any solution to solve dis?? i also use the local server url and the image does not show.. but when i use url from website, the image display did well!

  • katamaraju

    Nice article.. helped me a lot…! Thank you

  • arpit

    .i can display data on activity using JSON..but i cant display it on sliding menu .
    fragment ..any help????

    • Dare Olowoniyi

      did you use FragmentList?

      • Farhal Ansari

        The app force closes if there is no network connection. Any chance you
        could fix this to show a network error dialogue or a Toast instead of it
        force closing?qqqqqqqq

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?sdsss

  • Muhammed Hussain

    Dear Sir the same we need but data must be from server and json

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?dsdsds

  • JahirFiquitiva

    Hey I would like to implement a click listener so that when the user clicks an item, it will start a new activity showing the picture in the item… can you help me with the code to do that?? Thanks in advance.

  • IMam Chairul Arifin

    I had a problem with a NullPointerException when starting singleitem.java
    I think the problem is in the process of loading in ImageView in singleitemview.java

    ImageLoader imageLoader = new ImageLoader (this);

    I’ve tried to fix it by replacing like this

    Context context;
    String rank;
    String country;
    String population;
    String flag;
    String position;
    ImageLoader imageLoader = new ImageLoader (context);

    but still problematic
    Can you help me as soon as possible
    thanks

  • Vaibhav

    Very good code and thanks a lot for code .

    i was found solutions for 3 days in internet but using your code i was solved my problem.

    Thanks Thanks once again

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?12

  • Oby Saputra

    it force closed when I try to click on item,

    here is my logcat:

    // ===========================================================================
    04-01 00:58:00.238: D/AndroidRuntime(750): Shutting down VM

    04-01 00:58:00.238: W/dalvikvm(750): threadid=1: thread exiting with uncaught exception (group=0x40a13300)

    04-01 00:58:00.268: E/AndroidRuntime(750): FATAL EXCEPTION: main

    04-01 00:58:00.268: E/AndroidRuntime(750): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidbegin.jsonparsetutorial/com.androidbegin.jsonparsetutorial.SingleItemView}: java.lang.NullPointerException

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.ActivityThread.access$600(ActivityThread.java:130)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.os.Handler.dispatchMessage(Handler.java:99)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.os.Looper.loop(Looper.java:137)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.ActivityThread.main(ActivityThread.java:4745)

    04-01 00:58:00.268: E/AndroidRuntime(750): at java.lang.reflect.Method.invokeNative(Native Method)

    04-01 00:58:00.268: E/AndroidRuntime(750): at java.lang.reflect.Method.invoke(Method.java:511)

    04-01 00:58:00.268: E/AndroidRuntime(750): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

    04-01 00:58:00.268: E/AndroidRuntime(750): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

    04-01 00:58:00.268: E/AndroidRuntime(750): at dalvik.system.NativeStart.main(Native Method)

    04-01 00:58:00.268: E/AndroidRuntime(750): Caused by: java.lang.NullPointerException

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.content.ContextWrapper.getCacheDir(ContextWrapper.java:200)

    04-01 00:58:00.268: E/AndroidRuntime(750): at com.androidbegin.jsonparsetutorial.FileCache.(FileCache.java:18)

    04-01 00:58:00.268: E/AndroidRuntime(750): at com.androidbegin.jsonparsetutorial.ImageLoader.(ImageLoader.java:34)

    04-01 00:58:00.268: E/AndroidRuntime(750): at com.androidbegin.jsonparsetutorial.SingleItemView.(SingleItemView.java:16)

    04-01 00:58:00.268: E/AndroidRuntime(750): at java.lang.Class.newInstanceImpl(Native Method)

    04-01 00:58:00.268: E/AndroidRuntime(750): at java.lang.Class.newInstance(Class.java:1319)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)

    04-01 00:58:00.268: E/AndroidRuntime(750): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)

    04-01 00:58:00.268: E/AndroidRuntime(750): … 11 more

    04-01 00:58:02.638: I/Process(750): Sending signal. PID: 750 SIG: 9

    // ========================================================================

    i’ll be wating for Your answer, Thanks….

    • Farhal Ansari

      The app force closes if there is no network connection. Any chance you
      could fix this to show a network error dialogue or a Toast instead of it
      force closing?

    • Urnish Makwana

      May be, you haven’t define Singleview activity in menifest file.

  • portal47

    how can i increase the resolution of the images?

  • portal47

    Great tutorial
    how can avoid forceclose the app when no internet?

  • Urnish Makwana

    It was really nice tutorial for beginners. I have implement your whole project which works perfectly fine. while i make change as per my requirement in layout and class files, Only default image shown in listview. but not that information which are in my JSON file. I don’t know what i m missing. here i have added the screenshot.

    • mani kandan

      I have the same problem dude!!

  • Pratik Sharma

    Hi,
    The code above runs pretty fine! But can you please guide me in parsing the data from JSONArray instead of JSONObject which you have already explained.I’m getting an JSONArray from MySql database. Reply deeply appreciated. Thanking you in advance!

  • ionpanaro .

    Hy, thanks very much for the tutorial. Have one problem though: it gives me java.lang.NullPointerException at MainActivity$DownloadJSON.doInBackground, at jsonarray = jsonobject.getJSONArray(“worldpopulation”); – inside private class DownloadJSON extends AsyncTask {…
    Any help much appreciated.
    See you and many thanks in advance.

  • Aminshafiee

    how to implement endless listview in this code? I need convert my listview to endless listview

  • Alexander

    Does not work with my .json is not changed
    HttpPost
    to
    HttpGet

    To have a good quality image you need changed
    final int REQUIRED_SIZE = 70
    to
    final int REQUIRED_SIZE = 256

    Good luck!

  • Vinayak Parab

    These Are The Errors With Me
    When There IS No Network Connection It Giving Following Error
    Can You Give Me The Full Code. For No Network Connection Error.

    java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:300)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
    Caused by: java.lang.NullPointerException
    at com.shivmudra.laplogics.shivmudra.Traking.Treking$DownloadJSON.doInBackground(Treking.java:72)
    at com.shivmudra.laplogics.shivmudra.Traking.Treking$DownloadJSON.doInBackground(Treking.java:44)
    at android.os.AsyncTask$2.call(AsyncTask.java:288)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)

    • Eric

      Compare with this and make necessary addittions
      if(jsonobject!=null){

      try {

      // Locate the array name in JSON

      jsonarray = jsonobject.getJSONArray(“worldpopulation”);

      for (int i = 0; i < jsonarray.length(); i++) {

      HashMap map = new HashMap();

      jsonobject = jsonarray.getJSONObject(i);

      // Retrive JSON Objects

      map.put(“rank”, jsonobject.getString(“rank”));

      map.put(“country”, jsonobject.getString(“country”));

      map.put(“population”, jsonobject.getString(“population”));

      map.put(“flag”, jsonobject.getString(“flag”));

      // Set the JSON Objects into the array

      arraylist.add(map);

      }

      } catch (JSONException e) {

      Log.e(“Error”, e.getMessage());

      e.printStackTrace();

      }}

      else{}

      return null;

      }

  • Artemis

    Hi Mr

    This code is very nice.I have import as project and when I run , give me this error:

    SkImageDecoder::Factory returned null

    Can u help me please.Thanks.

  • ganesh

    hi sir
    how to add toast data into listView.

  • Dušan Dimitrijević

    How to create json like this one which is used in tutorial?

  • Harsh

    Hi, nice tutorial. can you please let me know how we can able to pass data from list adapter to other listadapter if wants to create nested listview.

  • mjpy

    hi, very nice tutorial. i’m creating now an offline one, but my images in my listview is all the same. can u help me with this? i want it offline. my pictures are in the assets folder. thanks in advance 🙂

  • joehamir balabadan

    hi, thanks for this tutorial. it really help me a lot, i just want to know why is it not working when i use .php file.. bbut when i change it to .txt it work.. how to fix this problem? i want to use my .php file.. here is the sample link.. . php file : http://www.joehamirbalabadan.com/android/android/products.php, .txt file : http://www.joehamirbalabadan.com/android/android/products.txt

  • Mohamad Arafat

    In case if u want to resize the imageview flag u can use the below code

    android.view.ViewGroup.LayoutParams layoutParams = flag.getLayoutParams();

    layoutParams.width = 80;

    layoutParams.height = 80;

    flag.setLayoutParams(layoutParams);

  • sharayu kulkarni

    hi.. i used it by importing this code.but it is not working.

    There are no errors but the project gets stopped while running.”unfortunately app has stopped”.
    The exceptions are “An error occured while executing doInBackgroung()

  • shaymol

    Error:(38, 35) error: cannot find symbol variable temp_img

    • Luan Felipe Appolinário

      Insert into drawable folder one image called temp_img.

  • Pritish Joshi

    very nice tutorial
    worked for me
    every thing is seprate class
    so its easy to understand and implement

  • Yaqoub Alsaadi

    thanx for this tutorial
    but are there any method to write and read json file when there is no internet(read the last list view)???

  • david pilco

    i got a problem with new DownloadJSON().execute(); ?!??! someone can help me ??

  • yogi puranik

    sir plz show give me ur json array code means php code

  • yogi puranik

    here is my php code but it was showing me error while i m executing project
    Error in http connection java.net.UnknownHostException: Unable to resolve host “mahatiffin.com”: No address associated with hostname

    0){
    while($row=mysqli_fetch_array($result)){
    $temp_array[] = $row;
    }
    }
    echo json_encode(array(“AllMenu”=>$temp_array));
    mysqli_close($connect);
    }

  • yogi puranik

    here is my log cat

    05-18 17:43:11.730 27019-27019/com.androidbelieve.MahaTiffin D/dalvikvm: VFY: replacing opcode 0x6f at 0x0000
    05-18 17:43:11.740 27019-27082/com.androidbelieve.MahaTiffin E/log_tag: Error converting result java.lang.NullPointerException
    05-18 17:43:11.740 27019-27082/com.androidbelieve.MahaTiffin E/log_tag: Error parsing data org.json.JSONException: End of input at character 0 of
    05-18 17:43:11.770 27019-27082/com.androidbelieve.MahaTiffin W/dalvikvm: threadid=12: thread exiting with uncaught exception (group=0x40e11378)
    05-18 17:43:11.770 27019-27082/com.androidbelieve.MahaTiffin E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:299)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:856)
    Caused by: java.lang.NullPointerException
    at com.androidbelieve.MahaTiffin.All_Item_Fragment$ReadJSON.doInBackground(All_Item_Fragment.java:58)
    at com.androidbelieve.MahaTiffin.All_Item_Fragment$ReadJSON.doInBackground(All_Item_Fragment.java:43)
    at android.os.AsyncTask$2.call(AsyncTask.java:287)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:856)
    05-18 17:43:12.420 27019-27019/com.androidbelieve.MahaTiffin W/FragmentManager: moveToState: Fragment state for Veg_Item_Fragment{415d7030 #1 id=0x7f0c00a0 android:switcher:2131493024:1} not updated inline; expected state 3 found 2
    05-18 17:43:12.530 27019-27104/com.androidbelieve.MahaTiffin E/log_tag: Error in http connection java.net.UnknownHostException: Unable to resolve host “mahatiffin.com”: No address associated with hostname
    05-18 17:43:12.540 27019-27104/com.androidbelieve.MahaTiffin E/log_tag: Error converting result java.lang.NullPointerException
    05-18 17:43:12.540 27019-27104/com.androidbelieve.MahaTiffin E/log_tag: Error parsing data org.json.JSONException: End of input at character 0 of
    05-18 17:43:12.570 27019-27104/com.androidbelieve.MahaTiffin W/dalvikvm: threadid=14: thread exiting with uncaught exception (group=0x40e11378)
    05-18 17:43:12.570 27019-27104/com.androidbelieve.MahaTiffin I/Process: Sending signal. PID: 27019 SIG: 9

  • yogi puranik

    Sir plz help me for this i was waiting for u r answer plz mail me yppuranik2794@gmail.com

  • yogi puranik

    my image size is 346*251 so where i can do change n what changes are there plz help me do this.

  • Sanchit Mahajan

    Unfortunately tutorial has stopped msg displays when i click on any list item…. pls help me sir..

  • Sanchit Mahajan

    When i run this project on localhost with my json link the default image is displayed everywhere, no original image is displayed. what changes are to be performed. pls help me sir.

  • Sanchit Mahajan

    what to do to work this example offline.. pls help sir

  • Sanchit Mahajan

    how to work this example offline.. pls help me sir…

  • Sanchit Mahajan

    How to insert multiple images…need help.. thank u sir..

  • shivam

    How to insert multiple images into an array to scroll it horizontally ,on click on any of the item, using this tutorial?

  • Aswin GK

    Nice Tutorial.
    Can i know why is imageViewReused used ?
    Is there any complete tutorial explaining the thread model ?

  • Guntur Nur

    sir can you help me ? I follow this tutorial and i have some error

    Error:(39, 23) error: constructor ImageLoader in class ImageLoader cannot be applied to given types;
    required: RequestQueue,ImageCache
    found: no arguments
    reason: actual and formal argument lists differ in length
    Error:(86, 20) error: cannot find symbol method DisplayImage(String,ImageView)
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Error:Execution failed for task ‘:app:compileDebugJavaWithJavac’.
    > Compilation failed; see the compiler error output for details.

  • vaibhav

    Great Exapmle

  • Vinayak Parab

    Not Working With GoDaddy Domain What Can I DO

  • ABU HASAN

    In this example is very nice.But i face one problem ie: image is not showing on other device.For that what i have to do?

  • prince singh

    sir could you let me know that how we access mp3 file from server and display it our listview..

  • Ellah Jereza

    Thanks for your tutorial.
    However, I am sure that my json url is running cause I can retrieve everything including my image url. But I don’t know why my image doesn’t show. Always temp_img is shown which means null? But I have given the right url. Can you help me? Thank you so much.

    • tuneer mahatpure

      set your default image to nothing. worked in my case

  • tuneer mahatpure

    hello sir , can you tell me..In adapter class that MainActivity.Rank and all other code…where it come from