繁体   English   中英

java.lang.NullPointerException: inStream 参数是 null 在我的 Maven 项目中

[英]java.lang.NullPointerException: inStream parameter is null in my Maven Project

我在我的项目中进行了结构更改,我收到了这个错误

项目结构:在此处输入图片描述

平台通知我以下错误:

Step failed
java.lang.NullPointerException: inStream parameter is null
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at java.base/java.util.Properties.load(Properties.java:407)
at com.crm.framework.config.ConfigReader.ReadProperty(ConfigReader.java:19)
at com.crm.framework.config.ConfigReader.PopulateSettings(ConfigReader.java:11)
at steps.TestInitialize.Initialize(TestInitialize.java:21)

这是我的 ConfigReader,在上面的错误 ConfigReader 中显示:

package com.crm.framework.config;
import com.crm.framework.base.BrowserType;
import java.io.IOException;
import java.util.Properties;

public class ConfigReader {

public static void PopulateSettings() throws IOException {
    ConfigReader reader = new ConfigReader();
    reader.ReadProperty();
}


private void ReadProperty() throws IOException {
    //Create Property Object
    Properties p = new Properties();
    //Load the property file available in same package
    p.load(getClass().getResourceAsStream("GlobalConfig.properties"));
    //Get AUTConnection String
    Settings.AUTConnectionString = p.getProperty("AUTConnectionString");
    //Get Reporting String
    Settings.ReportingConnectionString = p.getProperty("ReportingConnectionString");
    //Get LogPath
    Settings.LogPath = p.getProperty("LogPath");
    //Get DriverType
    Settings.DriverType = p.getProperty("DriverType");
    //Get ExcelSheetPath
    Settings.ExcelSheetPath = p.getProperty("ExcelSheetPath");
    //Get AUT
    Settings.AUT = p.getProperty("AUT");
    //Browser Type
    Settings.BrowserType = BrowserType.valueOf(p.getProperty("BrowserType"));
}
}

我还附上了 TestInitialize 的代码,该文件包含 @Before 以运行测试用例 TestInitialize:

package steps;

import com.crm.framework.base.DriverContext;
import com.crm.framework.base.FrameworkInitialize;
import com.crm.framework.config.ConfigReader;
import com.crm.framework.config.Settings;
import com.crm.framework.utilities.LogUtil;
import io.cucumber.java.Before;


// import io.cucumber.java.Before;


import java.io.IOException;

public class TestInitialize extends FrameworkInitialize {

@Before
public void Initialize() throws IOException {
    //Initialize config
    ConfigReader.PopulateSettings();

    //Logging
    Settings.Logs = new LogUtil();
    Settings.Logs.CreateLogFile();
    Settings.Logs.Write("Framework initialize");

    //Create Test Cycle for Reporting
        /*
        Pending
         */

    Settings.Logs.Write("Test Cycle Created");
    InitializeBrowser(Settings.BrowserType);
    Settings.Logs.Write("Browser initialize");
    DriverContext.Browser.GotoUrl(Settings.AUT);
    Settings.Logs.Write("Navigate to URL: " + Settings.AUT);
}
}

这是最可能的罪魁祸首: https://docs.oracle.com/javase/10/docs/api/java/util/Properties.html#getProperty(java.lang.String)

来自 Javadoc:

公共字符串 getProperty(字符串键)

在此属性列表中搜索具有指定键的属性。 如果在该属性列表中未找到该键,则递归地检查默认属性列表及其默认值。 如果未找到该属性,则该方法返回 null

属性区分大小写。 确保:

  1. 你需要的属性文件存在,那么
  2. 文件内的属性键存在,最后
  3. 它的拼写方式与它在文件中的显示方式完全相同。

作为故障保护,您可以使用与上述类似的getProperty(key, defaultValue) ,除了在传递给方法的属性键不存在于给定的属性文件。

此外,请确保属性文件的 PATH 是正确的。 如果您不了解资源是如何解决的,那么在从 IDE 和部署环境运行时如何解决文件路径也可能是一个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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