jms_gears1
Lurker
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
anything that could potentially help me would be awesome, Thanks in advance
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(); [B][COLOR="Red"]<---- So far this is where it throws the exception[/COLOR][/B]
}
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;
}
}