2013-03-07 81 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