0

これは私のコードです。エミュレーターでは、コードは正しく機能し、印刷されます

<!doctype html>
    <html itemscope="" itemtype="http://schema.org/WebPage">
    <head>
    <meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description">
    <meta content="noodp" name="robots"><meta content="/images/google_favicon_128.png" itemprop="image"><meta content="origin" id="mref" name="referrer"><title>Google</title>        

    <script>(function(){

しかし、私の電話では、残念ながらプログラムは終了しました!!

そのため、プログラムはエミュレーターで正しく実行され、電話で強制的に閉じられました。私のマニフェストで、インターネット許可を設定しました

    package com.example.untitled11;

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

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.ArrayList;

    public class MyActivity extends Activity {

    static URL url = null;
    static TextView textView;

    static ArrayList<String> html = new ArrayList<String> (1000)  ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        textView = (TextView) findViewById(R.id.textView);

        try {
            url = new URL("http://google.com/");
        } catch (MalformedURLException e) {
            textView.setText("URL\n"+e);
        }
        InputStream xx = null;
        try {
            xx = url.openConnection().getInputStream();
        } catch (IOException e) {
            textView.setText("InputStream\n" + e);
        }

        BufferedReader reader = null;
        reader = new BufferedReader( new InputStreamReader( xx  ));


        String line = "";

        try {
            while( (line = reader.readLine() ) != null )  {
                html.add(line+"");
            }
        } catch (IOException e) {
            textView.setText("adding\n" + e);
        }

        try {
            reader.close();
        } catch (IOException e) {
            textView.setText("closing\n"+e);

        }

        textView.setText(html.get(0)+"");

        }
}

これは私のマニフェストです:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.untitled11"
      android:versionCode="1"
      android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="@string/app_name">
    <activity android:name="MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>
</manifest> 
4

2 に答える 2