gpt4 book ai didi

android - 致命异常 : Main eclipse error

转载 作者:行者123 更新时间:2023-11-29 21:58:12 25 4
gpt4 key购买 nike

这是我的日志猫:

enter image description here

它说 Fatal Exception : Mainres.resources not found,还有很多其他错误。怎么回事?

这是我的主要 Activity :

public class MainActivity extends Activity {

private final static String highscore = "Your High Score : ";
private ListView listMenu;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ListMenu listMenuData[] = new ListMenu[]
{
new ListMenu(R.drawable.repetition, "Repetition\n" + highscore, 0)
};

ListMenuAdapter adapter = new ListMenuAdapter(this, R.layout.listmenu_item, listMenuData);

listMenu = (ListView)findViewById(R.id.listMenu);

View header = (View)getLayoutInflater().inflate(R.layout.listmenu_header, null);
listMenu.addHeaderView(header);

listMenu.setAdapter(adapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

这是 ListMenu,用于 setter-getter :

public class ListMenu {
public int icon, highscore;
public String title;

public ListMenu(){
super();
}

public ListMenu(int icon, String title, int highscore){
super();
this.icon = icon;
this.title = title;
this.highscore = highscore;
}

这是我的 ListMenuAdapter 类:

public class ListMenuAdapter extends ArrayAdapter<ListMenu> {
Context context;
int layoutResourceId;
ListMenu listmenu[] = null;

static class MenuHolder{
ImageView imgMenuIcon;
TextView txtTitle, txtHighScore;
}

public ListMenuAdapter (Context context, int layoutResourceId, ListMenu[] listmenu){
super(context, layoutResourceId, listmenu);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.listmenu = listmenu;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
MenuHolder holder = null;

if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);

holder = new MenuHolder();
holder.imgMenuIcon = (ImageView)row.findViewById(R.id.imgMenuIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.txtHighScore = (TextView)row.findViewById(R.id.txtHighScore);

row.setTag(holder);
}
else holder = (MenuHolder)row.getTag();

ListMenu menu = listmenu[position];
holder.imgMenuIcon.setImageResource(menu.icon);
holder.txtTitle.setText(menu.title);
holder.txtHighScore.setText(menu.highscore);

return row;
}

我遵循并修改了本教程中的代码:click here

有人说 android.content.res.resources$NotFoundException 错误可以通过清理项目/重启 Eclipse 来修复,但它对我不起作用

抱歉发了这么长的帖子,我真的不知道现在该怎么办谢谢:D

最佳答案

如果是这样,那就是问题所在。你应该这样做:

holder.txtHighScore.setText(""+menu.highscore);

由于 menu.highscoreint,它将调用方法 setText(int resId) 加载您定义的关联资源 ID你的 strings.xml

如果你输入 ""+menu.highscore,它会调用你想要的 setText(CharSequence text)

关于android - 致命异常 : Main eclipse error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667099/

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