From 40866ddba74761f4fd7ed24d9e2415beb4ca1b8e Mon Sep 17 00:00:00 2001 From: Programmers3539 Date: Fri, 3 Feb 2023 19:02:23 -0500 Subject: [PATCH] Update INIConfig.java --- .../INIConfiguration/INIConfig.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java b/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java index 87b26f8..1a2cad9 100644 --- a/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java +++ b/src/main/java/org/bytingbulldogs/bulldoglibrary/INIConfiguration/INIConfig.java @@ -11,6 +11,8 @@ import org.ini4j.Wini; import org.ini4j.Profile.Section; +import edu.wpi.first.wpilibj.DriverStation; + /** Add your docs here. */ public class INIConfig { Wini ini; @@ -26,21 +28,27 @@ public INIConfig(String filename) { } public void autoPopulate(Object o) { - Field[] fields = o.getClass().getFields(); - for (Field field : fields) { - String[] split = field.getName().split("_"); - int length = split.length; - if (length >= 2) { - try { - - field.set(o, getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType())); + if (ini != null) { + Field[] fields = o.getClass().getFields(); + for (Field field : fields) { + String[] split = field.getName().split("_"); + int length = split.length; + if (length >= 2) { + try { + + if(getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType())!=null) + { + field.set(o, + getOrDefault(split[split.length - 2], split[split.length - 1], null, field.getType())); + } - } catch (IllegalArgumentException | IllegalAccessException e) { - // DriverStation.reportWarning("Could not load item "+field.getName()+" from - // file "+iniConfig.getFileName(), e.getStackTrace()); + } catch (IllegalArgumentException | IllegalAccessException e) { + DriverStation.reportWarning("Could not load item " + field.getName() + " from file " + filename, + e.getStackTrace()); + } } + field.getType(); } - field.getType(); } }