gpt4 book ai didi

android - 更改为Gridview应用程序现在会崩溃?

转载 作者:行者123 更新时间:2023-12-03 16:35:14 39 4
gpt4 key购买 nike

因此,我有一个RSS feed应用程序,但当前遇到一些问题。我将其移至基于网格的应用程序而不是列表 View ,但是由于应用程序不断崩溃而遇到了一些问题,并且我做了很多更改,使我开始迷失了方向。所以我的问题是,您能否看一下下面的代码,让我知道是什么导致它崩溃?

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

这是我的日志:

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

最佳答案

通过使用ListActivity,Android希望在布局中使用ListView。我没有深入研究,但是您可以尝试将ListActivity更改为Activity。

关于android - 更改为Gridview应用程序现在会崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8998032/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com