java - How to call a method that uses potentially uninitilized arrays as paramaters? -
I am writing a program that reads a text file in parallel array, then users can match those parameters Let's declare these arrays at the beginning of the code, printed in a separate file, but they did not start until the length of time depends on the data extracted from the file.
I am now attempting to write methods that print filtered results in a file, but eclipse is telling me that I can not give them as parameters because they are initialized Are not there. But they are started, only within a loop. I can not start them before, because the program does not yet know the required length
the relevant bit of code
filter location (time, longitude, magnitude, latitude , Location, description, entries); Where there are errors, when I try to call the method by the main method
public static zero filter location (string [] time, double [] Latitude, double [] longitude, double [] magnitude, string [] location, string [] description, int entries) I'm trying to write, where there is no error Received by eclipse
string [] time; Double [] latitude; Double [] longitude; Double [] magnitude; String [] location; String [] description; Where variables have been declared, it is true that public static zero main ...
if (entries! = 0) {time = new String [entries]; Latitude = new double [entries]; Longitude = new double [entries]; Magnitude = new double [entries]; Location = new string [entries]; Description = new string [entries]; Where they are initialized, nested in the loop for a while, try the statement and block
Start the variable in that method from which the filter location is called. It seems that you are not starting the variable there.
Edit : Your code contains a condition
if (entries! = 0) {< > which prevents initialization, indicating the compiler's status What if entries = 0?
See a dummy code below.
public static zero main (string)
[] args) {
int a; If (args! = Null) {a = 10; } And {one = 11; } Sample method (A); } Public static zero sampling method (int a) {// TODO auto-generated method stub} Remove the second position, and see the compile error.
Hope you understand the problem.
Edit Or call the method only in the condition. See the dummy code.
public static zero main (string [] args) {int a; If (args! = Null) {a = 10; SampleMethod (a); }} Public static zero sampling method (int a) {// TODO auto-generated method stub} edit or The variable should be at the class level.
Public class TestMethod {Private int a; Public static zero main (string [] args) {TestMethod method = New TestMethod (); Method.wrapperMethod (args); } Public Zero Cover Method (string [] Args) {if (args! = Null) {a = 10; } Sample method (A); } Excerpt from Public Static Zero Sampling Method (Integrated) {// Tudo Auto-Generated Method Stub}
Each method parameter (§ 8.4.1 ) Is initiated for the rational argument provided by the inventor of the method (§ 15.12).
A local variable (§ 14.4, §14.14) should be clearly given a value, either in the initial (§ 14.4) or the assignment (§ 15.26), in the manner specified by the assignment (§ 16 ) Can be verified using the rules.
Comments
Post a Comment