Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old June 14th, 2010, 12:44 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2010
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default java.net.UnknownHostException

Im attempting to build an application that sends a request to a server.
The server spits out JSON encoded text.
I want the app to get that text and display that information/store it in the droids sql base.

Im stuck on the part where i am supposed to retrieve the information. I continue to get the error: java.net.UnkownHostException

Code:
package lol.lol.lol;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class lol extends Activity {
    /** Called when the activity is first created. */
    public int num;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView txt = (TextView)this.findViewById(R.id.text);
        txt.setText(getScramble("lol",0));
    }
    public String getScramble(String table, int numb){
    	HttpClient client = new DefaultHttpClient();
    	HttpPost post = new HttpPost("http://www.youtube.com");
    	HttpResponse response = null;
    	HttpEntity entity = null;
    	InputStream is = null;
    	BufferedReader reader = null;
    	String s = "";
    	try{
    		response = client.execute(post);
    	}catch(Exception e){
    		Log.e("log_tag",e.toString()+": "+e.getMessage());
    		return e.toString(); <---- So far this is where it throws the exception
    	}
    	try{
    		entity = response.getEntity();
    	}catch(Exception e){
    		Log.e("log_tag",e.toString()+": "+e.getMessage());
    		return e.getMessage();
    	}
    	try{
    		is = entity.getContent();
    	}catch(Exception e){
    		Log.e("log_tag",e.toString()+": "+e.getMessage());
    		return e.getMessage();
    	}
    	try{
    		reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    	}catch(Exception e){
    		Log.e("log_tag",e.toString()+": "+e.getMessage());
    		return e.getMessage();
    	}
    	StringBuilder sb = new StringBuilder();
        String line = null;
        try{
        	while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
        	}
        	is.close();
        }catch(Exception e){
        	Log.e("log_tag",e.toString()+": "+e.getMessage());
        	return e.getMessage();
        }
 
        String result = sb.toString();
        try{
        	JSONArray jArray = new JSONArray(result);
        	for(int i=0;i<jArray.length();i++){
        		JSONObject json_data = jArray.getJSONObject(i);
        		Log.i("log_tag","2x2x2: "+json_data.getString("two2H")+
        				", 3x3x3: "+json_data.getString("three2H"));
        		s = json_data.getString("two2H");
        	}
        }catch(Exception e){
        		Log.e("log_tag",e.toString()+": "+e.getMessage());
        		return e.getMessage();
        	}
		return s;    	
    }
}
anything that could potentially help me would be awesome, Thanks in advance

Advertisements
jms_gears1 is offline  
Reply With Quote
sponsored links
Old June 16th, 2010, 07:48 PM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jun 2010
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

can no one help me?
Do i need more information, or is it just because im using the eumlator?
jms_gears1 is offline  
Reply With Quote
Old June 18th, 2010, 09:02 AM   #3 (permalink)
New Member
 
Join Date: Jun 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same problem until i put
Code:
<uses-permission android:name="android.permission.INTERNET" />
in the AndriodManifest.xml as the first child element (i.e. even before the application element). Then it worked.
o90pO()P is offline  
Reply With Quote
Old September 10th, 2010, 12:56 PM   #4 (permalink)
New Member
 
Join Date: Sep 2010
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Fixed my problem, thanks!

Thank you, I missed the permissions setting and spend a couple hours beating my head against the wall.

Thanks!
swiftk77 is offline  
Reply With Quote
Old March 14th, 2011, 01:26 PM   #5 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are some tips on this link too, just in case.
Tips to solve the UnknownHostException on Android
guerrarj is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:37 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.