Sign in to follow this  

Java File processing error

This topic is 2036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I’m getting an error in Java with Eclipse.
What I’m trying to do is if bamButton is selected I want selectedFile to be processed with doWork.
I’m getting the following errors on the noted lines.


[CODE]


if (returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfileChooser.getSelectedFile(); //jTable receives file from filechooser

//ALT if BAM
if (bamButton.isSelected())
>>File selectedFileBamHolder = BamToBed.doWork(selectedFile);
>>File selectedFile = selectedFileBamHolder;






[/CODE]


Cannot make a static reference to the non-static method doWork(File) from the type BamToBed SoleSearchToolPanel.java /GUI/src line 528 Java Problem
Duplicate local variable selectedFile SoleSearchToolPanel.java /GUI/src line 529 Java Problem
File cannot be resolved to a variable SoleSearchToolPanel.java /GUI/src line 528 Java Problem
selectedFileBamHolder cannot be resolved to a variable SoleSearchToolPanel.java /GUI/src line 528 Java Problem
selectedFileBamHolder cannot be resolved to a variable SoleSearchToolPanel.java /GUI/src line 529 Java Problem
Syntax error, insert ";" to complete Statement SoleSearchToolPanel.java /GUI/src line 528 Java Problem
Syntax error, insert "AssignmentOperator Expression" to complete Assignment SoleSearchToolPanel.java /GUI/src line 528 Java Problem Edited by Jarwulf

Share this post


Link to post
Share on other sites
Well it looks like most errors are because the compiler doesn't know about the type "File".
Have you got an import statement for "java.io.File" or "java.io.*" ? If so, there must be a syntax error somewhere else in the code.

For the "doWork" method, if you need to access without an instance of BamToBed, make sure to declare the method static. In BamToBed class it should read:

[CODE]
public static File doWork(File f) {
// Do something...
return null;
}
[/CODE]


For "Duplicate local variable selectedFile", you declare a "File" variable twice with the same name.
If you want to replace selectedFile with selectedFileBamHolder, just do:

[CODE]
selectedFile = selectedFileBamHolder

// Instead of:
// File selectedFile = selectedFileBamHolder;
[/CODE]

Otherwise it needs a different name. Edited by Angex

Share this post


Link to post
Share on other sites
[quote name='Angex' timestamp='1337026925' post='4940184']
Well it looks like most errors are because the compiler doesn't know about the type "File".
Have you got an import statement for "java.io.File" or "java.io.*" ? If so, there must be a syntax error somewhere else in the code.

For the "doWork" method, if you need to access without an instance of BamToBed, make sure to declare the method static. In BamToBed class it should read:

[CODE]
public static File doWork(File f) {
// Do something...
return null;
}
[/CODE]


For "Duplicate local variable selectedFile", you declare a "File" variable twice with the same name.
If you want to replace selectedFile with selectedFileBamHolder, just do:

[CODE]
selectedFile = selectedFileBamHolder

// Instead of:
// File selectedFile = selectedFileBamHolder;
[/CODE]

Otherwise it needs a different name.
[/quote]



I changed to this


[CODE]
public void actionPerformed(ActionEvent e){
int returnVal = jfileChooser.showOpenDialog(parentPanel);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfileChooser.getSelectedFile(); //jTable receives file from filechooser
File selectedFileBamHolder;

//ALT if BAM
if (bamButton.isSelected())
selectedFileBamHolder = BamToBed.doWork(selectedFile); //selectedFileBamHolder holds BAM since dunno if selectedFile could equal itself being processed by doWork
selectedFile = selectedFileBamHolder;

[/CODE]

and changed dowork from protected to public static its still giving me pretty much all the same errors


Here is the top of the class

[CODE]
import java.util.Vector;
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Cursor;
import java.awt.ComponentOrientation;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class SoleSearchToolPanel extends JPanel{
private final int defaultPermutation = 5;
private final int defaultFragment = 150;
private String defaultFDRStr = "0.0001";
private String defaultPeakMergeDistanceStr = "0";
private final String defaultHistoneBlurLengthStr = "1200";
private JTextArea txtArea;
private JTextField combinedFileNameField;
private JTextField permutationField;
private JTextField fragmentField;
private JTextField fdrField;
private JTextField peakMergeDistanceField;
private JTextField emailField;
private JTable jTable;
private JTable bgJTable;
private JButton browseButton;
private JButton clearButton;
private JButton browseBgButton;
private JButton clearBgButton;
private JButton submitButton;
private JButton restoreButton;
private JRadioButton bamButton; //ALT declare bambutton
private JRadioButton useExistedBgButton;
private JRadioButton useCustomizedBgButton;
private JRadioButton helaBgButton;
private JRadioButton K562BgButton;
private JRadioButton Ntera2BgButton;
private JRadioButton HEK293BgButton;
private JRadioButton genericButton;
private JRadioButton alphaValue01Button;
private JRadioButton alphaValue05Button;
private JRadioButton alphaValue1Button;
private JRadioButton alphaValue001Button;
private JRadioButton alphaValue0001Button;
private JCheckBox histoneCheckbox = null;
private JTextField histoneBlurLegnthField = null;

private Vector testFileVector = null; //intermediate holder for test file?
private String outputFileName = null;
private String cellLine = null;
private Vector bgFileVector = null;
private int permutation;
private int fragment;
private double alphaValue;
private double fdr;
private int peakMergeDistance;
private int histoneBlurLength;
private String email = null;
[/CODE]


as you can see import java.io.File; is there but eclipse refuses to recognize File for some reason.

Share this post


Link to post
Share on other sites
I can only think of a few reasons why the compiler can't resolve a type.

[b]1) The compiler can't find the class "java.io.File".[/b]

Check to make sure the java libraries are referenced by the project.
In "Package Explorer", right-click the project and select "Properties".
Then click "Java Build Path", then "Libraries" tab.
In the list you should have something like "JRE System Library". (Names may vary depending on the version of Eclipse).
If missing, then it needs to be added.


[b]2) There are multiple classes with the same name.[/b]

Your project has another class called File, and the compiler doesn't know which File you mean.
Looking at the imports, this doesn't seem to be the case.
But double check there are no other classes in the same package called File, or inner classes.

If you do have multiple classes with the same name, you just need to specify the full package name when using them e.g.
[CODE]
java.io.File selectedFileBamHolder;
[/CODE]


[b]3) There is a syntax error somewhere else in the code; the compiler has generated misleading errors.[/b]

The compiler has encountered a File variable declaration when it didn't expect too.
In isolation, the code causing the error looks okay. Usually this is caused by a mis-placed bracket somewhere else in the code. Edited by Angex

Share this post


Link to post
Share on other sites

This topic is 2036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this