正如标题所暗示的,这段代码在 Eclipse 中运行良好,但是一旦我导出并尝试仅在设备上使用它,它就不会降低任何东西,只是返回 null。
它应该从 url 读取文本并将其显示在文本视图中
我不知道我做错了什么,它可能相当简单,但我只是看不到它
public class nextEvent extends Activity implements OnClickListener {
String Event;
TextView eventText;
TextView titleText;
String HTML;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newevent);
titleText = (TextView) findViewById(R.id.Title);
eventText = (TextView) findViewById(R.id.Event);
try {
getHTML();
} catch (Exception e) {
e.printStackTrace();
}
eventText.setText("" + HTML);
}
private void getHTML() throws ClientProtocolException, IOException
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://masterzangetsu.eu/Apps/rocksoctest"); //URL!
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while ((line = reader.readLine()) != null) {
result += line + "\n";
HTML = result;
}
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
继承人的xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Upcoming Events"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/Event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Title"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:text="Sever Event Update Failed" />
</RelativeLayout>
</ScrollView>
任何帮助都会很棒