开发者

Why keep throws Rescources.NotFoundException?

In the following code, these lines:

score.setText(shops[i].getScore());

and icon.setImageResource(R.drawable.test1);

the app keep throws the Resources.NotFoundException. I checked the XML file, all the ids are开发者_如何转开发 defined and they are all in the R.java. So I really don't know why the app throw this exception. Could anyone help me on this problem? Thank you very much!!!

try{
    TextView name= (TextView)findViewById(R.id.name);
    TextView description = (TextView)findViewById(R.id.description);
    TextView score = (TextView)findViewById(R.id.score);
    ImageView icon = (ImageView)findViewById(R.id.icon);

    name.setText(shops[i].getName());
    description.setText(shops[i].getDescription());
    score.setText(shops[i].getScore());

    UrlImage urlImage = new UrlImage(context,shops[i].getIconUrl());
    Drawable drawable = urlImage.getDrawable(context);
    if(drawable!=null){
        icon.setImageDrawable(urlImage.getDrawable(context));
    }else{
        icon.setImageResource(R.drawable.test1);
    }
}catch(NotFoundException e){
    Toast.makeText(walkstreet.this,
        "marker"+i,
        Toast.LENGTH_SHORT).show();
}


Inside of Eclipse, try doing a Project > Force Clean. Outside of Eclipse, delete your bin/ and gen/ directories. In either case, after doing the above, try rebuilding.

Sometimes, when you add resources, Android changes the resource ID numbers but does not recompile everywhere those numbers are used.


It ends up it is data type problem.... Integer cannot be put in the setText(). lol Interesting how the exception is not related at all. and the compiler do not throw any error when it is being compliled.


When I encounter this king of 'weird' issues with *.xml resources I add one more item. I case of strings.xml I add new item and that CTRL+S the project will be rebuild and the R class will be refreshed. This usually fix the problems, and afterwards I delete the item that I added.

There are a lot of times when eclipese doesn't rebuild until you add something new (that it , until you make a change in your resources)

I hope this will help you if not , it might help to someone else having similar problems

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜