import java.awt.*;
import java.awt.event.*;
import javax.swing.*;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;public class crtt
{
public class AA implements Serializable
{
int CRF[] = new int[200];
}
public void wrf(String fpw)
{
try{FileOutputStream fos = new FileOutputStream(fpw);
ObjectOutputStream out = new ObjectOutputStream(fos);
AA a = new AA();
out.writeObject(a);}catch (IOException e) {e.printStackTrace();}
} public void rdf(String fpr)
{
try{FileInputStream fis = new FileInputStream(fpr);
ObjectInputStream in = new ObjectInputStream(fis);
AA a = (AA)in.readObject();}catch (IOException e) {crt.wrf(fpr);}
catch (ClassNotFoundException e){crt.wrf(fpr);} } public void main(String[] args)
{
String fp1="D:\\javad\\CS.txt"; crt.wrf(fp1);
System.out.println(AA.CRF[1]);
AA.CRF[1]=46849;
crt.rdf(fp1);
System.out.println(AA.CRF[1]);
}
} System.out.println(AA.CRF[1]);
^
“在静态上下文中不能引用非静态变量”
import java.awt.event.*;
import javax.swing.*;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;public class crtt
{
public class AA implements Serializable
{
int CRF[] = new int[200];
}
public void wrf(String fpw)
{
try{FileOutputStream fos = new FileOutputStream(fpw);
ObjectOutputStream out = new ObjectOutputStream(fos);
AA a = new AA();
out.writeObject(a);}catch (IOException e) {e.printStackTrace();}
} public void rdf(String fpr)
{
try{FileInputStream fis = new FileInputStream(fpr);
ObjectInputStream in = new ObjectInputStream(fis);
AA a = (AA)in.readObject();}catch (IOException e) {crt.wrf(fpr);}
catch (ClassNotFoundException e){crt.wrf(fpr);} } public void main(String[] args)
{
String fp1="D:\\javad\\CS.txt"; crt.wrf(fp1);
System.out.println(AA.CRF[1]);
AA.CRF[1]=46849;
crt.rdf(fp1);
System.out.println(AA.CRF[1]);
}
} System.out.println(AA.CRF[1]);
^
“在静态上下文中不能引用非静态变量”
如何处理?
1: 把你要引用的方法变成静态的.
2: 在你的静态方法里new 出非静态方法的实例来.在通过这个实例点出这个方法来.