2013-03-07 75 views
-1

Java代碼:活動沒有得到顯示

package com.piyush.bankai; 

import java.io.IOException; 

import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class HomeParse extends Activity { 
static final String BLOG_URL = "http://www.google.com/"; 
Document doc=null; 
String linkText=null; 
String linkHref=null; 
//TextView a; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    // set layout view 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.homeparse); 

    try { 
     doc = Jsoup.connect("http://en.wikipedia.org/").get(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    Elements divs = doc.select("#mp-itn b a"); 

    for (Element div : divs) { 
      linkHref = div.attr("href"); 
      linkText = div.text(); 
     } 


    try { 
     ((TextView)findViewById(R.id.tv1)).setText(linkHref); 
    } catch (Exception ex) { 
     ((TextView)findViewById(R.id.tv1)).setText("kalal"); 
    } 


    for (Element div : divs) 
     System.out.println(div.text()); 
    } 
} 

XML佈局文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 


<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    android:id="@+id/tv1" 
    /> 

</LinearLayout> 

清單文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.piyush.bankai" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="8" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 

    <activity 
     android:name=".Flip" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 


    <activity 
     android:name=".Queries" 
     android:configChanges="orientation" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
     <intent-filter> 
      <action android:name="android.intent.action.QUERIES" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 


    <activity 
     android:name=".Test" 
     android:configChanges="orientation" 
     android:label="@string/app_name" 
     android:screenOrientation="portrait" > 
    </activity> 


    <activity 
     android:name=".HomeParse" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.HOMEPARSE" /> 
      <category android:name="android.intent.category.LAUNCHER"   /> 
     </intent-filter> 
    </activity> 


</application> 

<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

</manifest> 

運行這個項目後,我可以在控制檯中看到的是安裝成功!和完成。就是這樣,輸出不會顯示在android設備上。請幫我調試這個bug。我曾嘗試創建其他項目,他們似乎運行良好。

回答

2

您的清單是錯誤的:

如果你想回家解析是你必須把這一意圖過濾器就可以發射活動

<intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 

並從.flip活動中刪除。

也是這個<action android:name="android.intent.action.HOMEPARSE" />是不是一個真實的東西和Android無能爲力這一行

+0

非常感謝你much.It的工作。 – SeasonalShot 2013-03-07 16:37:29