当我尝试运行程序时,这就是计算机返回的内容:
First_Name Last_Name Test1 Test2 Test3 Test4 Test5平均成绩
线程中的异常" main" java.lang.NullPointerException at tests.Tests.main(Tests.java:132)C:\ Users \ Michael Jr \ AppData \ Local \ NetBeans \ Cache \ 8.1 \ executor-snippets \ run.xml:53:Java 返回:1 BUILD FAILED(总时间:0秒)
# -*- coding: utf-8 -*-
from robot.libraries.BuiltIn import BuiltIn
class global_hooks(object):
"""
Global scope library listener
as global hook mechanism.
"""
ROBOT_LISTENER_API_VERSION = 3
ROBOT_LIBRARY_SCOPE = "GLOBAL"
def __init__(self):
self.ROBOT_LIBRARY_LISTENER = self
def __log_variables(self):
"""
Example private function.
"""
if BuiltIn().get_variable_value(name='${SOME_VAR}', default=False):
BuiltIn().run_keyword(name=self.log_test_variables.__name__)
def end_test(self, data, result):
""" The `end test` hook """
self.__log_variables()
def log_test_variables(self):
"""
Keyword for showing up all variables in the test context.
"""
BuiltIn().log_variables(level='INFO')
答案 0 :(得分:0)
您应该检查您的阅读功能的结果:
public static void main(String[] a)
{
ArrayList<Tests> ar=read("E:/score.txt");
if (ar != null){
System.out.println("First_Name\tLast_Name\tTest1\t\tTest2\t\tTest3\t\tTest4 \t\tTest5\t\tAverage\t\tGrade");
for(Tests e:ar)
{
System.out.println(e);
}
} else {
System.out.println("Could not read file");
}
}
答案 1 :(得分:0)
你在验证try
语句吗?,read函数返回'Null'值。我认为这个问题出在您阅读文件时。
String sCurrentLine;
ArrayList<Tests> ar=new ArrayList<Tests>();
br = new BufferedReader(new FileReader("C:\\Users\\Michael Jr\\Desktop\\ch9_Ex13Data.txt"));
while ((sCurrentLine = br.readLine()) != null)
{
ar.add(new Tests(sCurrentLine));
}
return ar;
如果您能够共享该文件,我将验证此代码是正确的!