Can't get informations over JSON
**What I'm trying**


----------
I try to learn JSON, for that I created a small Youtube-App with witch you can see all videos of a channel. But this dosn't work, when i try to get the data over JSON i allways get this Error: `11-22 08:35:37.932: E/CANT READ DATA(15923): Error parsing data org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject`

**Question**


----------
What do I need to change to get this code working? A good sample or something would also help much!
Down here you find the Code.

**Code**


----------

JSONfunction.java

    package de.stepforward;
    
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.HashMap;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.util.Log;
    
    public class JSONfunction {
    
    	public static JSONObject getJSONfromURL(String url){
    		InputStream is = null;
    		String result = "";
    		JSONObject jArray = null;
    		
    		//http post
    	    try{
    	            HttpClient httpclient = new DefaultHttpClient();
    	            HttpPost httppost = new HttpPost(url);
    	            HttpResponse response = httpclient.execute(httppost);
    	            HttpEntity entity = response.getEntity();
    	            is = entity.getContent();
    
    	    }catch(Exception e){
    	            Log.e("NO CONNECTION", "Error in http connection "+e.toString());
    	    }
    	    
    	  //convert response to string
    	    try{
    	            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    	            StringBuilder sb = new StringBuilder();
    	            String line = null;
    	            while ((line = reader.readLine()) != null) {
    	                    sb.append(line + "\n");
    	            }
    	            is.close();
    	            result=sb.toString();
    	    }catch(Exception e){
    	            Log.e("CANT CONVERT DATA", "Error converting result "+e.toString());
    	    }
    	    
    	    try{
    	    	
                jArray = new JSONObject(result);            
    	    }catch(JSONException e){
    	            Log.e("CANT READ DATA", "Error parsing data "+e.toString());
    	    }
        
    	    return jArray;
    	}
    }

ShowChannel.java

    package de.stepforward;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;
    import android.widget.AdapterView.OnItemClickListener;
    
    
    public class ShowChannel  extends ListActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
            
            JSONObject json = JSONfunction.getJSONfromURL("http://gdata.youtube.com/feeds/mobile/users/TheStepForward/uploads?alt=json");
            
            
            //Anzeigebild laden und in ArrayList einfügen
            try{
            	JSONArray thumbnail = json.getJSONArray("thumbnail");
            	for(int i=0;i<thumbnail.length();i++){
            		HashMap<String, String> map = new HashMap<String, String>();
            		JSONObject e = thumbnail.getJSONObject(i);
            		
            		map.put("thumbnail", e.getString("default"));
            		mylist.add(map);
            	}
            }catch(JSONException e){
            	Log.e("Bildladen", "Error-Data"+e.toString());
            }
            
            //Video Name sowie Beschreibung laden und in ArrayList einfügen
            try{
            	
            	JSONArray  items = json.getJSONArray("items");
    	        for(int i=0;i<items.length();i++){						
    				HashMap<String, String> map = new HashMap<String, String>();	
    				JSONObject e = items.getJSONObject(i);
    				
    	        	map.put("title",  e.getString("title"));
    	        	map.put("description", e.getString("description"));
    	        	mylist.add(map);			
    			}		
            }catch(JSONException e)        {
            	 Log.e("VideoLaden", "Error-Data "+e.toString());
            }
            
            //Video-Link laden und in Arrayöost einfügen
            try{
            	
            	JSONArray  link = json.getJSONArray("player");
    	        for(int i=0;i<link.length();i++){						
    				HashMap<String, String> map = new HashMap<String, String>();	
    				JSONObject e = link.getJSONObject(i);
    				
    	        	map.put("link",  e.getString("mobile"));
    	        	mylist.add(map);			
    			}		
            }catch(JSONException e)        {
            	 Log.e("LinkLaden", "Error-Data "+e.toString());
            }
            
            //Liste füllen
            ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.listlayout, 
                    new String[] {"thumbnail", "title", "subtitle" }, 
                    new int[] { R.id.img_video, R.id.txt_title, R.id.txt_subtitle });
    
            setListAdapter(adapter);
            
            //OnItemClickListner für Hyperlinks
            final ListView lv = getListView();
            lv.setTextFilterEnabled(true);	
            lv.setOnItemClickListener(new OnItemClickListener() {
            	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {   
            		@SuppressWarnings("unchecked")
    				HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
            		Toast.makeText(ShowChannel.this, "Link '" + o.get("link") + "' was clicked.", Toast.LENGTH_SHORT).show();
            	}
            		
            });
        
        }
        
    }


Error-Log

    11-22 08:35:37.932: E/CANT READ DATA(15923): Error parsing data org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject
    11-22 08:35:37.932: D/AndroidRuntime(15923): Shutting down VM
    11-22 08:35:37.932: W/dalvikvm(15923): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
    11-22 08:35:38.032: E/AndroidRuntime(15923): FATAL EXCEPTION: main
    11-22 08:35:38.032: E/AndroidRuntime(15923): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.stepforward/de.stepforward.ShowChannel}: java.lang.NullPointerException
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.access$1500(ActivityThread.java:132)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.os.Looper.loop(Looper.java:143)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.main(ActivityThread.java:4196)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at java.lang.reflect.Method.invokeNative(Native Method)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at java.lang.reflect.Method.invoke(Method.java:507)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at dalvik.system.NativeStart.main(Native Method)
    11-22 08:35:38.032: E/AndroidRuntime(15923): Caused by: java.lang.NullPointerException
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at de.stepforward.ShowChannel.onCreate(ShowChannel.java:36)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	... 11 more


----------
Thanks for you help in advance
best regardes
safari
Can't get informations over JSON
===

**What I'm trying**


----------
I try to learn JSON, for that I created a small Youtube-App with witch you can see all videos of a channel. But this dosn't work, when i try to get the data over JSON i allways get this Error: `11-22 08:35:37.932: E/CANT READ DATA(15923): Error parsing data org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject`

**Question**


----------
What do I need to change to get this code working? A good sample or something would also help much!
Down here you find the Code.

**Code**


----------

JSONfunction.java

    package de.stepforward;
    
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.HashMap;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.util.Log;
    
    public class JSONfunction {
    
    	public static JSONObject getJSONfromURL(String url){
    		InputStream is = null;
    		String result = "";
    		JSONObject jArray = null;
    		
    		//http post
    	    try{
    	            HttpClient httpclient = new DefaultHttpClient();
    	            HttpPost httppost = new HttpPost(url);
    	            HttpResponse response = httpclient.execute(httppost);
    	            HttpEntity entity = response.getEntity();
    	            is = entity.getContent();
    
    	    }catch(Exception e){
    	            Log.e("NO CONNECTION", "Error in http connection "+e.toString());
    	    }
    	    
    	  //convert response to string
    	    try{
    	            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    	            StringBuilder sb = new StringBuilder();
    	            String line = null;
    	            while ((line = reader.readLine()) != null) {
    	                    sb.append(line + "\n");
    	            }
    	            is.close();
    	            result=sb.toString();
    	    }catch(Exception e){
    	            Log.e("CANT CONVERT DATA", "Error converting result "+e.toString());
    	    }
    	    
    	    try{
    	    	
                jArray = new JSONObject(result);            
    	    }catch(JSONException e){
    	            Log.e("CANT READ DATA", "Error parsing data "+e.toString());
    	    }
        
    	    return jArray;
    	}
    }

ShowChannel.java

    package de.stepforward;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.app.ListActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;
    import android.widget.AdapterView.OnItemClickListener;
    
    
    public class ShowChannel  extends ListActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
            
            JSONObject json = JSONfunction.getJSONfromURL("http://gdata.youtube.com/feeds/mobile/users/TheStepForward/uploads?alt=json");
            
            
            //Anzeigebild laden und in ArrayList einfügen
            try{
            	JSONArray thumbnail = json.getJSONArray("thumbnail");
            	for(int i=0;i<thumbnail.length();i++){
            		HashMap<String, String> map = new HashMap<String, String>();
            		JSONObject e = thumbnail.getJSONObject(i);
            		
            		map.put("thumbnail", e.getString("default"));
            		mylist.add(map);
            	}
            }catch(JSONException e){
            	Log.e("Bildladen", "Error-Data"+e.toString());
            }
            
            //Video Name sowie Beschreibung laden und in ArrayList einfügen
            try{
            	
            	JSONArray  items = json.getJSONArray("items");
    	        for(int i=0;i<items.length();i++){						
    				HashMap<String, String> map = new HashMap<String, String>();	
    				JSONObject e = items.getJSONObject(i);
    				
    	        	map.put("title",  e.getString("title"));
    	        	map.put("description", e.getString("description"));
    	        	mylist.add(map);			
    			}		
            }catch(JSONException e)        {
            	 Log.e("VideoLaden", "Error-Data "+e.toString());
            }
            
            //Video-Link laden und in Arrayöost einfügen
            try{
            	
            	JSONArray  link = json.getJSONArray("player");
    	        for(int i=0;i<link.length();i++){						
    				HashMap<String, String> map = new HashMap<String, String>();	
    				JSONObject e = link.getJSONObject(i);
    				
    	        	map.put("link",  e.getString("mobile"));
    	        	mylist.add(map);			
    			}		
            }catch(JSONException e)        {
            	 Log.e("LinkLaden", "Error-Data "+e.toString());
            }
            
            //Liste füllen
            ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.listlayout, 
                    new String[] {"thumbnail", "title", "subtitle" }, 
                    new int[] { R.id.img_video, R.id.txt_title, R.id.txt_subtitle });
    
            setListAdapter(adapter);
            
            //OnItemClickListner für Hyperlinks
            final ListView lv = getListView();
            lv.setTextFilterEnabled(true);	
            lv.setOnItemClickListener(new OnItemClickListener() {
            	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {   
            		@SuppressWarnings("unchecked")
    				HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
            		Toast.makeText(ShowChannel.this, "Link '" + o.get("link") + "' was clicked.", Toast.LENGTH_SHORT).show();
            	}
            		
            });
        
        }
        
    }


Error-Log

    11-22 08:35:37.932: E/CANT READ DATA(15923): Error parsing data org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject
    11-22 08:35:37.932: D/AndroidRuntime(15923): Shutting down VM
    11-22 08:35:37.932: W/dalvikvm(15923): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
    11-22 08:35:38.032: E/AndroidRuntime(15923): FATAL EXCEPTION: main
    11-22 08:35:38.032: E/AndroidRuntime(15923): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.stepforward/de.stepforward.ShowChannel}: java.lang.NullPointerException
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.access$1500(ActivityThread.java:132)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.os.Looper.loop(Looper.java:143)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.main(ActivityThread.java:4196)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at java.lang.reflect.Method.invokeNative(Native Method)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at java.lang.reflect.Method.invoke(Method.java:507)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at dalvik.system.NativeStart.main(Native Method)
    11-22 08:35:38.032: E/AndroidRuntime(15923): Caused by: java.lang.NullPointerException
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at de.stepforward.ShowChannel.onCreate(ShowChannel.java:36)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
    11-22 08:35:38.032: E/AndroidRuntime(15923): 	... 11 more


----------
Thanks for you help in advance
best regardes
safari