Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need help
plz
here is my code:

C#
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="->";
	}
}


C#
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]);
}
}

but i get allways null pointer Expretion
Posted

1 solution

After the initialization of the array, all values are null, not an instance of the structFile class, so you cannot call the structFile method on them. Before calling this method, create a new class instance:
Java
for(int k = 0; k < file10.length; k++)
{
    file10[k] = new structFile();
    file10[k].structFile();
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Jan-16 15:09pm    
Right, a 5.
—SA
Thomas Daniels 13-Jan-16 15:12pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900