Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing array of string from one class to another
    text
    copied!<p>I'm trying to pass a string array from one class to another in my java code. By using code such as </p> <pre><code>Class instanceofclass = new Class(); String text1 = instanceofclass.variablename; </code></pre> <p>and then displaying it out on screen worked fine!</p> <p>However I'm trying to get the array of a string. So in my first class I have</p> <pre><code>JButton [] FilmTime = new JButton[5]; JButton [] FilmNames = new JButton[8]; String [] films = new String [8]; DbConnector dataBase = new DbConnector(); for (int i =0; i &lt;= 7; i++) { films[i] = dataBase.FilmTitle[i]; } for (int i =0; i&lt;= 7; i++) { FilmNames[i] = new JButton (films[i] + " ("+age+")"); FilmNames[i].setPreferredSize(new Dimension(563,50)); grid.add(FilmNames[i]); } </code></pre> <p>I know I can use one for loop but I was just checking issues at the momment.</p> <p>In my second class used named dbconnector i have:</p> <pre><code>public String FilmTitle []; for (int i =0; i&lt;=7; i++) { String query = "SELECT * FROM films WHERE ID =" + i; Rs = St.executeQuery(query); while (Rs.next()) { FilmTitle[i] = Rs.getString("FilmName"); } } </code></pre> <p>Eclipse gives the error as:</p> <pre><code>Error is: java.lang.NullPointerException java.lang.NullPointerException at main.init(main.java:46) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) </code></pre> <p>Line 46 is the statement in the first for loop... testingme[i] = instanceofclass.variablename[i];</p>
 

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