Android 无法声明按钮,Eclipse不断抛出错误

Android 无法声明按钮,Eclipse不断抛出错误,android,button,layout-inflater,Android,Button,Layout Inflater,我正试图放置一个按钮,但我不知道为什么Eclipse一直向我抛出这个错误“局部变量按钮可能尚未初始化”。我在xml文件“rssfeedapter\u布局”中添加了一个按钮。但我不能在代码中调用它。我正在尝试: RssReaderListAdapter.java package com.rssfeed.adapter; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection

我正试图放置一个按钮,但我不知道为什么Eclipse一直向我抛出这个错误“局部变量按钮可能尚未初始化”。我在xml文件“rssfeedapter\u布局”中添加了一个按钮。但我不能在代码中调用它。我正在尝试:

RssReaderListAdapter.java

package com.rssfeed.adapter;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.rssfeed.R;
import com.rssfeed.helper.RssFeedStructure;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class RssReaderListAdapter extends ArrayAdapter<RssFeedStructure> {

List<RssFeedStructure> imageAndTexts1 =null;
public RssReaderListAdapter(Activity activity, List<RssFeedStructure> imageAndTexts) {
super(activity, 0, imageAndTexts);
imageAndTexts1 = imageAndTexts;

}


@Override
public View getView(int position, View convertView, ViewGroup parent) {

Activity activity = (Activity) getContext();
LayoutInflater inflater = activity.getLayoutInflater();


View rowView = inflater.inflate(R.layout.rssfeedadapter_layout, null);
TextView title = (TextView) rowView.findViewById(R.id.feed_text);
TextView description = (TextView) rowView.findViewById(R.id.feed_updatetime);
ImageButton button = (ImageButton) button.findViewById(R.id.button_web);//Eclipse keeps throwing error in this line
ImageView imageView = (ImageView) rowView.findViewById(R.id.feed_image);
ImageLoader imgLoader;
imgLoader = new ImageLoader(activity);
        Log.d("rssfeed", "imageAndTexts1.get(position).getImgLink() :: " +imageAndTexts1.get(position).getImgLink() +" :: " +imageAndTexts1.get(position).getTitle());
        title.setText(imageAndTexts1.get(position).getTitle());
        description.setText(imageAndTexts1.get(position).getDescription());
        if(imageAndTexts1.get(position).getImgLink() !=null){

            String imageUrl= imageAndTexts1.get(position).getImgLink();
            imgLoader.DisplayImage(imageUrl, imageView);

            }

return rowView;

}

}
package com.rssfeed.adapter;
导入java.io.IOException;
导入java.io.InputStream;
导入java.net.HttpURLConnection;
导入java.net.MalformedURLException;
导入java.net.URL;
导入java.util.List;
导入org.json.JSONException;
导入org.json.JSONObject;
导入com.rssfeed.R;
导入com.rssfeed.helper.rssfeed结构;
导入android.app.Activity;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.text.SpannableString;
导入android.text.span;
导入android.text.style.UnderlineSpan;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.ImageButton;
导入android.widget.ImageView;
导入android.widget.TextView;
公共类RssReaderListAdapter扩展了ArrayAdapter{
列表imageAndTexts1=null;
公共RssReaderListAdapter(活动、列表图像和文本){
超级(活动、0、图像和文本);
imageAndTexts1=图像和文本;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
活动活动=(活动)getContext();
LayoutInflater充气器=活动。getLayoutInflater();
视图行视图=充气机。充气(R.layout.rssfeedapter\u布局,null);
TextView title=(TextView)rowView.findViewById(R.id.feed_text);
TextView description=(TextView)rowView.findViewById(R.id.feed\u updatetime);
ImageButton=(ImageButton)button.findViewById(R.id.button_web);//Eclipse一直在这一行中抛出错误
ImageView ImageView=(ImageView)rowView.findViewById(R.id.feed_image);
图像加载器;
imgLoader=新图像加载程序(活动);
Log.d(“rssfeed”,“imageAndTexts1.get(position).getImgLink()::”+imageAndTexts1.get(position).getImgLink()+”:“+imageAndTexts1.get(position).getTitle());
title.setText(imageAndTexts1.get(position.getTitle());
description.setText(imageAndTexts1.get(position.getDescription());
if(imageAndTexts1.get(position).getImgLink()!=null){
字符串imageUrl=imageAndTexts1.get(position.getImgLink();
显示图像(imageUrl,imageView);
}
返回行视图;
}
}
使用

而不是

ImageButton button = (ImageButton) button.findViewById(R.id.button_web);
您需要使用
行视图
rssfeedapter\u布局
布局中获取初始化按钮,而不是按钮

更改:

button.findViewById(R.id.button_web);
致:


不应该
button.findViewById(R.id.button\u web)
be
rowView.findViewById(R.id.button\u web)
?这些小错误让我心碎。。。我想是因为疲劳。谢谢你的回答,这是唯一的问题。
button.findViewById(R.id.button_web);
rowView.findViewById(R.id.button_web);