无法访问Java中另一个类中方法的返回实例

塞巴斯蒂安·泽基(Sebastian Zeki)

我正在尝试从Java中的另一个类访问填充的HashMap。由于某种原因,我不能。我认为该代码是正确的,但显然我遗漏了一些东西。hashMap可以很好地填充,但是我无法访问它。

 public class Main {
    public static String HospNum;
    public static Map<String,String> mapAllBreathTest= new LinkedHashMap<String,String>();

        public static void main(String[] args) throws IOException, TikaException, SQLException {

                String str = //Extracted text file ;
                String HospNum="1234"
                BreathTestExtractorMethods BT =new BreathTestExtractorMethods(HospNum);
                System.out.println(mapAllBreathTest); //EMPTY HASHMAP RETURNED
                }
        }

该类被称为:

    public class BreathTestExtractorMethods {
     public String HospNum;
     public Map<String,String> mapAllBreathTest= new LinkedHashMap<String,String>();


        public BreathTestExtractorMethods(String HospNum) {
            BreathTestExtractorMethods.HospNum=HospNum;
        }

        public Map<String,String> NameExtractor(String str){
            Pattern match_pattern = Pattern.compile("Patient Name(.*)Date",Pattern.DOTALL);
            Matcher matchermatch_pattern = match_pattern.matcher(str);
            if (matchermatch_pattern.find()) {
                String[] PtName=matchermatch_pattern.group(1).toString().trim().split("\\s");
                mapAllBreathTest.put("Sname",PtName[0].trim());
                mapAllBreathTest.put("Fname",PtName[1].trim());


            }
            return mapAllBreathTest; //THIS IS A POPULATED HASHMAP
    }
施泰菲

班上有一个Map电话然后,在您的班级中,您还有另一个对象称为负责填充而且它从未被调用过。mapAllBreathTestMainBreathTestExtractorMethodsMapmapAllBreathTestNameExtractormapAllBreathTest

因此,您main应该调用以下NameExtractor方法BreathTestExtractorMethods

String str = //Extracted text file ;
String HospNum="1234"
BreathTestExtractorMethods BT =new BreathTestExtractorMethods(HospNum);
mapAllBreathTest = BT.NameExtractor("RIGHT STRING TO PASS");
System.out.println(mapAllBreathTest);

祝你好运。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何通过在Javascript另一个类的实例访问另一个类中的方法

Java:如何从另一个类访问方法

从Java中的另一个类访问变量

如何访问Java中另一个类的另一个方法内的类中的方法

Kotlin中另一个类中的密封类无法编译:无法访问“ <init>”,因为它是私有的

不明白为什么我无法访问导致另一个类方法的结果

我无法访问Java中另一个类的变量值

在另一个类方法中存储一个类的实例

无法从Visual Studio C ++中的另一个类访问一个类

使用Java中另一个类的另一个方法返回用户输入

无法访问另一个QML的属性

无法访问在另一个模块中设置的类实例变量

从Android中的另一个类访问方法

无法访问Requirejs模块中的另一个类

如何在另一个类中访问此实例方法

重新启动后无法访问另一个类中的SharedPreferences值

访问从其实例化另一个类的类的方法

如何从另一个类调用对象-无法访问

无法从Java中的另一个类访问变量?

从Java中的另一个类访问变量

Java如何使用另一个类的实例访问方法

无法从java中的另一个类访问一个类

Java - 无法访问另一个类中的数组列表

试图访问另一个类中的方法

Python类:一个类中的实例方法指向另一个类中的实例方法

python中访问另一个类的方法

无法从 JAVA 中同一类的另一个方法调用方法

如何从另一个类中的另一个函数访问新的实例化类方法?

访问另一个类中 main 中定义的类的实例