Не удалось загрузить веб-просмотр в виде вкладок

Я понятия не имею, почему мой веб-просмотр не может загрузиться в моем tabhost/tabwidget. Для tabhost/tabwidget я использую учебник, предоставленный разработчиком Android. Кроме того, в моем логарифме предупреждение, похоже, находится на tab1Activity.java, указывая предупреждение на "wv.loadDataWithBaseURL("http://lovetherings.livejournal.com/961.html", myString, "text/html", "UTF-8", "о: пусто"); "

Ниже мои коды. Может кто-нибудь помочь мне? Большое спасибо заранее! :D

Вот мой main.xml

    <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

        </FrameLayout>
</LinearLayout>

Моя основная деятельность

public class HelloTabWidgetMain extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, ArtistsActivity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("tab1").setIndicator("tab1",
                      res.getDrawable(R.drawable.ic_tab_tab1))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, tab2Activity.class);
    spec = tabHost.newTabSpec("tab2").setIndicator("tab2",
                      res.getDrawable(R.drawable.ic_tab_tab2))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, tab3Activity.class);
    spec = tabHost.newTabSpec("tab3").setIndicator("tab3",
                      res.getDrawable(R.drawable.ic_tab_tab3))
                  .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);
}

}

И моя активность на вкладке (где я хотел бы, чтобы отображалось содержимое моего веб-просмотра)

public class tab1Activity extends Activity{

WebView wv;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
    URL url = new URL("http://lovetherings.livejournal.com/961.html");

    // Make the connection
    URLConnection conn = url.openConnection();
    BufferedReader reader = new BufferedReader(
        new InputStreamReader(conn.getInputStream()));

    // Read the contents line by line (assume it is text),
    // storing it all into one string
    String content ="";
    String line = reader.readLine();
    while (line != null) {
        content += line + "\n";
        line = reader.readLine();
    }
    reader.close();

    String myString = content.substring(content.indexOf("<newcollection>"));

    int start = myString.indexOf("<newcollection>");
    if (start < 0) {
        Log.d(this.toString(), "collection start tag not found");
    }
    else {
        int end = myString.indexOf("</newcollection>", start) + 8;
        if (end < 0) {
            Log.d(this.toString(), "collection end tag not found");
        } else {
            myString = "<html><body>" + myString.substring(start, end) + "</body></html>";
        }

        WebView wv = (WebView)findViewById(R.id.webview);
        wv.loadDataWithBaseURL("http://lovetherings.livejournal.com/961.html", myString, "text/html", "UTF-8", "about:blank");
    }
    } catch (Exception ex) {
        ex.printStackTrace();
    // Display the string in txt_content
    //TextView txtContent = (TextView)findViewById(R.id.txt_content);
    //txtContent.setText(myString);
    }    
}    

}

Помогите мне, пожалуйста! Заранее спасибо!


person Winona    schedule 03.06.2011    source источник


Ответы (1)


В XML макета корневому узлу (LinearLayout) нужен атрибут пространства имен. Вставьте xmlns:android="http://schemas.android.com/apk/res/android" в качестве первого атрибута. Я предполагаю, что ваш макет не наполняется должным образом, вызывая ошибку, когда вы пытаетесь что-то сделать с WebView.

person ErikR    schedule 03.06.2011
comment
Нет, у меня действительно был этот корневой узел. Просто, когда я скопировал сюда, он исчез, возможно, я пропустил копирование корневого узла. - person Winona; 03.06.2011