Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting code to output file, and non-public type error
    primarykey
    data
    text
    <p>I have two problems that I am dealing with in my create a class of string instruments problem. First the requirements are:</p> <ol> <li>The name of the output file in the code of main must be the name specified on the command line, where you find the required code. As specified in the requirements, the test class must be started with an argument in the command line:</li> </ol> <p>java Mynamep3tst myfilename.txt here myfilename.txt is the file where all output must go. This file name should be used in the program as follows:</p> <p>java.io.File file = new java.io.File(args[0]);</p> <p>java.io.PrintWriter output = new java.io.PrintWriter(file);</p> <p>and when you have a message to be sent to the file,</p> <p>output.println(message);</p> <p>I keep receiving an error at this point:</p> <pre><code>public static void printInstrumentArray(StringInstrument[] instruments)throws Exception{ java.io.File file = new java.io.File(args[0]); java.io.PrintWriter output = new java.io.PrintWriter(file); </code></pre> <p>the error says "cannot find symbol" which I know is what it does when I haven't declared the array. When I do declare the array args[] it says "Exception in thread "main" java.lang.NullPointerException".</p> <p><strong>Next problem</strong></p> <ol> <li><p>When I run this it works but it keeps popping up the error "exporting non-public type through public API". I have tried putting public at "StringInstrument[] instruments;". However it will pop up the error "illegal start of operation". </p> <pre><code> public static void main(String[] args) throws Exception{//begin main //declare instruments StringInstrument[] instruments; //create instrument array instruments = createInstrumentArray(); //Print instrument array printInstrumentArray(instruments); }//end main //Create an array of instrument objects public static StringInstrument[] createInstrumentArray(){//begin method StringInstrument[] instruments = new StringInstrument [10]; //Loop that inputs random integers into the array for (int i = 0; i &lt; instruments.length; i++){//begin loop instruments[i] = new StringInstrument(); }//end loop return instruments; }//End method public static void printInstrumentArray(StringInstrument[] instruments)throws Exception{ java.io.File file = new java.io.File(args[0]); java.io.PrintWriter output = new java.io.PrintWriter(file); //declare and initialize arrays String[] instrumentList = new String [10]; int[] stringNumber = new int [10]; //input string names into array instrumentList[0] = "Guitar"; instrumentList[1] = "Violin"; instrumentList[2] = "Bass Guitar"; instrumentList[3] = "Cello"; instrumentList[4] = "Banjo"; instrumentList[5] = "Sitar"; instrumentList[6] = "Rabab"; instrumentList[7] = "Viola"; instrumentList[8] = "Harp"; instrumentList[9] = "Ukulele"; stringNumber[0] = 5; stringNumber[1] = 4; stringNumber[2] = 5; stringNumber[3] = 4; stringNumber[4] = 5; stringNumber[5] = 18; stringNumber[6] = 3; stringNumber[7] = 4; stringNumber[8] = 47; stringNumber[9] = 4; //Print an array of instruments and their actions for (int i = 0; i &lt; instruments.length; i++){//begin for loop instruments[i].setInstrumentName(instrumentList[i]); output.println(instruments[i].instrumentNameDisplay()); output.println(instruments[i].numberOfStrings(stringNumber[i])); output.println(instruments[i].tuneInstrument()); output.println(instruments[i].playInstrument()); output.println(instruments[i].playInstrumentBand()); output.println(" "); }//end for loop output.close(); }//end method }//end class </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload