Errors driving me crazy! But, it all compiles fine

Errors driving me crazy! although compiles fine
I am working on a project for an online class - I am teaching myself really! My last assignment I cannot get to work. I had a friend who "knows" what he is doing help me. Well that didn't work out too well, my class is a beginner and he put stuff in that I never used yet. I am using Jgrasp and Eclipse. I really am trying but, there really is no teacher with this online class. I can't get questions answered in time and stuff goes past due. I am getting this error:
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader .java:55)
at java.util.Scanner.<init>(Scanner.java:590)
at ttest.main(ttest.java:54)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
This is my code:
import java.util.*;
import java.io.*;
public class ttest
static Scanner console = new Scanner(System.in);
public static void main(String[] args)throws IOException
FileInputStream fin = null; // input file reference
PrintStream floser = null; // output file references
PrintStream fwinner = null;
Scanner rs; // record scanner
Scanner ls; // line scanner
String inputrec; // full record buffer
int wins; // data read from each record
int losses;
double pctg;
String team;
String best = null; // track best/worst team(s)
String worst = null;
double worst_pctg = 2.0; // track best/worst pctgs
double best_pctg = -1.0;
int winner_count = 0; // counters for winning/losing records
int loser_count = 0;
// should check args.length and if not == 1 generate error
try
Scanner inFile = new Scanner(new FileReader("football.txt"));
catch( FileNotFoundException e )
System.exit( 1 );
try
floser = new PrintStream( new FileOutputStream( "loser.txt" ) );
fwinner = new PrintStream( new FileOutputStream( "winner.txt" ) );
catch( FileNotFoundException e )
System.out.printf( "unable to open an output file: %s\n", e.toString() );
System.exit( 1 );
try
rs = new Scanner( fin );
while( rs.hasNext( ) )
inputrec = rs.nextLine( ); /* read next line */
ls = new Scanner( inputrec ); /* prevents stumble if record has more than expected */
team = ls.next( );
wins = ls.nextInt();
losses = ls.nextInt();
if( wins + losses > 0 )
pctg = ((double) wins)/(wins + losses);
else
pctg = 0.0;
if( pctg > .5 )
if( pctg > best_pctg )
best_pctg = pctg;
best = team;
else
if( pctg == best_pctg )
best += ", " + team;
fwinner.printf( "%10s %2d %2d %5.3f\n", team, wins, losses, pctg );
winner_count++;
else
if( pctg < worst_pctg )
worst_pctg = pctg;
worst = team;
else
if( pctg == worst_pctg )
worst += ", " + team;
floser.printf( "%10s %2d %2d %5.3f\n", team, wins, losses, pctg );
loser_count++;
fin.close( );
floser.close( );
fwinner.close( );
catch( IOException e ) {
System.out.printf( "I/O error: %s\n", e.toString() );
System.exit( 1 );
System.out.printf( "%d teams have winning records; %d teams have losing records\n", winner_count, loser_count );
System.out.printf( "Team(s) with best percentage: %5.3f %s\n", best_pctg, best );
System.out.printf( "Team(s) with worst percentage: %5.3f %s\n", worst_pctg, worst );
The assignment is:
Create a Java program to read in an unknown number of lines from a data file. You will need to create the data file. The contents of the file can be found at the bottom of this document. This file contains a football team's name, the number of games they have won, and the number of games they have lost.
Your program should accomplish the following tasks:
1. Process all data until it reaches the end-of-file. Calculate the win percentage for each team.
2. Output to a file ("top.txt") a listing of all teams with a win percentage greater than .500. This file should contain the team name and the win percentage.
3. Output to a file ("bottom.txt") a listing of all teams with a win percentage of .500 or lower. This file should contain the team name and the win percentage.
4. Count and print to the screen the number of teams with a record greater then .500 and the number of teams with a record of .500 and below, each appropriately labeled.
5. Output in a message box: the team with the highest win percentage and the team with the lowest win percentage, each appropriately labeled. If there is a tie for the highest win percentage or a tie for the lowest win percentage, you must output all of the teams.
Dallas 5 2
Philadelphia 4 3
Washington 3 4
NY_Giants 3 4
Minnesota 6 1
Green_Bay 3 4

If you are working in Eclipse IDE, you can set a breakpoint and single step through your code to determe what line crashes. You can also examine variable values before the crash. Locate a line before the crash and set a breakpoint by double clicking on the vertical blue line that appears immediately to the left of the line of code. A blue 'dot' will appear on the line. Then,from the menu, select 'debug as application'. This will run your main() function up to that break point. In the menu, there are icons to allow you to single step through lines of code from that point, and another icon to step over lines of code if you want.
Alternatively to setting break points, you can sprinkle your code with piles of System.out.println statements. Example: you have System.out.println("1"), and in another part of your code System.out.println("2"). If you code runs and prints out "1", but not "2", then you code crashed between them. I use breakpoints and System.out.println to debug.
In your trace, you have "at java.util.Scanner.<init>(Scanner.java:590)" which means it crashed at line 590 (note in all the tracings, Scanner.java is a name of one of your custom classes and not a vendor class, thats how you can quickly find what part of the trace is important to you).
NullPointerException means you tried to call a function on an object that is not instansiated (its null).
Example: person.getName() will not work if person is null. Its the call to getName() that crashes.
Debugging code is a very important skill set that you have to develop in which you have to logically track down and isolate problems.

Similar Messages

  • Iphone lost tunes plus "error 50" with many but not all songes

    My iPhone 3GS used to sync without difficulty to iTunes 9 running on XP
    I have recently updated to iTunes 10.0.1.22 on the PC and to 4.1 (8B117) on the Iphone 3GS
    When I try to sync the iPhone backs up successfully but I get numerous “error -50” when it tries to sync music. The song tracks themselves are not damaged in the iTunes library, they play via iTunes normally. Additionally, and alarmingly, repeated attempts to sync have wiped out most of the tunes on the iPhone, which have reduced from the 6207 there originally to 127.
    I have two Ipod 5th generation and they get the same error and have started to lose songs, though not so many as I have stopped trying to sync
    I have reinstalled iTunes clicking on the repair option ( i.e. I have not completely uninstalled iTunes) and it has made no difference, I have also bought and run a registry cleaner called Perfect Optimiser as it was recommended on some forum as a solution, and that has not improved matters.
    I suspect the problem lies with iTunes and the PC rather than with the iPhones/iPod.
    Can anybody tell me how to solve this ?

    I should add that the two iPods that we have ( not iPhones) sync correctly, though they are both seen as cameras, so I suspect that the problem is in the iPhone, and to recap, the songs the iPhone is displaying have shrunk from 6200 to 127 and when I try to sync nearly all songs come up with an error 50 banner. and sometimes iTunes tell you the iphone has all 6200 songs and sometimes only 127. Is there anyway just to clean off all the songs only from the iPhone, stop the 50 errors and just reload the music library ?

  • IDisk syncing error driving me crazy!

    Every time my iDisk syncs, it fails and I get an error message saying that a file can't be found. I know I deleted that file a few days ago. I looked on all my other computers and searched spotlight and can't find anything. I deleted some of the preferences related to syncing, and now because of this I can't sync my iDisk at all! I signed out and back into my mobile me account. I reset iSync and reset sync data in preferences.
    Can anyone PLEASE HELP? Thanks.

    You can try this simple fix -
    Quit DW.
    Find this folder -
    C:\Documents and Settings\<username>\Application
    Data\Macromedia\Dreamweaver
    8\Configuration\WinFileCache-*.dat
    (these folders are normally hidden - you may have to use
    Explorer > Tools >
    Folder Options to unhide them)
    or on Mac -
    Library/Application Support/Macromedia/Dreamweaver
    8/Configuration/MacFileCache-*.dat
    and delete it.
    Restart DW. Works better?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "jmath_sf" <[email protected]> wrote in
    message
    news:ee9lvg$5k9$[email protected]..
    > Help! I keep encountering the following error message
    when trying to
    > access the
    > EDIT menu or right-clicking:
    > At line 30 of file "Disk:Applications:Macromedia
    Dreamweaver
    > 8:Configuration:Menus:MM:Edit_Paste.js".
    > Exception thrown in native function."
    >
    > Has anyone seen this? How can I deal with this??
    >
    > Thanks!
    >

  • Mail Error - Driving Me Crazy!

    I keep getting the following error:
    "Some actions taken while the account “[email protected]” was offline could not be completed online.
    Mail has undone actions on some messages so that you can redo the actions while online. Mail has saved other messages in mailbox “INBOX” in “On My Mac” so that you can complete the actions while online.
    Additional information: The connection to the server “mail.mac.com” on port 143 timed out."
    It is from an email the was marked as junk, and then I marked it as not-junk & tried to move it to my Inbox.
    I keep trying to delete the “INBOX” in “On My Mac” & the email - I have even tried on the webmail, but it keeps showing this error.
    Any suggestions?

    Nevermind - I figured it out - I just deleted the account in Mail.app & created it again. Problem solved!

  • "File is in use" error driving me crazy

    I have a few files on an xServe drive that I am trying to delete. They are not being used by any application and I have no applications open, yet I can not delete them. I keep getting the error, "The operation cannot be completed because the item "item name" is in use."
    Other files can be deleted, only a select few continue to give me this error. Any solutions??

    This is what I get....looks like either no program is using it, or I am doing something wrong:
    Last login: Tue Jun 10 09:45:08 on ttys000
    MARK-Mark-I:~ markivey$ sudo lsof /Volumes/xserve/Marketing/Personal\ Folders/Mark\ Ivey/TRASH/4DDW1696.tif
    WARNING: Improper use of the sudo command could lead to data loss
    or the deletion of important system files. Please double-check your
    typing when using sudo. Type "man sudo" for more information.
    To proceed, enter your password, or type Ctrl-C to abort.
    Password:
    MARK-Mark-I:~ markivey$

  • ITunes server times out (error 408) with some, but not all downloads

    The episodes failing to download are "Dawn of a New Day" part 2 from "Skyland" and "Program" from "Animatrix." Everything else, 11 episodes of "Skyland" and "Animatrix", downloaded fine, so it is hard to imagine that this has anything to do with my system. I have already paid for these episodes and have tried numerous times over several days and the downloads never even get started. I would like to get what I paid for.
    G5   Mac OS X (10.3.9)   iTunes version 7.0.2

    Hi Stephen!
    If this problem persists, follow the instructions here:
    http://www.apple.com/support/itunes/musicstore/download/
    eMac   Mac OS X (10.4.8)  

  • Mail 2.1.3 on Tiger: mutiples of everything is driving me crazy!

    Hi, I recently had to reformat my hard drive and thus have been trying to reinstall all my email accounts (which I had backed up). I am using MAIL 2.1.3.
    I have several questions (this is driving me crazy!!):
    When I imported the archived files, it created new mailboxes but DID NOT reinstall my mail in it's corresponding email account file (i.e: i have an email account for incoming mail with "username", and then far below I have a mailbox (for EACH account, and I have about 7) which contains all my old mail. I can't seem to merge the two.
    When I recreated my useraccounts (most of which are gmail), I followed online instructions and created all my accounts using IMAP, since my first attempt using the POP version of these same accounts would NOT SEND OUT any of my Gmail mail. Now, for EACH ACCOUNT, not only do I have a "regular mailbox", I have the same "imported" from my old version, AND a third folder under "IMAP".... All this is REALLY driving me crazy!!
    All I want to achieve is what i had before : one version of each of my email accounts, including Gmail, that both recieve AND send mail. Nothing more.
    On the my other computer (leopard) Mail configures itself and everything works: it's bliss!!!
    Can anyone help me clear up this mess (also because as a result everything is SLOW!!)
    Infinite thanks,
    Nicaru

    Thanks BDAqua, Unfortunately I did not do a very good job explaining myself.
    I am not trying to sync two computers (Tiger/Leopard). The Leopard comment was just me venting that it was so much a better program than Tiger....
    No, what I want is simply to recreate my Mail Client the way it looked before: with one inbox per username, a single Sent/Draft/Outgoing mailbox and that's all!!
    Instead for each username I have "normal" Inboxes, PLUS imported folders (each with their own Inbox/Sent/Draft mailboxes) PLUS IMAP folders again with their own individual Inbox/Sent/Draft mailboxes). My homepage when I open Mail contains something like 21 folders, whereas I only want the 7 (one per username).
    This whole thing came about because when I tried to import my old mailboxes (pre-formatting my mac) they imported as separate folders whereas I wanted them to merge into their respective accounts.
    The other issue I had (originally) which led to this mess is that none of my Gmail accounts would SEND mail (receiving is Ok) so I followed the online IMAP instructions and this is where I got triplets....
    Gosh, I don't know how else to explain it... If it's still not clear perhaps I should just erase everything and start from scratch??
    Thanks again,
    Nicaru

  • Any solution to the network lost popup yet? Mine is driving me crazy?

    Any solution to the network lost popup problem? Mine is driving me crazy!

    With all the issues you describe, I would search for something conflicting with Mountain Lion.
    Have you booted into Safe Mode and checked to see if it works correctly there? It will take a while to boot, and it will run a bit slow, so just look for the issues you described above. If they don't appear, you've got something installed that is causing the issues.

  • I can no longer back up my iphone to my computer on selecting 'sync'. I can back up to iCloud but I get an error message telling me I cannot backup to my Mac. Can any one help? It's driving me crazy!

    I can no longer back up my iphone to my computer on selecting 'sync'. I can back up to iCloud but I get an error message telling me I cannot backup to my Mac. Can any one help? It's driving me crazy!

    Hello joelfromn. charleston,
    It seems you are unable to activate iMessage on a device with no carrier service. The following article provides information regarding activation issues:
    If you get an error when trying to activate iMessage or FaceTime - Apple Support
    Check your device settings
    Make sure that you’re connected to a cellular data or Wi-Fi network. If you're using an iPhone, you'll need SMS messaging to activate your phone number with iMessage and FaceTime. Depending on your carrier, you might be charged for this SMS.
    Go to Settings > General > Date & Time and make sure that your time zone is set up correctly.
    Thank you for contributing to Apple Support Communities.
    Cheers,
    Bobby_D

  • After the new update my ipad4 will not do a full recharge even when turned off overnight and the battery goes flat it 2 hours  it is driving me crazy as I had to stop all apps but still not helping

    After the new update my ipad4 will not do a full recharge even when turned off overnight and the battery goes flat it 2 hours  it is driving me crazy as I had to stop all apps but still not helping but my iPhone 5 is great no troubles at all HELP

    Do you place the ipod in the dock during the night? I did this once and the other day the battery was almost empty because it kept on playing after it rested in the dock.
    Here is more info about battery life and exchange program: http://support.apple.com/kb/HT1322
    and http://www.apple.com/support/ipod/service/battery/

  • I have a Galaxy S3 and love this phone but here at my new home which has absolutely no trees of bushes blocking anything, my phone calls are dropped ALL THE TIME and it's driving me crazy.  Verizon finally said that they would come out and boost the signa

    I have a Galaxy S3 and love this phone but here at my new home which has absolutely no trees of bushes blocking anything, my phone calls are dropped ALL THE TIME and it's driving me crazy.  Verizon finally said that they would come out and boost the signal but haven't seen anyone in two weeks.  I have called Verizon tech help for one year to get help with this, either trade phone or something.  I am so frustrated!  I picked Verizon for the clear calls and coverage inside hospitals and buildings but it's been terrible.  I have had three of these phones replaced.  I need a different model like the S4 or the S5 I think cause it's something in this model.

    Verizon is quickly becoming the worst cell phone company out there.  To read all of these pleas from your loyal customers is just so sad and pitiful.  You need to be sued for your data overage charges that you are intentionally imploding on your customers.  They have pleaded, very intelligently, with you to do something to fix the issue and you willingly have NOT.  As is with my reception issue that I was promised a signal booster for two months ago, so is this issue with the data.  You don't follow up and solve the issues.  Therefore the courts will find you fraudulent. When I was promised by your super tech that I needed a signal booster and he was sending it out overnight at no charge to me, I was relieved that it would finally be taken care of so I wouldn't lose faith with Verizon.  Well, that was two months ago now with no record of it ever being ordered or on my file anywhere.  I have since called three more times with hours of conversations about that issue and two more techs have told me they were sending me a signal booster with no follow up what so ever.  WOW!  That's pitiful!  You may not care now, oh but you will later when you lose lots of money and business.

  • My i tunes won't open. i keep getting error7 (windows error 193) . contacted microsoft(thought it was a windows thing...not) have uninstalled itunes and everything related to it ,re installed and message still comes up. Help please,driving me crazy.

    help. my iTunes wont open. I keep getting the message error7 (windows error 193). contacted Microsoft they said contact iTunes support. I have uninstalled all iTunes componets and then reinstalled everything but message still comes up... its driving me crazy.

    If it's a Windows error, it's typically going to be a Microsoft problem. Uninstall any security software you have and if you have a restore point for your PC, you may want to restore your PC back to when iTunes was working normally. If none of those work you would need to contact Microsoft and demand help.

  • I've added to ios6 to my new ipod touch with no problems. I'm trying to now restore the factory settings but the screen is frozen with an itunes sign and lead pointing towards it. The ipod won't even switch off. Can anyone help as it's driving me crazy

    I've added ios6 to my new ipod but tried then to restore the factory settings. It won't extract any settings and the itunes then tells me that the server cannot be reached or is unavailable. I've been trying all day. Now the ipod has a itunes sign and a computer lead pointing towards it on the screen and this is frozen. It won't switch off or do anything else. Any ideas as this is now driving me crazy.

    Try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar       

  • Every time I sync my Iphone 5c(with ios 8) to Itunes, it 1. deletes all of my purchased music 2. deletes all of my album artwork 3. replaces all of my deleted songs. please help! this is driving me crazy!

    Every time I sync my Iphone 5c(with ios 8) to Itunes, it 1. deletes all of my purchased music 2. deletes all of my album artwork 3. replaces all of my deleted songs. please help! this is driving me crazy! It syncs 100+ songs, when I only want to sync 1! I'm running Itunes 11.3.1.2

    After having experienced similar problems and having it back to work, I have a few suggestions:
    - Try to find out if the syncing stops at a particular track or song. That might - out of the blue - have gotten corrupted in one way or another. Since that song will not be on the iPod, iTunes will try over and over to put it on and crash in one way or another;
    - reformat the iPod as described in the iTunes 9 crash-thread. It takes time (at first it seems to do nothing, but that is because the green bar is moving with very small steps);
    HTH

  • This website is driving me crazy.   All I need to do is to contact a real body for help that is not listed.

    This website is driving me crazy.  All I need to do is to contact a real live body for help that is not listed.
    This shouldn't be that difficult.  GRRRRR

    Post DETAILS about the help you need here and someone may be able to help... some questions to get you started
    From the Premiere Elements Information FAQ http://forums.adobe.com/thread/1042180
    •You MUST use an account with Administrator Privileges to run Premiere Elements
    •(Doing Run as Administrator http://forums.adobe.com/thread/969395 [says Encore and also for "All" versions of Premiere] will sometimes fix "odd" errors)
    •What version of Premiere Elements? Include the minor version number (e.g., Premiere Elements 12 with the 12.0.1 update).
    •What operating system? This should include specific minor version numbers, like "Mac OSX v10.6.8"---not just "Mac"
    •Has this ever worked before?  If so, do you recall any changes you made to Premiere Elements, such as adding Plug-ins, brushes, etc.?  Did you make any changes to your system, such as updating hardware, printers or drivers; or installing/uninstalling any programs?
    •Have you installed any recent program or OS updates? (If not, you should. They fix a lot of problems.)
    •What kind(s) of image file(s)? When talking about camera raw files, include the model of camera.
    •If you are getting error message(s), what is the full text of the error message(s)?
    •What were you doing when the problem occurred?
    •What other software are you running?
    •Tell us about your computer hardware. How much RAM is installed?  How much free space is on your system (C:) drive?
    And some other questions...
    •What are you editing, and does your video have a red line over it BEFORE you do any work?
    •Which version of Quicktime do you have installed?

Maybe you are looking for

  • What is the best way to export the data out of BW into a flat file on the S

    Hi All, We are BW 7.01 (EHP 1, Service Pack Level 7). As part of our BW project scope for our current release, we will be developing certain reports in BW, and for certain reports, the existing legacy reporting system based out of MS Access and the o

  • Sql server 2000 driver problem!!! Help

    sql server driver problem hi...i want to install sql server 2000 into my IDE Jbuilder 8 Enterprise Edition i have follow the instruction that i make a config file by using enterprise setup tool, database driver in Jbuilder and location select <Jbuild

  • SLIDE SHOW ORDER

    I cannot get ATV2 to display the slides in my album in the order they are in the album.  IT goes along for a while in order, the reverts back to earlier slides. After a while it will resume later on in the order?   It may be my imigination, but when

  • Is it possible to avoid using anonymous functions in certain calls?

    Hi All, In my plugin code I have some calls similar to the following:         LrTasks.startAsyncTaskWithoutErrorHandler(function ()             -- do stuff here         end) Use of anonymous functions to pass parameters to the SDK is straight out of

  • SRKIM: R12: Payables  Accounting Data 를 R12 로 upgrade 할때 사용 되는 Scripts

    PURPOSE R11i 의 Payables Accounting 정보를 R12 로 upgrade 시 사용되는 scripts 에 대해 알아보도록 한다. EXPLANATION R12 의 AP Accounting 정보를 담는 new tables 은 아래와 같다. New Tables: XLA_EVENTS XLA_AE_HEADERS XLA_AE_LINES XLA_TRANSACTION_ENTITIES_UPG XLA_DISTRIBUTION_LINKS R12