我总是得到无效的表达 [英] i get always null expretion
本文介绍了我总是得到无效的表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助
plz
这是我的代码:
i need help
plz
here is my code:
class structFile
{
String filename="";
int words=0;
int matchs=0;
int semiMatchs=0;
int precent=0;
String source="";
void structFile()
{
this.filename="BroadCast";
this.words=0;
this.matchs=0;
this.semiMatchs=0;
this.precent=0;
this.source="->";
}
}
public class testGUI extend JFrame
{
/*
some funtion the show me tables in JFrame
*/
public static void main ( String[] args )
{
structFile file10[]=new structFile[10];
for(int k=0;k<file10.length;k++)
{
file10[k].structFile();
}
System.out.println(file10[some index between 1-10]);
}
}
但我得到allways null指针Expretion
but i get allways null pointer Expretion
推荐答案
之后数组的初始化,所有值都是null
,而不是structFile
类的实例,所以你不能调用structFile
方法。在调用此方法之前,请创建一个新的类实例:
After the initialization of the array, all values arenull
, not an instance of thestructFile
class, so you cannot call thestructFile
method on them. Before calling this method, create a new class instance:
for(int k = 0; k < file10.length; k++)
{
file10[k] = new structFile();
file10[k].structFile();
}
这篇关于我总是得到无效的表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文