-   Programming (
-   -   Java non-static variable cannot be referenced from a static context issue (

rickrvo 02-12-2010 02:16 PM

Java non-static variable cannot be referenced from a static context issue

I'm having some problems on the line with ***. This is from a class file and I'm trying to update EmprestadorView's variables. Does anyone know how to fix this?
public class EmprestadorView extends FrameView {
public class OpenEntidade extends javax.swing.JFrame {

private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
File fix=jFileChooser1.getSelectedFile();

String aux1=null;
try {
BufferedReader inputStream = new BufferedReader(new FileReader(fix));

String tmp=null;
while ((aux1 = inputStream.readLine()) != null) {
tmp=aux1.substring(0, 6);
if(tmp.compareTo("Nome: ")==0){
EmprestadorView.emp[EmprestadorView.total_emp].setNome(aux1); ***
tmp=aux1.substring(0, 11);
if(tmp.compareTo("Emprestei: ")==0){
EmprestadorView.emp[EmprestadorView.total_emp].setEmpout(aux1); ***
EmprestadorView.setEmpIn(aux1); ***

nadroj 02-12-2010 03:05 PM

Well its hard to tell you the exact problem without the exact (i.e. complete) code. Its telling you that you're trying to use a variable as static, but its not declared static. Make sure that "EmprestadorView.emp" is declared "static". However, it might also (or either) be that "EmprestadorView.total_emp" must be static but isnt declared static.

Are there accessor methods (getter/setter) that you should be using instead?

rickrvo 02-12-2010 03:26 PM

thanks! staticed the emp and good to go :)

All times are GMT -5. The time now is 06:23 PM.