Why can't I use Resources.getSystem() without a Runtime error?

后端 未结 3 1220
孤城傲影
孤城傲影 2020-11-29 12:29
public class BobDatabase extends SQLiteOpenHelper{
private static final String DATABASE_NAME = \"bob.db\";
private static final int DATABASE_VERSION = 1;
public stat         


        
3条回答
  •  眼角桃花
    2020-11-29 12:52

    Using Resources.getSystem().getWhatEver() you can only access system-wide resources (you get the error because there is no system-wide resource with your ID). Since resource ID are not unique across applications you need to provide the application, when accessing a resource. In Android this is done using Context. So if you want to access some resource you need to use it like this

    context.getResources().getString(myID);
    

    Apart from that Brandon's comment is correct.

提交回复
热议问题