gpt4 book ai didi

java - 有没有办法摆脱我得到的这个空指针异常?

转载 作者:行者123 更新时间:2023-12-03 08:55:38 25 4
gpt4 key购买 nike

以下代码显示了空指针异常

private void _settooltip() {
localXYLineAndShapeRenderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
//String toolTip = getToolTipText();
// return toolTip;
CurveSegment segment = (CurveSegment) curveEncapsulator.getSegment(currentCurve);
if (segment != null) {
segment.getA();
segment.getB();
segment.getC();
}


double A = segment.getA();
double B = segment.getB();
double C = segment.getC();


String AA = String.valueOf(A);
String BB = String.valueOf(B);
String CC = String.valueOf(C);


return "A = " + AA + " B = " + BB + " C = " + CC;



}
});
}

我正在异常(exception)

public String generateToolTip(XYDataset数据集,int系列,int项)

谁能告诉我如何处理此空指针异常?

最佳答案

该错误可能与“段”有关,您可以像这样尝试sthg;

        double A = 0;
double B = 0;
double C = 0;

String AA = "";
String BB = "";
String CC = "";

if (segment != null) {
A = segment.getA();
B = segment.getB();
C = segment.getC();

AA = String.valueOf(A);
BB = String.valueOf(B);
CC = String.valueOf(C);
}

如果您共享stck trace,我们可以提供更好的帮助。

关于java - 有没有办法摆脱我得到的这个空指针异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26995363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com