I’m working with Eclipse (Android Developer Tools)
This page gives me two errors, could someone explain what’s to do please?
thanks a lot!
package com.example.myproject;
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.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class InternetTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_internet_test);
// Internet test
HttpGet httppost = new HttpGet("http://myurl.com/test.txt");
HttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
InputStream is = buf.getContent();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line + "\n");
}
TextView.setText(total);
// test done
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_internetseiten_test, menu);
return true;
}
}
The errors:
“httpclient cannot be resolved”
“Cannot make a static reference to the none-static methode setText(CharSequence) from the type TextView”
I imported external jars ( these: http://hc.apache.org/downloads.cgi )
Thanks!
The first error is caused because you haven never specified what
httpClientis.The second problem is because you are making a static call to a non-static function. You have to tell the system what TextView to set the text to. Not knowing it’s name, I’ll just show you roughly how it’s done.