LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Java non-static variable cannot be referenced from a static context issue (http://www.linuxquestions.org/questions/programming-9/java-non-static-variable-cannot-be-referenced-from-a-static-context-issue-788741/)

rickrvo 02-12-2010 02:16 PM

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

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


EmprestadorView.java
-------------------
public class EmprestadorView extends FrameView {
...


OpenEntidade.java
-----------------
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){
aux1=aux1.substring(6);
EmprestadorView.emp[EmprestadorView.total_emp].setNome(aux1); ***
}
tmp=aux1.substring(0, 11);
if(tmp.compareTo("Emprestei: ")==0){
aux1=aux1.substring(11);
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 12:53 AM.