2012-01-25 16 views
0

所以我有一個RSS提要應用程序,但我目前有一些問題。我將它移動到一個基於網格的應用程序而不是一個列表視圖,但當應用程序不斷崩潰時,我遇到了一些問題,並且我已經改變了很多我開始失去蹤跡的事情。所以我的問題是你可以看看下面的代碼,讓我知道是什麼導致它崩潰?更改爲gridview應用程序現在崩潰?

package com.gamemaker.bob; 

import java.util.ArrayList; 
import java.util.List; 

import com.gamemaker.bob.R; 
import com.google.ads.AdRequest; 
import com.google.ads.AdView; 

import android.app.ListActivity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 

import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import android.widget.AbsListView.LayoutParams; 
import android.widget.ArrayAdapter; 
import android.widget.BaseAdapter; 
import android.widget.GridView; 
import android.widget.ListView; 
import android.widget.TabHost; 
import android.widget.TabHost.TabSpec; 
import android.widget.TextView; 


public class MessageList extends ListActivity { 

    private List<Message> messages; 
    AdView adView; 
    WebView webview; 
    protected int position; 

    private class WebcadeViewClient extends WebViewClient { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    } 

    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main); 
     TabHost tabHost = (TabHost)findViewById(R.id.tabHost); 
     tabHost.setup(); 
     Resources res = getResources(); 

     GridView gridview = (GridView) findViewById(R.id.GridView); 
     gridview.setAdapter(new MyAdapter(this)); 

     TabSpec spec1 = tabHost.newTabSpec("Tab 1"); 
     spec1.setContent(R.id.tab1); 
     spec1.setIndicator("GameMakerBlog" , res.getDrawable(R.drawable.ic_tab_blog)); 

     TabSpec spec2 = tabHost.newTabSpec("Tab 2"); 
     spec2.setContent(R.id.tab2); 
     spec2.setIndicator("Community" , res.getDrawable(R.drawable.ic_tab_com)); 

     webview = (WebView) findViewById(R.id.webview); 
     webview.getSettings().setJavaScriptEnabled(true); 
     webview.getSettings().setPluginsEnabled(true); 
     webview.getSettings().setSupportZoom(false); 
     webview.setVerticalScrollBarEnabled(false); 
     webview.setHorizontalScrollBarEnabled(false); 
     webview.getSettings().setUseWideViewPort(false); 
     webview.loadUrl("http://bobhoil.com/android/"); 
     webview.setWebViewClient(new WebcadeViewClient()); 
     adView = (AdView) findViewById(R.id.adView); 
     adView.loadAd(new AdRequest()); 
     tabHost.addTab(spec1); 
     tabHost.addTab(spec2);; 

     } 


    public class MyAdapter extends BaseAdapter { 

     private Context mcontext; 

     public MyAdapter(Context c) { 
      mcontext = c; 
     } 

     public int getCount() { 
      return messages.size(); 
      } 

     public Object getItem(int position) { 
      return null; 
     } 

     public long getItemId(int position) { 
      return 0; 
     } 

     public View getView(int position, View convertView, ViewGroup parent) { 
      TextView textView; 
      if (convertView == null) { // if it's not recycled, initialize some attributes 
       textView = new TextView(mcontext); 
       textView.setLayoutParams(new GridView.LayoutParams(85, 85)); 
       textView.setPadding(8, 8, 8, 8); 
      } else { 
       textView = (TextView) convertView; 
      } 
      BaseParseGM parser = new BaseParseGM(); 
      messages = parser.parse(); 
      List<String> titles = new ArrayList<String>(messages.size()); 
      for (Message msg : messages){ 
       titles.add(msg.getTitle()); 
      } 
      textView.setTag(titles); 
      return textView; 
     } 
    } 
} 

這是我的logcat:

03-04 14:16:19.238:ERROR/AndroidRuntime(11659):致命異常:主 03-04 14:16:19.238:ERROR/AndroidRuntime(11659): java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.gamemaker.bob/com.gamemaker.bob.MessageList}: java.lang.RuntimeException:您的內容必須有一個ListView,其ID爲 屬性是'android.R.id.list'03-04 14:16:19.238: 錯誤/ AndroidRuntime(11659):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 03-04 14:16:19.238:ERROR/AndroidRuntime(11659):在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at android.app.ActivityThread.access $ 600(ActivityThread.java:123)03-04 14:16:19.238:ERROR/AndroidRuntime(11659): at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147) 03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at android.os.Handler.dispatchMessage(Handler.java:99 )03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at android.os.Looper.loop(Looper.java:137)03-04 1 4:16:19.238: 錯誤/ AndroidRuntime(11659):在 android.app.ActivityThread.main(ActivityThread.java:4424)03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at java .lang.reflect.Method.invokeNative(Native Method)03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at java.lang.reflect.Method.invoke(Method.java:511)03-04 14:16:19.238: 錯誤/ AndroidRuntime(11659):在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784) 03-04 14:16:19.238:ERROR/AndroidRuntime( 11659):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at dalv ik.system.nativestart.main(本地方法)03-04 14:16:19.238: 錯誤/ AndroidRuntime(11659):由於:java.lang.RuntimeException: 您的內容必須具有ListView,其id參數爲 ' android.R.id.list'03-04 14:16:19.238:ERROR/AndroidRuntime(11659):
at android.app.ListActivity.onContentChanged(ListActivity.java:243) 03-04 14:16:19.238 :ERROR/AndroidRuntime(11659):at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254) 03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at android .app.Activity.setContentView(Activity.java:1835)03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at com.gamemaker.bob.MessageList.o nCreate(MessageList.java:47)03-04 14:16:19.238:ERROR/AndroidRuntime(11659):at android.app.Activity.performCreate(Activity.java:4465)03-04 14:16:19.238 :ERROR/AndroidRuntime(11659):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 03-04 14:16:19。238:ERROR/AndroidRuntime(11659):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 03-04 14:16:19.238:ERROR/AndroidRuntime(11659):... 11更

+2

它更好,如果你提供logcat信息.. – user370305

+0

過去一段時間,因爲我發佈了這個問題,但我已經包括一個logcat。 –

回答

2

通過使用ListActivity,Android需要在佈局中使用ListView。我沒有深入瞭解,但可以嘗試將ListActivity更改爲「活動」。

相關問題