0
votes

So I have an RSS feed application but am currently having some problems. I am moving it over to a gridbased application instead of a listview but am having some problems as the application keeps crashing and I have changed so many things I am starting to lose track. So my question is can you look at the code below and let me know what is causing it to crash?

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;
        }
    }
}

Here is my logcat:

03-04 14:16:19.238: ERROR/AndroidRuntime(11659): FATAL EXCEPTION: main 03-04 14:16:19.238: ERROR/AndroidRuntime(11659): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gamemaker.bob/com.gamemaker.bob.MessageList}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 03-04 14:16:19.238: ERROR/AndroidRuntime(11659): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 03-04 14:16:19.238: ERROR/AndroidRuntime(11659): at 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 14:16:19.238: ERROR/AndroidRuntime(11659): at 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: ERROR/AndroidRuntime(11659): at 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 dalvik.system.NativeStart.main(Native Method) 03-04 14:16:19.238: ERROR/AndroidRuntime(11659): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is '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.onCreate(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): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 03-04 14:16:19.238: ERROR/AndroidRuntime(11659): ... 11 more

1
Its a better if you provide logcat information..user370305
Been a while since I posted on this question but I have included a logcat.Greg Froning

1 Answers

2
votes

By using ListActivity Android expects a ListView in your layout. I didn't take a deep look but you can try to change ListActivity into Activity.