Keep getting ioexception... please help

I have two classes. Class ItemRecord defines the record in my input file and OrderCalculator4 opens the file and should load some arrays up with the data in the file. But it keeps throwing the first ioexception where i have "Error opening file". I have both classes in the same directory which is why I don't import ItemRecord into OrderCalculator. The code for the two classes is below:
/* This class defines an item record */
import java.io.Serializable;
public class ItemRecord implements Serializable {
private int itemNumb;
private String itemDesc;
private double itemPrice;
// no-argument constructor calls other constructor with default values
public ItemRecord()
this( 0, "", 0.0 );
// initialize a record
public ItemRecord( int id, String desc, double price )
setItemNumb( id );
setItemDesc( desc );
setItemPrice( price );
// set item number
public void setItemNumb( int id )
itemNumb = id;
// get item number
public int getItemNumb()
return itemNumb;
// set item description
public void setItemDesc( String desc )
itemDesc = desc;
// get item description
public String getItemDesc()
return itemDesc;
// set item price
public void setItemPrice( double price )
itemPrice = price;
// get item price
public double getItemPrice()
return itemPrice;
/* This program inputs an item number and quantity from a user
and then calculates and displays a line item total and final total.
Line item totals are also written to an output file. */
// Import Java Packages
import java.text.NumberFormat;
import java.util.Locale;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class OrderCalculator4 extends JFrame implements ActionListener {
private JLabel lineItemLabel;
private JButton addNextButton, summaryButton;
private JTextArea summaryArea;
String output2 = ""; //used for the final total output
double subtotal = 0; //running subtotal
Container container = getContentPane();
ObjectInputStream input;
// create US currency format
NumberFormat moneyFormat = NumberFormat.getCurrencyInstance(Locale.US);
//set up GUI
public OrderCalculator4()
container.setLayout(new BorderLayout(70,70));
lineItemLabel= new JLabel();
addNextButton = new JButton("Add Another Item");
summaryButton = new JButton("Compute Order Total");
container.add(lineItemLabel,BorderLayout.NORTH);
container.add(addNextButton,BorderLayout.WEST);
container.add(summaryButton,BorderLayout.EAST);
addNextButton.addActionListener(this);
summaryButton.addActionListener(this);
getInputs();
} // end constructor
//gets item number and quantity and processes line item total
public void getInputs(){
double itemTotal; //line item total for one order
String itemNumb; //item number entered by user
String qty; //quantity entered by user
StringBuffer output = new StringBuffer(); //used to redisplay a new line item order for each iteration
int quantity=0; //quantity used in calculation
int searchKey=-1; // -1 if item not found
int itemNumber[] = new int[5];
String desc[] = new String[5];
double itemPrice[] = new double[5];
loadArrays(itemNumber,desc,itemPrice);
do {
//Get item number from user
itemNumb = JOptionPane.showInputDialog("Enter the 2 digit item number:");
try {
searchKey = linearSearch(itemNumber, Integer.parseInt(itemNumb) );
if (searchKey == -1 ) {
JOptionPane.showMessageDialog(null,"Item Number does not exist",
"Invalid Data",JOptionPane.ERROR_MESSAGE);
itemNumb = JOptionPane.showInputDialog("Enter a valid 2 digit item number:");
searchKey = linearSearch(itemNumber, Integer.parseInt(itemNumb) );
//Get Quantity from user
qty = JOptionPane.showInputDialog("Enter quantity to be ordered:");
//Convert to proper type
quantity = Integer.parseInt(qty); } //end try block
catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog (this, "Item Number and Quantity must be inputted as positive integers",
"Invalid Number Format",JOptionPane.ERROR_MESSAGE);
} //end catch
} while (searchKey == -1 || quantity <= 0); //even if alpha entered for numbers,
//searchkey remains at -1 and inputs asked for again
itemTotal = quantity * itemPrice[searchKey];
subtotal += itemTotal;
//append each round of output for label
output.append(itemNumb).append(" ").append(desc[searchKey]).append(rightJustify(Integer.toString(quantity))).append(" at")
.append(rightJustify(moneyFormat.format(itemPrice[searchKey]))).append(" ").append(rightJustify(moneyFormat.format(itemTotal)));
lineItemLabel.setText(output.toString());
output.delete(0, output.length()); //clear stringbuffer to append same string with tab char
output.append(itemNumb).append(" ").append(desc[searchKey]).append("\t").append(rightJustify(Integer.toString(quantity))).append(" at")
.append(rightJustify(moneyFormat.format(itemPrice[searchKey]))).append(" ").append(rightJustify(moneyFormat.format(itemTotal)));
output2 += output.toString() + "\n"; //running string for final summary
output.delete(0, output.length()); //clear for next round of input
} //end method getInputs
public void displaySummary() {
double tax;
double finalTotal;
final double taxRate = 0.08;
tax = taxRate * subtotal;
finalTotal = tax + subtotal;
//final total output
output2 += "\n" + "\t\t" +"Order Subtotal" + rightJustify(moneyFormat.format(subtotal));
output2 += "\n" + "\t\t" + "Tax " + rightJustify(moneyFormat.format(tax));
output2 += "\n" + "\t\t" + "Final Total" + " " + rightJustify(moneyFormat.format(finalTotal));
container.removeAll();
container.repaint();
summaryArea = new JTextArea(output2);
summaryArea.setFont(new Font("Courier New",Font.PLAIN,12));
container.add(summaryArea);
container.add(new JScrollPane(summaryArea));
container.validate();
closeFile();
public void actionPerformed(ActionEvent event)
if (event.getSource() == addNextButton)
getInputs();
if (event.getSource() == summaryButton)
displaySummary();
// finds the index of the item number entered
public int linearSearch( int array[], int item )
throws NumberFormatException
for (int counter = 0; counter < array.length; counter++ )
if ( array[ counter ] == item )
return counter;
return -1; //item not found
// right justify strings representing amounts in a field of 10 spaces
public String rightJustify(String s1)
final int fieldWidth = 10;
int spacesNeeded;
String paddedSpaces = "";
spacesNeeded = fieldWidth - s1.length();
for(int count=0 ; count < spacesNeeded; ++count)
paddedSpaces += " ";
return paddedSpaces + s1;
public void loadArrays(int itemNumber2[],String desc2[],double itemPrice2[])
File inputFile = new File("C:\\product.txt");
ItemRecord record;
try {
input = new ObjectInputStream( new FileInputStream( inputFile ) );
catch (IOException ioException) {
JOptionPane.showMessageDialog(this, "Error Opening File","Error",JOptionPane.ERROR_MESSAGE);
try {
for (int counter = 0; counter < itemNumber2.length; counter++)
record = ( ItemRecord ) input.readObject();
itemNumber2[counter] = record.getItemNumb();
desc2[counter] = record.getItemDesc();
itemPrice2[counter] = record.getItemPrice();
} // end for
} //end try
catch ( EOFException endOfFileException ) {
JOptionPane.showMessageDialog( this, "No more records in file",
"End of File", JOptionPane.ERROR_MESSAGE );
catch ( ClassNotFoundException classNotFoundException ) {
JOptionPane.showMessageDialog( this, "Unable to create object",
"Class Not Found", JOptionPane.ERROR_MESSAGE );
catch (IOException ioException) {
JOptionPane.showMessageDialog(this, "Error Opening File","Error",JOptionPane.ERROR_MESSAGE);
} // end method loadArrays
private void closeFile()
// close file and exit
try {
input.close();
System.exit( 0 );
// process exception while closing file
catch ( IOException ioException ) {
JOptionPane.showMessageDialog( this, "Error closing file",
"Error", JOptionPane.ERROR_MESSAGE );
System.exit( 1 );
} // end method closeFile
public static void main( String args[] )
OrderCalculator4 application = new OrderCalculator4();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} //end class OrderCalculator4

Well, does the input file actually exist?
Anyway, instead of hardcoding the string "Error opening file" and leaving it at that, how about actually printing some data from the exception you caught? That might give you more relevant and useful information.
ioexception.printStackTrace() is always nice.
When you post code on these forums, please wrap it in &#91;code]&#91;/code] tags so it's readable.

Similar Messages

  • I keep getting /3212 please help

    I am trying to bring up my full library on my computer and it keeps giving me the code /3212

    Hi metsrule6349 ,
    Hope you have the manuals
    First we try to get it on the air like this:
    Connect the router and the modem with an ethernet cable.
    Turn the Motorola on, leave the linksys off. Log in with the
    computer on your Motorola modem and type it's ip access:
    http://192.168.100.1 (check the manual) If the ip access of
    your Motorola modem is http//192.168.100.xxx then
    we need to ask help from Ralph. Any other number is fine.
    Now we switch the Lynksys on Log in to the Linksys with:
    http://192.168.0.224 (check the manual) and it's ip address
    should now be the same as your modem. If not, ask Ralph if
    he can help you. Leave everything in default and just check
    wether UPnP iis enabled.
    Ready to go online! Let the Mac's network assistant walk you through
    the Mac's config.
    JP
    I presumed your Motorola was a Surfboard streaming modem.
    (We can test that by looking if the Linksys gets the same ip address)
    If this is correct we need to check wether the linksys has NPnP
    enabled if so that's all

  • I'm trying to install Adobe Flash Player, and I keep getting a message that says I keep getting disconnected-Please Help!!!!!!!

    I'm so lost!!!!

    Welcome to the Adobe Forums.
    To better assist you with this issue we need to know:
    What is your operating system? (Windows or Mac) (XP, Vista, 7, 8)
    What browser do you use? (Internet Explorer, Firefox, Chrome, Opera, Safari)

  • HT201493 How do I get my old apple ID/email from popping up and asking to verifie it's getting annoying? I've change everything to my new email an my old one keeps popping up please help me stop it from popping up all the time?

    How do I get my old apple ID/email from popping up and asking to verifie it's getting annoying? I've change everything to my new email an my old one keeps popping up please help me stop it from popping up all the time?

    Did you change the ID you are using for iCoud?  If so, did you delete the account, then sign back in with your new ID on your device?

  • HT1476 My charging cables keep malfunctioning! Please help @ £15 a time having an iphone is getting exspensive

    My charging cables keep malfunctioning! Please help @ £15 a time having an iphone is getting exspensive

    If the cable that came with it went bad with in a year, it's still under warranty. Have it replaced.

  • HT1420 I get en error message 42408. I have tried several times to activate my account but the same message keeps reappearing. Please help. I cant even sink my iPad or iPhone. Thanks

    I get en error message 42408. I have tried several times to activate my account but the same message keeps reappearing. Please help. I cant even sink my iPad or iPhone. Thanks

    After searching, found a few answers and tried one last thing-- allowing Safari to accept Cookies. I never use Safari so never changed any settings in it ever. However, I guess an update along the way turned off cookies in it and that was the blockage. Once I allowed Safari to use cookies I was able to redeem the gift card. SO, glad this board is here for these types of questions!!!!

  • I keep getting a Please wait while windows configures itunes

    I keep getting a Please wait while windows configures itunes...
    It started this afternoon, I thought nothing of it and reinstalled itunes again and that seemed to have fixed the problem, but the problem has reoccurred.
    I've done a bit of research on how to fix for example going through to the regedit and changing the pcast Permissions etc but this hasn't helped at all, if anything Its made things worse because I cant uninstall itunes now.
    Please can anybody help me.
    Cheers

    If iTunes launches eventually then it's simply a matter of the installer not having correctly updated the shortcuts.
    Delete the shortcut to iTunes on your desktop and, if you have them, in the recently used/favouite applications area of the start menu and/or quick launch menu. Use the main *All Programs > iTunes > iTunes* icon to start iTunes. Copy this icon out to your desktop and/or quick launch menu if required.
    If that still doesn't work, create a new shortcut from the file at C:\Program Files\iTunes\iTunes.exe and replace all existing shortcuts with the new one.
    If iTunes won't start at all then you have another problem that I'm thankfully (at least for me) not familiar with...
    tt2
    Message was edited by: turingtest2

  • I keep getting the iTunes help screen in German Language on restart, how do I stop this?

    Ugraded to iTunes 10.5 and now on restart I keep getting the iTunes help screen in German Language how do I stop this?

    Hi Thanks,
    I could only see posts from some months ago and thought I had something different.
    Looks like I have not been using the correct search terms.
    Will wait and see what happens.

  • Hi, i just updated my iphone 3gs to iso5 now it will not activate ive ''try again'' alot but not getting anywere please help!!

    hi, i just updated my iphone 3gs to iso5 now it will not activate ive pressed ''try again'' alot but not getting anywere please help! i need my phone for work not had it too long and really annoyed lol thanks,

    Sorry, but Apple does not provide a downgrade path for iOS.
    Because downgrading is unsupported by Apple we cannot discuss it on these forums, but you can use Google to find information on how to install an older version of iOS on any device.
    Note that you will void the warranty and loose official support by Apple.
    Feel free to let Apple know at http://www.apple.com/feedback
    Anyway, give a try resetting all your settings:
    Settings > General > Reset > Reset All Settings

  • TS1702 Why won't my apps install on my ipad? it keeps waiting. Please help

    Why won't my apps install on my iPad, it just keeps waiting. Please help.
    Thanks.

    These are all steps that have worked for some other users in the past. They may not work for you, but they are worth a try.
    Make sure that you do not have a stalled download in iTunes - a song or podcast .... if you have a download in there that did not finish, complete that one first. Only one thing can download at a time on the iPad so that could be what is causing the problem.
    If that doesn't work - sign out of your account, restart the iPad and then sign in again.
    Settings>Store>Apple ID. Tap your ID and sign out. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Go back to Settings>Store>Sign in and then try to update again. Tap one waiting icon only if necessary to start the download stream.
    You can also try deleting the waiting icons - tap and hold down on an icon until it wiggles - the tap the X on the icon to delete it. Then try to download again.
    You can try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your app preferences and device settings again.

  • Not getting Result please Help

    Hi All
    query_string VARCHAR2(2000);
    query_string are EMPNO,ENAME
    for rec1 in (SELECT query_string FROM p_table_name ) loop
    utl_file.put_line(v_file, rec1.result1);
    END LOOP;
    not getting Result please Help
    Regards

    You may look at this:
    michaels>  DECLARE
       cur            sys_refcursor;
       query_string   VARCHAR2 (2000) := '';
       p_table_name   VARCHAR2 (30)   := UPPER ('emp');
       p_stmt         LONG;
    BEGIN
       FOR c IN (SELECT ROWNUM rn, column_name, COUNT (*) OVER () cnt
                   FROM user_tab_cols
                  WHERE table_name = p_table_name AND hidden_column = 'NO')
       LOOP
          query_string :=
             query_string || c.column_name
             || CASE
                WHEN c.rn != c.cnt
                   THEN ' || ''|'' || '
             END;
       END LOOP;
       p_stmt := 'select ' || query_string || ' FROM ' || p_table_name;
    -- DBMS_OUTPUT.put_line (p_stmt);
       OPEN cur FOR p_stmt;
       FOR rec1 IN (SELECT EXTRACTVALUE (t.COLUMN_VALUE, '/ROW//text()') result1
                      FROM TABLE (XMLSEQUENCE (cur)) t)
       LOOP
          /*  replace with utl_file in case ... */
          DBMS_OUTPUT.put_line (rec1.result1);
       END LOOP;
       CLOSE cur;
    END;
    7369|SMITH|CLERK|7902|17-DEC-80|800||20
    7499|ALLEN|SALESMAN|7698|20-FEB-81|1600|300|30
    7521|WARD|SALESMAN|7698|22-FEB-81|1250|500|30
    7566|JONES|MANAGER|7839|02-APR-81|2975||20
    7654|MARTIN|SALESMAN|7698|28-SEP-81|1250|1400|30
    7698|BLAKE|MANAGER|7839|01-MAY-81|2850||30
    7782|CLARK|MANAGER|7839|09-JUN-81|2450||10
    7788|SCOTT|ANALYST|7566|19-APR-87|3000||20
    7839|KING|PRESIDENT||17-NOV-81|5000||10
    7844|TURNER|SALESMAN|7698|08-SEP-81|1500|0|30
    7876|ADAMS|CLERK|7788|23-MAY-87|1100||20
    7900|JAMES|CLERK|7698|03-DEC-81|950||30
    7902|FORD|ANALYST|7566|03-DEC-81|3000||20
    7934|MILLER|CLERK|7782|23-JAN-82|1300||10
    PL/SQL procedure successfully completed.

  • Wat is wrong in this decode function, it doesn get executed,please help me

    wat is wrong in this decode function, it doesn get executed,please help me
    decode(DVI.COMPANY||'.')||
                                            DECODE(DVI.COST_CENTRE||'.')||
                                            DECODE(DVI.ACCOUNT||'.')||
                                            DECODE(DVI.LOCATION||'.')||
                                            DECODE(DVI.PRODUCT||'.')||
                                            DECODE(DVI.FUTURE)company_id,

    Hi,
    I could not understand what you are trying to do with decode here.
    The standard way of using the decode is like :
    SQL>SELECT DECODE (1 , 1 ,'TRUE','FALSE') FROM DUAL;
    DECO
    TRUE
    1 row selected.
    1* SELECT DECODE (1 , 0 ,'TRUE','FALSE') FROM DUAL
    SQL>/
    DECOD
    FALSE
    1 row selected.
    Please explain what you want to do with DECODE ?
    Regards

  • Keep getting error installation helper has stopped working for readstep2

    keep getting error installation helper has stopped working for readstep2

    attach a screenshot of that error message, FAQ: How do I capture and post a screen shot or... | Adobe Community

  • When i want delete music in my ipad i make sync in itunes without music but the music not remove from ipad i get problim please help me my email

    when i want delete music in my ipad i make sync in itunes without music but the music not remove from ipad i get problim please help me my email

    hi i think you can used itools is very esye for add and delete eny thing that is link http://www.itools.cn/multi_lang_pc_download.htm

  • In system preferences my search engine and homepage are set for google but my computer keeps using BING, please help!

    I have system preferences > general > homepage and search engine set as google but my computer keeps using BING! Please help!

    You installed the "Genieo/InstallMac" rootkit. The product is a fraud, and the developer knowingly distributes an uninstaller that doesn't work. I suggest the tedious procedure below to disable Genieo. This procedure may leave a few small files behind, but it will permanently deactivate the rootkit (as long as you never reinstall it.)
    Malware is constantly changing to get around the defenses against it. The instructions in this comment are valid as of now, as far as I know. They won't necessarily be valid in the future. Anyone finding this comment a few days or more after it was posted should look for more recent discussions or start a new one.
    Back up all data. You must know how to restore from a backup even if the system becomes unbootable. If you don't know how to do that, or if you don't have any backups, stop here and ask for guidance.
    Step 1
    In the Applications folder, there should be an item named "Genieo". Select it and open the Finder Info window. If it shows that the Version is less than 2.0, download and install the current version from the genieo.com website. This may seem paradoxical, since the goal is to remove it, but you'll be saving yourself some trouble as well as the risk of putting the system in an unusable state.
    There should be another application in the same folder named "Uninstall Genieo". After updating Genieo, if necessary, launch "Uninstall Genieo" and follow the prompts to remove the "newspaper-style home page." Restart the computer.
    This step does not completely inactivate Genieo.
    Step 2
    Don't take this step unless you completed Step 1, including the restart, without any error messages. If you couldn't complete Step 1, stop here and ask for instructions.
    Triple-click anywhere in the line below on this page to select it:
    /Library/Frameworks/GenieoExtra.framework
    Right-click or control-click the line and select
    Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.
    If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.
    A folder should open with an item named "GenieoExtra.framework" selected. Move that item to the Trash. You'll be prompted for your administrator password.
    Move each of these items to the Trash in the same way:
    /Library/LaunchAgents/com.genieo.completer.update.plist
    /Library/LaunchAgents/com.genieo.engine.plist
    /Library/LaunchAgents/com.genieoinnovation.macextension.plist
    /Library/LaunchDaemons/com.genieoinnovation.macextension.client.plist
    /Library/PrivilegedHelperTools/com.genieoinnovation.macextension.client
    /usr/lib/libgenkit.dylib/usr/lib/libgenkitsa.dylib
    /usr/lib/libimckit.dylib
    /usr/lib/libimckitsa.dylib~/Library/Application Support/com.genieoinnovation.Installer~/Library/LaunchAgents/com.genieo.completer.download.plist
    ~/Library/LaunchAgents/com.genieo.completer.update.plist
    If there are other items with a name that includes "Genieo" or "genieo" alongside any of those listed above, move them as well. There's no need to restart after each one. Some of these items will be absent, in which case you'll get a message that the file can't be found. Skip that item and go on to the next one.
    Restart and empty the Trash. Don't try to empty the Trash until you have restarted.
    Step 3
    From the Safari menu bar, select
    Safari ▹ Preferences... ▹ Extensions
    Uninstall any extensions you don't know you need, including ones called "Genieo" or "Omnibar," and any that have the word "Spigot" or "InstallMac" in the description. If in doubt, uninstall all extensions. Do the equivalent for the Firefox and Chrome browsers, if you use either of those.
    Your web browser(s) should now be working, and you should be able to reset the home page and search engine. If not, stop here and post your results.
    Make sure you don't repeat the mistake that led you to install this software. Chances are you got it from an Internet cesspit such as "Softonic" or "CNET Download." Never visit either of those sites again. You might also have downloaded it from an ad in a page on some other site. The ad has a large green button labeled "Download" or "Download Now" in white letters. The button is designed to confuse people who intend to download something else on the same page. If youever download a file that isn't obviously what you expected, delete it immediately.
    You may be wondering why you didn't get a warning from Gatekeeper about installing software from an unknown developer, as you should have. The reason is that the Genieo developer has a codesigning certificate issued by Apple, which causes Gatekeeper to give the installer a pass. Apple could revoke the certificate, but as of this writing, has not done so, even though it's aware of the problem. It must be said that this failure of oversight is inexcusable and has seriously compromised the value of Gatekeeper and the Developer ID program. You cannot rely on Gatekeeper alone to protect you from harmful software.
    Finally, be forewarned that when Genieo is mentioned on this site, the developer sometimes shows up under the name "Genieo support." If that happens, don't believe anything he says, but feel free to tell him what you think of his scam.

  • MacBook Pro is not turning on and keeps beeping. Please help!!

    My MacBook Pro 13" is not turning on. It keeps beeping three times then pauses and repeats. It froze earlier today and I had to force a shutdown. I've done this before and it's worked fine. How do I get it to work again??? Please help.

    Three beeps at startup indicates that your RAM hasn't passed the integrity check and one of the modules is faulty.
    Power On Self-Test Beep Definition - Part 2 - Support - Apple

Maybe you are looking for

  • Shoddy Product Nokia Asha 311

    I purchased this phone on 10th Sept 2012. In the first week of October, the touch screen would not function, rendering the phone useless. I was informed that it was a software problem and would require the phone to be sent to the service centre for a

  • I can not load a valid copy of office 2008 for mac.

    It gets nearly all the way loaded then I get a disc failure. I have a valid product key and a product ID. Di I have to load boot camp first? I am new to Apple.

  • How to Set External Speakers as Default output

    Everytime I reboot my Mac Pro, the computer defaults to the built in monitor speakers.  I have a nice set of Altec Lansing powered external speakers that I would like to use.  I have to go into system preferences and change my audio out to "Line Out"

  • Oracle portal import hangs - no errors

    I was trying to Import a newly developed page group into production environment from development environment. Running Script to Create an Export Dump File - no errors from portal or on backend. Running Script on Target System - No errors. Running imp

  • Workspace and associated Applications

    How can I tell what applications reside in which workspaces. I don't have access to the Admin web site, but I do have access to the Oracle tables and objects. I am brand new at this, and we are trying to recover this application after a few people le