main.java
Code:
package simpleobjects;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
Object[] people = new Object[4];
static void main(String[] args) {
int i = 0;
Object[] people = new Object[4];
people[0] = new Object("Bill",4);
people[1] = new Object("Nye",3);
people[2] = new Object("Science",7);
people[3] = new Object("Guy",3);
while(i <= 3 )
{
people[i].getInformation();
i++;
}
writeXML();
}
public static void writeXML()
{
String topLevel = "userList";
String secondLevel = "people";
try
{
BufferedWriter saveFile = new BufferedWriter(new FileWriter("1.xml"));
saveFile.write("<" + topLevel + ">\n");
for (int i = 0; i <= 3 ; i++)
{
saveFile.write(" <" + "people" + ">\n");
saveFile.write(" <name> " + people[i].getName() + "</name>\n");
saveFile.write(" <number> " + "" + "</number>\n");
saveFile.write(" </" + secondLevel + ">\n");
}
saveFile.write("</" + topLevel + ">\n");
saveFile.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
Object.java
Code:
package simpleobjects;
/**
*
* @author harry
*
*/
public class Object
{
public int number;
public String word;
public Object(String inWord,int inNumber)
{
number = inNumber;
word = inWord;
}
public int setNumber( int inNumber )
{
return this.number = inNumber;
}
public void getNumber()
{
System.out.println(number);
}
public String setWord( String inWord )
{
return this.word = inWord;
}
public void getWord()
{
System.out.println(word);
}
public void getInformation()
{
System.out.println("Name: " + word);
System.out.println("Number: " + number);
}
}
I successfully create the objects, and can pull/push data into each object but I cannot reference them in the XML function (to get the name/number of each object and save them to XML).
I've googled the error (even though it's a general error), so see how it can be fixed - with no avail.
So where am I going wrong?
Easier to download the whole package?
_________________
Skillers wrote:
Oh gawd no! Not the crazy frog! Arghhhhhh! $&^%&*^%*$^ %$(%^((% %$(O*%(#*%^ %)*#$&%)*@#% %_(#&%*%) frog