2014-09-30 111 views
0

交換活動我有一個應用程序,它解析RSS饋送到列表中,當我們點擊列表中的項目,它調用其他活動中的WebView顯示RSS源鏈接中的內容:錯誤當機器人

public class ListListener implements OnItemClickListener { 
    // List item's reference 
    List<RssItem> listItems; 
    // Calling activity reference 
    Activity activity; 

    public ListListener(List<RssItem> aListItems, Activity anActivity) { 
    listItems = aListItems; 
    activity = anActivity; 
    } 

/** 
* Start a browser with url from the rss item. 
*/ 
    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { 
    //Intent i = new Intent(Intent.ACTION_VIEW); 
    //i.setData(Uri.parse(listItems.get(pos).getLink())); 
    Intent i = new Intent(activity, WebPageActivity.class); 
    i.putExtra("LINK", Uri.parse(listItems.get(pos).getLink())); 
    //Intent intent = new Intent(this, WebPageController(listItems.get(pos).getLink())); 
    activity.startActivity(i); 

    } 

} 

而且從onItemClick它應該調用的WebView活動,以顯示該網頁

public class WebPageActivity extends ActionBarActivity { 
    private WebView webview; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     Intent intent = getIntent(); 
     String url = intent.getStringExtra("LINK"); 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_web_page); 

     WebSettings webSettings = webview.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 
     webview = (WebView) findViewById(R.id.webView1); 
     webview.getSettings().setJavaScriptEnabled(true); 
     webview.loadUrl(url); 
    } 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.web_page, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
    } 
    } 

有一個在編譯沒有錯誤,但是當我在應用程序中單擊去停止好康活動。 這裏是我的logcat http://pastie.org/9606345

+1

顯示你的logcat,並確定這是因爲你的listItems – k0sh 2014-09-30 04:58:26

+0

1.確保你在Manifest文件中聲明瞭WebPageActivity.java。 2.請發佈logcat輸出 – 2014-09-30 04:58:36

+0

發佈您的logcat錯誤 – appukrb 2014-09-30 05:51:04

回答

0

與此代碼替換您的onCreate:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     Intent intent = getIntent(); 
     String url = intent.getStringExtra("LINK"); 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_web_page); 

     webview = (WebView) findViewById(R.id.webView1); 
     WebSettings webSettings = webview.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 

     webview.getSettings().setJavaScriptEnabled(true); 
     webview.loadUrl(url); 
    } 

的問題是,你能WebSettings之前定義的WebView ID。

+0

不行,沒有工作 – Ophelia 2014-09-30 06:19:52

0

試試如下:

public class WebPageActivity extends ActionBarActivity { 
    private WebView webview; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_web_page); 

     Intent intent = getIntent(); 
     String url = intent.getStringExtra("LINK"); 

     webview = (WebView) findViewById(R.id.webView1); 
     WebSettings webSettings = webview.getSettings(); 
     webSettings.setJavaScriptEnabled(true); 

     webview.getSettings().setJavaScriptEnabled(true); 
     webview.loadUrl(url); 
    } 
0

檢查這個Answer,它說你需要修復你的項目的依賴關係爲「根」,然後再「SRC」。試一試。它應該解決ClassDefNotFound error