I have some Android code that I'm hoping to pull data off of a webpage and display it as text. Unfortunately, I'm getting this error, even though it has proper permissions and everything:
java.net.UnknownHostException: Unable to resolve host "ephemeraltech.com": No address associated with hostname
Here is my manifest file permissions:
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And here is the code itself:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.round_activity_my);
TextView mTextView = (TextView)findViewById(R.id.text);
myAsyncTask mTask = new myAsyncTask();
mTask.execute("http://ephemeraltech.com/demo/android_tutorial20.php");
/* final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
mTextView = (TextView) stub.findViewById(R.id.text);
}
}); */
}
private class myAsyncTask extends AsyncTask<String,Void,Void> {
public String resultText;
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(String... str) {
try {
System.out.println("testing");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://ephemeraltech.com/demo/android_tutorial20.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream webs = entity.getContent();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(webs,"iso-8859-1"),8);
resultText = reader.readLine();
webs.close();
System.out.println("testing II");
} catch(Exception e){
resultText = "hi";
}
} catch (Exception e) {
System.out.println(e.toString());
}
return null;
}
}
protected void onPostExecute(String resultText) {
TextView mTextView = (TextView)findViewById(R.id.text);
mTextView.setText("sdfdfdfdf");
System.out.println("Testing III");
}
}
I have no clue why am getting it. Anyone have any idea?
EDIT: It's an Android Wear emulator, and it is paired to a phone that has Wifi, so I don't know why it can't reach the internet.