在调试时,我看到文本正确地保存在dataText内部,但是当我在另一个侦听器上调用它时,出现错误“尝试调用虚拟方法'boolean java.lang.String.equals(java.lang.Object) '在空对象引用上”
if (controlli.checknull(variabili.LoadTextblock(w)))
出什么问题了?怎么解决呢? variabili.java:
public class Variabili {
public static String[] dataText = new String[500];
public void SaveTextblock(String text, int i) {
dataText[i] = text;
}
public String LoadTextblock(int i){
return dataText[i];
}
}
我在firebase的for-cycle中创建变量:
final Task<FirebaseVisionText> result =
textRecognizer.processImage(image)
.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText firebaseVisionText) {
Integer i = 0;
for (FirebaseVisionText.TextBlock block: firebaseVisionText.getTextBlocks()) {
String blockText = block.getText();
variabili.SaveTextblock(blockText,i);
i++;
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});