Android project custom profile to resolve getResourceAsStream () Return null

tags: Android  

Returns NULL is the path error. After multiple attempts, use the following method to solve

1. Create an Assets folder, create a new config.properties file

2.config.properties file content

# Request address
IP=192.168.1.101:8080

loginurl=http://192.168.1.101:8080/assets/login.html

3. Create a package Until, create a new utils.java file

4.Utils.java read configuration file content

public class utils {
    public static Properties getNetConfigProperties() {
        Properties props = new Properties();
        InputStream in = utils.class.getResourceAsStream("/assets/config.properties");

        try {
            props.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return props;
    }
}

5. Use

 String loginurl = utils.getNetConfigProperties().getProperty("loginurl");

Intelligent Recommendation

Android Butterknife controls return NULL

One of the reasons for this problem may be that in the Layout page, there is an Include quoting block, butterknife and initialized reference block layout, which is caused. Problem code: layout code In...

Log4J custom profile (SpringMVC project)

Source of the problem This week, the error log level file that cannot be customized in the actual project cannot be customized, and the default INFO level log is still printed after the project is sta...

Solve the null problem with getResourceAsStream in IntelliJ IDEA

To solve this problem is very simple: windows version press the shortcut key alt + shift + ctrl + s mac:command + ; Enter the module configuration, select the module you are using, click sources, crea...

Record that the content of the json file obtained with getResourceAsStream is null

Yesterday I wanted to use getResourceAsStream to get the content of the json file in the resources, and found that it was always null Finally, I changed the uppercase of the first letter of the file n...

getResourceAsStream gets the time null pointer exception

background: I have written a springboot+testng project. The project needs to be run through the mvn test command, but the getResourceAsStream method has been reporting errors and cannot run At that ti...

More Recommendation

ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties"); Times null pointer exception

When connecting to the database, I reported this 500, thinking that there was a problem with the server deployment, and then the java code soon created a new Test test connection database. I found tha...

Huawei cell phone call to resolve Safe return value is null problem

In system development projects need to call the album, to be able to get a normal return values ​​on other android phone, but Huawei is the return value is null, please see the code below After the ab...

Resolve the return JSON data, the property value is NULL or empty omissions.

When using com.alibaba.fastjson.support.spring.fastjsonhttpMessageConverter Transition Returns to JSON, it will be omitted to an attribute value of empty NULL. The solution is equipped with the proces...

Use Java to open the image and resolve imageio.read () Return null

Use Java to open the picture: Solve Imageio.Read () Returns NULL: In useImageIO.read()The method may encounter a problem, that is, I have entered the image address, howeverImageIO.read()Returning isnu...

getResourceAsStream

directory structure src:reflect/ReflectTest2.java reflect/resource/config.properties The class's getResourceAsStream is relative to the class loader directory path of the current class. The current pa...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top