HTTP Client API level 11 or greater in Android
<p>I have Restful Web Service implemented by Jersey.
I connect from Android via HTTP client to fetch the data. It works fine in API level 10 and older versions but not on API level 11 or greater. I appreciate for any help. I have a nullPointerException in these versions.</p>

<pre><code>public String getBaseURI(String str) {
        String result = "";
        try {
            HttpParams httpParameters = new BasicHttpParams();
            int timeoutConnection = 3000;
            HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
            int timeoutSocket = 5000;
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
            DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
            HttpGet getRequest = new HttpGet(ServerAddress + str);
            getRequest.addHeader("accept", "application/json");
            HttpResponse response = httpClient.execute(getRequest);
            result = getResult(response).toString();
            httpClient.getConnectionManager().shutdown();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } 
        return result;
    }

private StringBuilder getResult(HttpResponse response) throws IllegalStateException, IOException {
        if (response.getStatusLine().getStatusCode() != 201) 
            throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        StringBuilder result = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())), 1024);
        String output;
        while ((output = br.readLine()) != null) 
            result.append(output);
        return result;      
    }
</code></pre>

<p>Tag : AndroidRuntime</p>

<p>The logcat exception:</p>

<pre><code>Exception: FATAL EXCEPTION: main
java.lang.NullPointerException
at com.android.internal.os.LoggingPrintStream.Prrintln(LogiingPrintStream.java.298)
at Client.getBaseURI (Client.java:66)
</code></pre>

<p>when I call a rest service such as:
String str = client.getBaseURI("task/project/get/" + user);<br>
I get the <strong>Error.</strong></p>

<pre><code>private void listViewSet() {

        ListView lv = (ListView) this.findViewById(R.id.listView);
        lv.setAdapter(new MultiAdapter(this));

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int pos, long id) {

                switch (pos) {
            case ADD:
            String str = client.getBaseURI("task/project/get/" + user);// Json format
                        ......
                }
            }
        });
    }
</code></pre>
