Ой, простите, промахнулся разделом... Но, может, и здесь помогут.
В общем, проблема такова: мне надо сериализовать объект в XML файл. При использовании XMLEncoder пишет:
java.lang.IllegalAccessException: Class sun.reflect.misc.Trampoline can not access a member of class task4.Task4$Zachotka with modifiers "public"
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(Task4$Zachotka);
Continuing ...
Код
package task4;
import java.io.*;
import java.util.Scanner;
import java.beans.XMLEncoder;
import java.beans.XMLDecoder;
public class Task4 {
private static class Zachotka implements java.io.Serializable{
public Zachotka(){}
static class Session
{
int NumOfSubj;
int marks[];
String subjects[];
Session(Scanner eye) {
eye.nextInt();
this.NumOfSubj = eye.nextInt();
this.subjects = new String[NumOfSubj];
this.marks = new int[NumOfSubj];
for (int j = 0; j < NumOfSubj; ++j) {
this.subjects[j] = eye.next();
this.marks[j] = eye.nextInt();
}
}
}
static private String name, fam, otch;
static private int kyrs, grope, ClosedSession;
private static Session etap[] = new Session[10];
//public void writeObject(){}
Zachotka(Scanner eye) {
this.name = eye.next();
this.fam = eye.next();
this.otch = eye.next();
this.kyrs = eye.nextInt();
this.grope = eye.nextInt();
this.ClosedSession = eye.nextInt();
for (int i = 0; i < ClosedSession; ++i) {
etap[i] = new Session(eye);
}
}
}
public static void main(String[] args) throws FileNotFoundException {
try {
FileInputStream in = new FileInputStream("input.txt");
Scanner eye = new Scanner(in, "cp1251");
eye.useDelimiter("[-.,:=_;()?!\" \t\n\r]+");
Zachotka NZ = new Zachotka(eye);
FileOutputStream out = new FileOutputStream("Zachotka.xml");
XMLEncoder xmlEncoder = new XMLEncoder(out);
xmlEncoder.writeObject(NZ);
xmlEncoder.flush();
xmlEncoder.close();
}
catch (IOException e)
{
System.out.printf("Ошибка ввода");
}
}
}
Как, собственно надо описать класс, чтобы он сериализовался с помощью XMLEncoder ?
Тему перемещаю.