GUI to set file, other class to read it, file null error
Perhaps not the most informative subject for this problem. I have a GUI in which a file chooser is used to select a file to be read. Another class reads in this file, and goes on to process it. My main class sets up the GUI and then goes on to process the files in the second class.
I am having trouble, I believe, with timing. The main class sets up the GUI, it runs perfectly, and then I catch a problem (that will evolve into an error), where the file I am supposed to process is null, because I have not had a chance to use the file chooser in the GUI. I haven't had any luck finding a solution online, although if there is one (or another tutorial I missed), please feel free to pass the link(s) along. I am posting the relevant code below.
Thanks,
Danielle
public Main()
* @param args the command line arguments
public static void main(String[] args)
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
System.out.println("About to run create GUI method");
MGui app = new MGui();
System.out.println("declared a new MGui....");
app.createAndShowGUI();
/**Starting to get file choices and moving them into GPR Handler:
GprHandler gpr = new GprHandler();
//~ System.out.println("should be perfect????");
// }//end if
}// end main(String[] args)
}// end class MainThe GUI uses the following code for the file chooser:
private class enterFile2Action implements ActionListener
public void actionPerformed(ActionEvent evt)
JFileChooser chooser = new JFileChooser();
int rVal = chooser.showOpenDialog(enterFile1);
if(rVal == JFileChooser.APPROVE_OPTION)
inputFile2 = chooser.getSelectedFile();
PrintWriter outputStream;
file2Name = inputFile2.getName();
enterLabel2.setText(file2Name);
}Finally, the GprHandler class processes the file- reading it and such. The only relevant method, however is below.
/** taking in files*/
public boolean readFiles()
boolean nullFiles = true;
System.out.println("into method readFiles()");
if (MGui.get1Name() != null)
System.out.println("name isn't null");
file1Name = MGui.get1Name();
file1 = new File(file1Name);
if (MGui.get2Name() != null)
file2Name = MGui.get2Name();
file2 = new File(file2Name);
nullFiles = false;
}//end if
if (nullFiles)
System.out.println("one or more files is undeclared");
return false;
}//end if
else
try{
file1Reader = new FileReader(file1);
file2Reader = new FileReader(file2);
}//end try
catch (FileNotFoundException e)
System.out.println("file not found exception");
return false;
} //end catch
}//end else
return true;
}
No, you're quite right. I want the GprHandler to
start when I've got something there for it to start
with. I never thought to call it from the
actionPerformed though. I think I've been listening
to too many lectures on some prof's definition of a
"proper main class".
I think I understand what you're suggesting: I
should simply remove the GprHandler part from my main
class and place it instead in the actionPerformed
methods, once the files are actually named/chosen.
Did I get that right?
Qualified yes. Does GPRHandler implement Runnable? I mean you don't want to do the processing in the swing event thread. So what you should do is in the actionPerformed create the Handler (with the file or whatever other bits it needs) and then start it.
Then it can process merrily along in a seperate thread.
Similar Messages
-
Using Lightroom 4 w/ Windows 7. Recently started shooting w/ Sony camera that shoots .arw files. Lightroom cannot read the files. Loaded Adobe converter program onto the computer and this program cannot read the files either. Any suggestions?
Thnx again for the reply. The version of Lightroom I have is 4.0 (working w/Windows 7) This computer and all media files are kept off-line After doing more research, I downloaded DNG Converter 7.1This loaded into a .zip folder, which I am planning to install into the off-line computer andrun. Where does this folder go?
And will this set up work with my version of Lightroom?
What a pain. Makes me wanna go back to shooting .nef files for all stills
Thnx -
I am working on a Mac 10.9.5 with Adobe CS6. My files are locally in Dropbox but once we moved files to network and tried opening the AI - the file would not recognize the original folder location. I tried ignoring the missing images but then I receive the error - The file could not be read due to an error." The same error happens when I try replacing the first missing image. I know the problem lies in the images are linked back to my Dropbox but the AI file doesn't care since it won't let me replace or ignore the image links.
Jasion,
Maybe a bit beside the question, but it is always recommended here to open/save from/to own hard disk, and to copy from/to networks and removable media. You may be lucky, at least for a while, but it is better to be safe than sorry.
In addition to the (far greater) risk of file corruption, some issues are mentioned here:
http://helpx.adobe.com/illustrator/kb/illustrator-support-networks-removable-media.html -
I am working on a Mac 10.9.5 with Adobe CS6. My files are locally in Dropbox but once we moved files to network and tried opening the AI - the file would not recognize the original folder location. I tried ignoring the missing images but then I receive the error - The file could not be read due to an error." The same error happens when I try replacing the first missing image. I know the problem lies in the images are linked back to my Dropbox but the AI file doesn't care since it won't let me replace or ignore the image links.
Jasion,
Maybe a bit beside the question, but it is always recommended here to open/save from/to own hard disk, and to copy from/to networks and removable media. You may be lucky, at least for a while, but it is better to be safe than sorry.
In addition to the (far greater) risk of file corruption, some issues are mentioned here:
http://helpx.adobe.com/illustrator/kb/illustrator-support-networks-removable-media.html -
Hello,
I'm trying to troubleshoot several Illustrator files that won't open on desktops at my company's 2nd office. The files open fine on any desktop at my primary office. When opening the files from the 2nd office, it begins "Reading Illustrator file..." then the message "The file could not be read due to an error" is displayed and the file closes out.
Both offices have the same model desktop and are running:
Adobe Illustrator CS6 (up to date)
Windows 7 x64
Both desktops have the same system fonts and I've tried saving the files locally.
Thanks, ShaunHey Jacob and Monika,
Sorry if I wasn't clear, but I did already try saving the files to the hard disk.
"Both desktops have the same system fonts and I've tried saving the files locally."
My fix was copying the content of the files into new, blank .ai files. Those new files open from both offices now.
Still, I wish I could have identified the issue in case it happens again. The error message is vague and there isn't much info on the web about it.
Best, Shaun -
How to include text file in classes directory of war file.
I have a project that uses a text file called cache.ccf (JCS configuration file) when debugging the webservices, I have to dig into the inflated war file directory and manually place the cache.ccf file in the WEB-INF/classes/ directory/
How can i have JDeveloper wrap the file up in the war file in the WEB-INF/classes directory. both for debugging and when the war file is actually built for deployment.
Thanks,
BartNevermind, I figured it out using the Project Properties->Deployment and include it in the WEB-INF/classes
-
An official site incometaxindiaefiling.gov.in requires .XML files to be uploaded. When .XML files are uploaded without digital signatures there is no problem. When digital signatures are required for signing the same a message 'CANNOT READ THE FILE FOR SIGNING" is displaced. It happens with CHROME and IE also. The solution which I have devised is that I copy the .XML files in a folder called FAKEPATH in C: drive and pick the file for signing from this folder. The browser allows the file to sign with digital signatures. What is the solution.
Ashish GoelAshish,
You might want to submit this feedback at https://incometaxindiaefiling.gov.in/e-Filing/Services/Feedback.html instead. -
I'm creating the web-site. it is currently on the development level. the link is http://snazhmudinov.byethost7.com/
If you open it with chrome, safari and ie, it works fine. But when I start using Mozilla and Opera, they simply don't see css files.
Thank you in advance!hello, your source code specifies the path to the stylesheet files like this styles\page.css instead of styles'''/'''page.css. apparently some browsers are less tolerant to such errors than others...
-
My Excel files were imported as read only files how can I change these
I am a new Mac user. When my excel files were copied over from my MS PC they have come over as read only files. How can i change these to "normal" files as they were on my PC? Thanks
More info:
Version: 10.6.8
Format: Mac OS Extended
Sharing & Permissions:
system - Read & Write
admin - Read & Write
everyone - Read only
When I click the lock in the bottom right corner it prompts me for my password but after unlocking it it doesn't allow me to change privelages or give me any new permissions. -
Pls, Determine what file's encoding when read a file use NIO
Hi every body,
When I use NIO (New I/O JDK1.4) to read a file's content.
How can I know exactly file's encoding (example: UTF-8, Cp1252, shift-jis ...) to choose right decoder to decode the file??
Thanks
Best regards.
Hung, Nguyen Thanh.I think there's no way to do that except...
If you are sure your files are all in japanese,
you can use JISAutoDetect encoding. -
HTML reader or other means to read HTML files in browser?
On my old XP computer I had a default that easily allowed any HTML files to display as intended. On my Windows 8.1 laptop I can't find any option to do this. Will "Scratchpad" let me display html files? I have seen the online readers which are fine for text; but if images are included with the html file folder, it is very nice to have them show up on the page, which is linked to the images in the folder.
I don't really want to go out and download software for this purpose if I'm missing something in my current system?
thanks
rosebud''jscher2000 [[#answer-676473|said]]''
<blockquote>
Are these some HTML files that you saved on your computer?
Firefox can display locally saved HTML files, but depending on how the pages were saved, some elements may be missing. There also are some security restrictions that Firefox applies to local files in a different way than pages on the web. Still, it's worth a try.
Normally, double-clicking the file will launch it in your default browser. If there are problems with the display, could you describe them in more detail?
</blockquote>
The folder is unzipped now...it is an art tutorial folder....and maybe I did the wrong thing by asking my Wordpad to be the opener of the text file. That is written as HTML. Each time I click it, all I get is the raw HTML on a wordpad document. Maybe I should try downloading the zipped file again? I have another one that is in PDF format, that is no problem at all! It's the one with that non-PDF text file that's giving me headaches...
[EDIT] Never mind, I found it! The change to Wordpad did no harm. I right clicked on that file and sure enough, it shows Firefox as the first option! I don't know how I missed it before. But when I chose that, the file opened just fine in the browser.
All is well now! Thanks! ----- rosebud -
Passing a binary file to class outputing a compressed file
Hi,
Am i writing a program which gets passed a file to encode via "java compressor < <filename>".
Compressor is a class with main method.
what i have right now is simply:
public class Compressor {
* @param args the command line arguments
public static void main(String[] args) {
InputStream in = new FileInputStream ("");
File f = new File ("");
ByteArrayOutputStream out = new ByteArrayOutputStream (f.length());
int i;
while ((i = in.read()) != -1) {
out.write(i);
in.close();
byte[] result = out.toByteArray();
for (int j = 0 ; i < result.length ; j++) {
byte a = result[j];
} The program is suppose to read the input one byte at a time and treats each one as an instruction which encodes byte compressoring the file and finally outputing this newly compressed file. I'm not sure how the main method will take the filename i.e "java compressor examplefile", any guidance would help greatly.
Thanksin the case above, the command line arguments are passed in the aaaaaaaaaaaaaaaaaaaaaaarggggggggggs array
you probably want aaaaaaaaaaaaaaaaaaaaaaarggggggggggs[0] for the filenameAm not sure i understand, do you mean i must change the param of the main method to String[] args[0] as this resulted in error when i did so. Or do you mean at command line instead file simply being passed to the Compressor program as
"java Compressor < examplefilename"
It has to be "java Compressor < examplefilename[0]" ?
If you could expand on this, would be grateful,
Thanks. -
How do I convert a JPEG file to an Adobe Reader (PDF) file?
Please help me. I have scanned an image of a text in a book. The scanned image is automatically uploaded into a JPEG file. How do I convert this into a PDF file?
None of the free Adobe Reader products provide the capability of converting image files (e.g. jpeg, gif, png) to PDF.
You can either use
Acrobat XI Pro or Standard - Scan to PDF
Adobe PDF Pack (formerly known as CreatePDF): online subscription service - JPEG to PDF Converter
You may find some free non-Adobe apps or online services. But the quality of PDF output may vary.
Unless you use OCR (Optical Character Recognition), the scanned image of text will not be recognized as real text. So you will not be able to highlight text, for example. -
How to convert .ase files to text or read .ase files
wondering if theres a way to open up my saved .ase files as a text file.
Use the open command on your text editor.
Not sure you can use this much as it is not like postscipt where you can read all the code, as much is in hexadecimal.
I opened this with textedit on mac. -
This has happened twice in one week. I'm 99% it's not the developers' fault, because the first time it happened, it was with Camtasia. They're big to be making mistakes. They even said that they got 100s of other downloads that day that worked. This time it's with Synfig, an animation program. When I download it, nothing happened. When I tried to copy it to applications, it gave me ^that^ error. When this happened with Camtasia, when I tried to mount it to disk, it had an invalid checksum, and it didn't work. They were nice enough to give me a FTP and HTTP download link. It didn't work with HTTP, but FTP worked. (Maybe just luck?) This time, I don't want to ask for a link becasue the person who owns the website has quit or something. The community is still active, but they'll hardly know. Besides, it looks like this is a problem on my end and not theirs. So yeah, Error Code -36. That's an I/O error. Is that a sign of a failing hard drive, or am I having problems while downloading? Please respond. Thanks
Aint you quick to jump to conslusions? So becasue one thing isn't working of the hundreds of things I donwloaded doesnt work, my drivers are broken?
Ok then, let me download some other things to make sure
Minecraft: it worked ✓
Firefox: it worked✓
Synthesia: it worked✓
iExplorer: it worked✓
Pencil: it worked✓
Flash: it worked✓
Synfig was made in 2006, so it's not unlikely that it might not work for some people. By 'some people', I mean me. I was just asking if it was something on my side, but if that's all you got, I think it's highly unlikely that it's my fault. I don't even want it anymore, I got Flash Professional. I was just wondering. I could have sworn you used to write more detailed answers before jumping striaght to conclusions. 'Did this happen to you on anything else?' or maybe even 'Why don't you complain to them?' would have been fine.
Maybe you are looking for
-
My Ipad wont retrieve my new emails and if I try to check passwords in Settings, the settings window only stays open open for a second or two and the automatically closes. Any help on how to fix. I tried the turn off and on trick and that didn't work
-
File 2 Proxy Sync - BPM - Mapping
Hi Guys, I am doing file 2 proxy sync interface. I am getting 2 files from 2 locations. First file contains group of records and second file contains the total records in the file 1. File 1: File :1 GroupNo InvoiceNo InvoiceDate InvoiceAmoun
-
Google Earth hangs Firefox 10.0.2
I'm seeing Firefox hang when using Google Maps. Specifically when switching to the Google Earth option on Google Maps. The problem is most likely to happen during rotations to view the horizon but can also crash when just moving around. I didn't used
-
Hi i want understand the role of "Management ID" I read that in the BI administration guide but I can not understand the purpose of this parameter Note: The Change Management ID is used for obtaining information related to logging, auditing, job hist
-
Error in Customer master data creation
when I am creating customer master data, error is in sales area data :partner functions data is not complete: I can't proceed from there. If I choose account group 001, it is working, when I am doing with my own account grp gets eorror. I hope I did