Error in Java: "Variable might not have been initialized"


Here what I do is call the class "Application" to create a table, in the error of the "c" it tells me that it has not been initialized, what can I do?

asked by Mip ́s Trash. 07.11.2016 в 23:49

2 answers


You have to create an instance of that class using the new command with all its parameters just like you did with app :

Aplicacion c = new Aplicacion(parámetros);

In fact, you should use app instead of c to access the methods of your class since you already have it initialized and in this way you avoid duplicating variables.

answered by 07.11.2016 / 23:50

You have to initialize your variable, you have declared it and the variable:

Aplicacion c;

Aplicacion is actually a class that has to receive 6 parameters, you can see it in the initialization of app :

Aplicacion app = new Applicacion( , , , , , );

Therefore for c you would have to do the same:

Aplicacion c = new Applicacion( , , , , , );

Check your application because you might not need to create another instance of the Aplicacion class and use the one already created that is app .

answered by 08.11.2016 в 00:04