简体   繁体   中英

Android java, error during import of string from string.xml with getString()

i have a problem. I'm creating an application that stores data in the cell , but first create a folder that will contain the various files . This folder will have the name of the app, but continuoa receive an error at that point.

Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f060014

The class is:

public class Config {

private Properties configuration;
public static String root = Resources.getSystem().getString((R.string.app_name)) + "_data_file";
public File cartella = new File(Environment.getExternalStorageDirectory() + "/Android/obb/"+ root);
private String configurationFile = Environment.getExternalStorageDirectory() + "/Android/obb/"+ root  + "/config.ini";

and String.xml is:

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Il Maestro</string>
    <string name="homefrontextb">Per iniziare,completa il modulo.</string>
    <string name="homefrontext">Per iniziare,seleziona la tua lingua.</string>
    <string name="action_settings">Settings</string>
    <string name="sondaggiopub">Come hai conosciuto quest\' app?</string>
    <string name="Pubblicita">Pubblicità</string>
    <string name="socialnetwork">Social Network</string>
    <string name="amici">Consigliata dagli amici</string>
    <string name="store">Visita casuale sullo store</string>
    <string name="namehome">Nome</string>
    <string name="cognomehome">Cognome</string>
    <string name="nickhome">Nickname</string>
    <string name="emailhome">Email</string>
</resources>

However , when I try to get the string as int , it works , and I get the number " 2131099668 "

Please help me , I'm going crazy ..

Resources.getSystem() retrieves the System's resources, not the one specific of your app. From the doc

Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

You need your app's context to access your specific resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM