Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipse Android config file always returns null
    primarykey
    data
    text
    <p>Currently in the process of creating a testing framework for Android via Eclipse and JUnit. The last thing I'm implementing is a Configuration file and reader so that the config file can be used to change various properties when necessary. The structure of my framework is as follows:</p> <pre><code>MainFramework (project) Base package Utility package Config class Testing (project) examples package Artist testing class </code></pre> <p>The Config class is as follows:</p> <p>public class Config {</p> <pre><code>private static Config instance; public Context context; public static Properties prop; public static StorefrontConfig getInstance(Context context) { if(instance == null) instance = new StorefrontConfig(context); return instance; } protected StorefrontConfig(Context cont) { context = cont; AssetManager manager = context.getAssets(); try { InputStream instream = manager.open("config"); readConfig(instream); } catch (Exception e) { Log.d("cool", "Failed to create properly initialized config class"); } } private static void readConfig(InputStream instream) { try { String line = ""; BufferedReader read = new BufferedReader(new InputStreamReader(instream)); while ((line = read.readLine()) != null) { String[] split_line = line.split("=", 2); prop.setProperty(split_line[0], split_line[1]); } prop.store(new FileOutputStream("config.properties"), "Default and local config files"); read.close(); } catch (Exception e) { Log.d("cool", "Failed to create properly initialized config class"); } } public String getProperty (String propertyKey) { try { return prop.getProperty(propertyKey); } catch (Exception e) { Log.d("cool", "Failed to access property"); return null; } } public Context getContext () { return context; } </code></pre> <p>When I call the getProperty() method in my code, it always returns null. However, I have no idea if it is failing to initially read and write the values or what is going on. All I know is that my program works with hard-coded values but not when using this class and referencing it via config.getProperty() in the code where needed (my main framework has a Config class that is inherited by all the tests).</p> <p>Any help would be really appreciated. Only thing I can think of is that Java's Properties class cannot be used with Android?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload