Help! The code keeps returning as "nullnull"! I am trying to make it so that if I have multiple elements, it will display it into the console. This is more of a two part question... 1. I am saving multiple different element symbols to one variable, it wont work will it? How should I make it so that it saves under a different variable each time? 2. Why does it keep returning as nullnull? I think something should be being saved as element 1. Not so sure about element11 though... Thanks for the help!
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import javax.swing.JOptionPane;
public class Science1 {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String element;
int more;
FileInputStream fin;
JOptionPane.showMessageDialog(null, "Balancing chemical equations, capable for anything with more than one compound");
element = JOptionPane.showInputDialog("Please input an element");
String element1 = null;
element = element1;
String element11 = null;
//MORE VARIABLES?
more = JOptionPane.showConfirmDialog(null, "Do you have more elements on this side?", element, JOptionPane.YES_NO_OPTION);
while(more == 0){
element = JOptionPane.showInputDialog("Please input an element");
element = element11;
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter("test.txt"));
writer.write(element1 + element11);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) try { writer.close(); } catch (IOException ignore) {}
}
//MORE VARIABLES?
more = JOptionPane.showConfirmDialog(null, "Do you have more elements on this side?", element, JOptionPane.YES_NO_OPTION);
}
try
{
// Open an input stream
fin = new FileInputStream ("test.txt");
// Read a line of text
System.out.println( new DataInputStream(fin).readLine() );
// Close our input stream
fin.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to read from file");
System.exit(-1);
}
}
}