Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-12-2010, 02:16 PM   #1
LQ Newbie
Registered: Feb 2010
Posts: 2

Rep: Reputation: 0
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); ***
Old 02-12-2010, 03:05 PM   #2
Senior Member
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 59
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?
Old 02-12-2010, 03:26 PM   #3
LQ Newbie
Registered: Feb 2010
Posts: 2

Original Poster
Rep: Reputation: 0
thanks! staticed the emp and good to go


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java: non-static variable this cannot be referenced from a static context chief_officer Programming 4 05-29-2006 01:37 PM
C++: difference between static method variable and static class variable? Thinking Programming 3 01-16-2006 10:08 AM
extern static variable alaios Programming 9 09-11-2005 04:11 AM
What is a static variable? saiz66 Programming 7 09-30-2004 05:17 PM
FC2 Overriding static if in favor of dhcp system set for static pkraus109 Linux - Networking 8 09-21-2004 11:13 AM

All times are GMT -5. The time now is 01:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration