This program won't work for some reason

I'm having trouble with getting this program to do what I want. It reads in a file and identifies certain parts that follow the rules I've given. The first version below is one that works. It simply prints out the string if it meets the conditions in the if statements. The second one will compile but shows no data. I know it stores the values in the arrays sortstem and sortdg becuase I put the println statement directly after the code for storing them and it worked. However, when I put it where it is now, it will not work. Any suggestions? Also, I get an error after the program runs for both versions: It says exception in thread "main" Java.lang.NullPointerException at tokens.main(tokens.java.69) (this was for the first program).
import java.io.*;
import java.util.*;
class tokens {
     public static void main(String args[]) throws IOException {
          int i;                                                       //int to read in the data from the text file
          int count = -1;
          int countt = -1;
          int countc = 0;                                                  //int to put data into a char array
          FileInputStream fin;                                             //input stream
          char array[] = new char[10000];                                        //array to hold chars from the text file
          String s;                                                  //chars are transfered to this String
          int index;                                                  //index of the names I'm searching for in the string
          String tokens[] = new String[10000];                    
          try {
               fin = new FileInputStream(args[0]);
          } catch (FileNotFoundException e) {
               System.out.println("File not Found");
               return;
          } catch (ArrayIndexOutOfBoundsException e) {
               System.out.println("Usage: ShowFile File");
               return;
          do {
               i = fin.read();
               if (i != -1) {
                    if (count==array.length-1) {                              //this expands the array if more space is needed
                         char temp[] = new char[array.length+5000];
                         for (int j = 0; j < array.length; j++) temp[j] = array[j];
                         array = temp;
                         array[++count] = (char) i;
                    else
                         array[++count] = (char) i;                         
          } while(i != -1);
          fin.close();
          s = new String(array);
          StringTokenizer st = new StringTokenizer(s);                                                            
          while (st.hasMoreTokens()) {
               if (countt==tokens.length-1) {                              //this expands the array if more space is needed
                         String temp1[] = new String[tokens.length+5000];
                         for (int j = 0; j < tokens.length; j++) temp1[j] = tokens[j];
                         tokens = temp1;
                         tokens[++countt] = st.nextToken();
                    else
                         tokens[++countt] = st.nextToken();     
          if (tokens[4].startsWith("stem")) {
               if (tokens[4].equals(tokens[201])) {      //Skip this one
               else
                    if ((tokens[9].equals("32")) && (tokens[15].equals("31"))
                    && (tokens[21].equals("30")) && (tokens[27].equals("29"))
                    && (tokens[33].equals("28")) && (tokens[39].equals("27"))) {
                         System.out.println(tokens[4]);
          for (int k = 201; k < tokens.length-198; k++) {
               if (tokens[k].startsWith("stem")) {
                    if ((tokens[k].equals(tokens[k+197])) || (tokens[k].equals(tokens[k-197]))) {
                         //Skip this one
                    else
                         if ((tokens[k+5].equals("32")) && (tokens[k+11].equals("31"))
                         && (tokens[k+17].equals("30")) && (tokens[k+23].equals("29"))
                         && (tokens[k+29].equals("28")) && (tokens[k+35].equals("27"))) {
                              System.out.println(tokens[k]);
}This one below compiles but doesn't print to the screen.
import java.io.*;
import java.util.*;
class tokenstest {
     public static void main(String args[]) throws IOException {
          int i;                                                       //int to read in the data from the text file
          int count = -1;
          int countt = -1;
          int countc = 0;                                                  //int to put data into a char array
          FileInputStream fin;                                             //input stream
          char array[] = new char[1000000];                                        //array to hold chars from the text file
          String s;                                                  //chars are transfered to this String
          int index;                                                  //index of the names I'm searching for in the string
          String tokens[] = new String[200000];
          String sortdg[] = new String[500];     
          String sortstem[] = new String[500];                         
          try {
               fin = new FileInputStream(args[0]);
          } catch (FileNotFoundException e) {
               System.out.println("File not Found");
               return;
          } catch (ArrayIndexOutOfBoundsException e) {
               System.out.println("Usage: ShowFile File");
               return;
          do {
               i = fin.read();
               if (i != -1) {
                    if (count==array.length-1) {                              //this expands the array if more space is needed
                         char temp[] = new char[array.length+5000];
                         for (int j = 0; j < array.length; j++) temp[j] = array[j];
                         array = temp;
                         array[++count] = (char) i;
                    else
                         array[++count] = (char) i;                         
          } while(i != -1);
          fin.close();
          s = new String(array);
          StringTokenizer st = new StringTokenizer(s);                                                            
          while (st.hasMoreTokens()) {
               if (countt==tokens.length-1) {                              //this expands the array if more space is needed
                         String temp1[] = new String[tokens.length+5000];
                         for (int j = 0; j < tokens.length; j++) temp1[j] = tokens[j];
                         tokens = temp1;
                         tokens[++countt] = st.nextToken();
                    else
                         tokens[++countt] = st.nextToken();     
          if (tokens[4].startsWith("stem")) {
               if (tokens[4].equals(tokens[201])) {      //Skip this one
               else
                    if ((tokens[9].equals("32")) && (tokens[15].equals("31"))
                    && (tokens[21].equals("30")) && (tokens[27].equals("29"))
                    && (tokens[33].equals("28")) && (tokens[39].equals("27"))) {
                         sortstem[countc] = tokens[4];
                         sortdg[countc] = tokens[3];
                         countc++;
          for (int k = 201; k < tokens.length-198; k++) {
               if (tokens[k].startsWith("stem")) {
                    if ((tokens[k].equals(tokens[k+197])) || (tokens[k].equals(tokens[k-197]))) {
                         //Do nothing
                    else
                         if ((tokens[k+5].equals("32")) && (tokens[k+11].equals("31"))
                         && (tokens[k+17].equals("30")) && (tokens[k+23].equals("29"))
                         && (tokens[k+29].equals("28")) && (tokens[k+35].equals("27"))) {
                              sortstem[countc] = tokens[k];
                              sortdg[countc] = tokens[k-1];
                              countc++;
          for (int z = 0; z < countc; z++) {
               System.out.println(sortstem[z]);
          for (int z = 0; z < countc; z++) {
               for (int y = z+1; y < countc; y++) {
                    if (sortdg[z].compareTo(sortdg[z]) > 0) {
                         String tdg = sortdg[z];
                         String tstem = sortstem[z];
                         sortdg[z] = sortdg[y];
                         sortstem[z] = sortstem[y];
                         sortdg[y] = tdg;
                         sortstem[y] = tstem;
          for (int j = 0; j < 20; j++) {
               System.out.println(sortstem[j] + ": dG = " + sortdg[j]);
          System.out.println("Test");
}

I'm still having trouble with the println in this program. For some reason, in this section of the code, if I put System.out.println(sortstem[0]); inside the for loop, it works fine. But if I try to do it ouside of this loop, it will not work. The only thing I can think of is that the variable is only available inside the loop but I just can't figure it out. Can anyone enlighten me?
for (int k = 201; k < tokens.length-198; k++) {
               if (tokens[k].startsWith("stem")) {
                    if ((tokens[k].equals(tokens[k+197])) || (tokens[k].equals(tokens[k-197]))) {
                         //Do nothing
                    else
                         if ((tokens[k+5].equals("32")) && (tokens[k+11].equals("31"))
                         && (tokens[k+17].equals("30")) && (tokens[k+23].equals("29"))
                         && (tokens[k+29].equals("28")) && (tokens[k+35].equals("27"))) {
                              sortstem[countc] = tokens[k];
                              sortdg[countc] = tokens[k-1];
                              countc++;
[code/]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

Similar Messages

  • Can't create new pdfs from powerpoint; either form within Adobe or within powerpoint.  I could do this yesterday and today it won't work for some reason.  The error says "an unexpected error occurred.  PDFMaker was unable to produce the Adobe PDF.  How do

    Can't create new pdfs from powerpoint; either form within Adobe or within powerpoint.  I could do this yesterday and today it won't work for some reason.  The error says "an unexpected error occurred.  PDFMaker was unable to produce the Adobe PDF.  How do I fix this?

    Is there a log file in the document folder indicating what the problem was. There are a number of reasons that PDF creation may fail. You can try to print to the Adobe PDF printer to see if there is any indication in that process. The processing is different, but the same problems may show up with both processes.

  • I just downloaded ilife every things working fine except, when i try to open iPhoto it said ''You can't open the application iPhoto because it may be damaged or incomplete. i tried to re-download it but my password didn't work for some reason. HELPPPP!!!

    i just downloaded ilife every things working fine except, when i try to open iPhoto it said ''You can't open the application iPhoto because it may be damaged or incomplete. i tried to re-download it but my password didn't work for some reason. HELPPPP!!!

    Make a temporary, backup copy (if you don't already have a backup copy) of the library and apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Select the options identified in the screenshot. 
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    Happy New Year

  • I cant get a photo project to email the moblile me address to someone else.  I know how, but it has stopped working for some reason.  Instead of pulling up the web address on the email form, it puts an error message?  Any ideas?

    I cant get a photo project to email the moblile me address to someone else.  I know how, but it has stopped working for some reason.  Instead of pulling up the web address on the email form, it puts an error message?  Any ideas?

    Michael,
    The link for the word 'HERE' directs to a Evergreen School District page, which outside of Mobile Me and/or Aperture. Your school district network might be intercepting the request from Aperture and displaying the 'network authentication page' that you see, instead of the email. I would get with the IT department to see if they can help you get around this.
    Have you also tried using the 'Tell a Friend' feature from another network location, like starbucks or your home?
    Cheers,
    Owen.

  • Hi i need help one of my key on the keyboard dosen't work for some reason please help

    hi i need help one of my key on the keyboard dosen't work for some reason please help

    try smc reset
    http://support.apple.com/kb/ht3964
    and Pram reset
    http://support.apple.com/kb/ht1379
    (Try pram a few times to get correct sequence)
    Check what you have selected in
    system preferences/system/accessibility/keyboard
    and system preferences/hardware/keyboard  (keyboard and keyboard short cuts tabs)

  • My FaceTime doesn't work for some reason, and i want to know why. ;\  It's iOS 6.1.6

    My FaceTime doesn't work for some reason, and i want to know why. >;\  It's iOS 6.1.6

    Judging by all the posts on the forum, there seems to be an issue at Apple's end, although they have made no announcement on their status page. Some users have reported that Apple is aware of the issue.
    http://www.apple.com/support/systemstatus/

  • My iTunes won't open for some reason.

    So for some reason my iTunes will not openm, I've clicked the shortcut, gone to the location, opened as a dmin, and still nothing. I've re-installed it plenty times, and still nothing. I have no absolute idea what is wrong. Maybe it's Quicktime or mobileme, but someone please help. I run Windows 7 64bit.

    Try following steps one at a time:
    1. Check to see if this file APSDaemon.exe is the problem here.
    Close your iTunes.
    Press Ctrl-Alt-Del key and choose Task Manager. In the "Processes" Tab, select the file APSDaemon.exe and click End Prosses button, then close the task manager window.
    Now open itunes and see if it is working?
    If that works, to prevent having to do the same process everytime you restart Windows, go to. START button, type in
    MSCONFIG
    Hit ENTER
    Click STARTUP Tab, Uncheck "Apple Push", click OK.
    Restart Windows.
    2. If you don't see ApsDaemon.exe in the Processes, refer to following article to remove SC files:
    http://support.apple.com/kb/TS2363
    Then, repair your Quicktime. START / CONTROL PANEL / PROGRAMS N FEATURES / hightlight QUICKTIME and click REPAIR.

  • This may sound stupid but for some reason I can no longer use the return button after typing in a url to go to that site. Does anyone know how to fix this?

    For some reason this stopped working on firefox a week or so ago. I have tried to uninstall and install firefox again but the problem still persists. I've tried both chrome and explorer and they don't seem to have this problem.
    I'd hate to stop using firefox but this so annoying that in less i can fix it, i'll have to change my browser!

    Hi larryhall,
    I'd try starting Firefox in [[Safe Mode]]. If you don't have the issue while all of your add-ons, extensions, and themes are disabled, you can try adding them back in one by one until you find the culprit. You should look at the [https://support.mozilla.org/en-US/kb/Troubleshooting-extensions-themes Extensions and Themes troubleshooting guide ] and the [[Troubleshooting plugins]] article as well.
    Hopefully this helps!

  • ITunes won't run for some reason... help me!!!

    I installed iTunes on my laptop in December 2005 (I got an iPod nano for Christmas). Recently, my laptop started making a funny clicking noise and, as the Best Buy guy said, "Your hard drive is shot." So, therefore, I have not been able to charge my iPod. I downloaded the updates for iPod on this desktop computer, but for some reason, iTunes wont show up. Do I have to download the software again? How do I get it working?? Please help me!!!
    eMachines   Windows 2000  

    for some reason, iTunes wont show up
    a few questions before proceeding.
    are you getting an error message? if so, what does it say? include error message numbers if you're getting any.
    or are you getting no error messages whatsoever when you try to launch itunes?
    if you're getting no error messages whatsoever, do you just see the wee hourglass for a few seconds, and then nothing? if so, do you also have Norton Internet Security 2005 installed on that PC?
    or are you seeing a brief "flash" of the itunes license screen (and then nothing)? if so, do you also see similar behavior when you try to launch your QuickTime?

  • Pse 13 for mac- Is there a digital download after you buy it disc won't read for some reason. using macbookpro.

    I bought the PSE 13 disc and put it in my laptop( macbookpro) and for some reason it won't read… all it does is run and then spit the disc out not sure what to do. Is there maybe a digital download since there is no customer service number to call…

    Download the trial version, install then enter your serial number
    http://www.adobe.com/cfusion/tdrc/index.cfm?product=photoshop_elements

  • [HELP!] My charger isn't working for some reason.

    Hey everyone!
    I am having a problem with my charger. I can't quite clarify if it's broken or not, but I know that there is something wrong with my computer or the charger itself. As a mac user, I've gone through 2 chargers so far. I'm currently on my second one because the old one broke. I've noticed that they had the exact same issues.
    Here's the story:
    First, the charger would be perfectly fine for about... a month or half a month.
    Then, the connecter (metal part) would start to overheat and the light that tells us when the computer is charging or full battery wouldn't work properly. Sometimes it would get all mixed up. For example, when it's 100% it's orange and when it's 88% it's green. Or sometimes it wouldn't even charge at all.
    I know that some of us have the sign "Not Charging" at the upper-right hand corner of our tool bar. That would occur too, in my experience. This would probably go on for about as long as my computer or charger gives up.
    Finally, I have to go down to the apple store to see what's going on with my jacked up charger.
    Last time, they said that it was the charger at fault.
    I have no idea if it's my charger or just my computer, but I'm a bit suspicious of my macbook's inner battery source though.
    Now my laptop is doing the exact same thing now as it was before. I'm so frustrated, but I never really cared about it until now; when it doesn't work.
    >:O
    This computer was a hand-me-down from my mother who got this computer from my father. He payed WAY too much for this computer and I don't want to haveit damaged; internally or externally.
    I still have my warrenty and I plan on checking it out at the apple store as soon as I come back from my vacation.
    I'm extremely anxious about this situation because I do online schooling and I'm in an area that has no apple store. At all.
    Please help me with this mess!

    It is allways helpful to indicate what model MBP you have and the OSX you are using.
    There is the posibility of a bad connection in the MBP.  Examine the electrical input port for dirt and debris.  also check to see if there is any discoloration of the contacts.
    Open System Profiler/Information and post this from your MBP.  Please make certain that the power adapter is connected.
    Ciao.

  • How do you save data into an excel file while myRIO is acquiring data? I tried saving it using "Write to file" but it doesn't work for some reason.

    I am acquiring cosine wave and a pulse wave as input and I want to store their peak to peak values into an excel file. "Write to File" is not working for it. Is there any other vi which can be used for data logging?
    Thank you for your help.

    Hi Ssheoran,
    Can you provide more detail when you say that the Write to File VI doesn't work? Is there an error given? Or can you just not find the file on your computer? Keep in mind using this file in a Real-Time VI on the myRIO will save files on the myRIO. You will then have to transfer to your PC. Please view the following video as a guide for saving files and transferring them to your computer: (http://www.youtube.com/watch?v=BuREWnD6Eno). Hope this helps.
    Best Regards,
    Roel F.
    Applications Engineer
    National Instruments

  • Iweb links won't work for some people

    Hi! I have recently made a website using iweb and most people have no troubles viewing all my pages (even if they appear slightly different than I designed them). I have gotten emails from a few people, however, saying they can't get to some of my pages.
    My website is www.ccforkids.com and the links that are causing troubles are the ones at the bottom of the slings page (sizing, instructions, etc.) there might be others, but these are the ones I have recieved emails about.
    Thanks for any help!
    iMac G5   Mac OS X (10.3.9)  

    If other people are willing to try a different browser, that seems to be the best solution, yes. Without knowing exactly what isn't working for them, I wouldn't like to say there's nothing else you can do.
    For example I find that IE for Mac (no longer supported by MS) doesn't show Apple's comments on blogs, so at the moment I'm using both those comments and iComment. I've also turned off the local iDisk, since that was making the running of both systems unworkable.
    Richard
    iMac G5 iSight   Mac OS X (10.4.7)   Power Mac G5 (10.3.9) at work, + Beige G3 (OS 9.2, 10.1.5) at home

  • My theory on why the 1.0.1 update won't work for some...

    Ok, I've racked my brain and this is the only thing I could come up w/ because I'm following the instructions to a tee. I took a closer look @ the Firmware Update page and noticed this: "It now runs on localized systems that use languages that read right to left." Idk if this makes sense but could this update not be working because I did format right when I got my MBP and chose not to install the language files? The only one I kept was English which obviously isn't right to left. The people who are having the same issue as I, did you do a clean format of Tiger as well and leave out the language files? Sorry if this is a terrible guess

    Nopes, I did a clean install of OSX the day I got my MBP, installed on English language, and have since updated to 10.4.6, Firmware 1.0 and Firmware 1.0.1. None of the installers gave me any problems. For the record, both firmwares brought my temperature down, but neither changed the whine/hiss at all.

  • Can you please cancel my  subscription?  This program is not working for me. Thank you.

    I am not happy with this program. Please cancel my  subscription.

    Hi shann1473,
    I'm sorry that your subscription didn't meet your needs. I just looked at your account, and I'm not able to cancel it myself. Please contact Adobe Customer Support; they'll be able to take care of that quickly for you. Here is the contact information:
    Contact Customer Care.
    I apologize for the inconvenience.
    Best,
    Sara

Maybe you are looking for

  • Issue in SAP CPS for Job Interception

    Issue in SAP CPS for Job Interception Scenario: After triggering a Process Chain in BW and maintaining the Job Interception settings in SAPCPS(Redwood) (so that any job which triggers in BW by that Particular User is intercepted and not let it procee

  • Printing from your iPad1 to a shared printer

    I have a usb printer connected to my desktop computer and my desktop computer is connected to my network via a network cable.  My printer is shared on the desktop but some apps cannot see it.  Primarily from Pages where i need it most.  I have the Pr

  • Java3D game problem(about wall)?(urgent " )

    I am developing a 3D shoot game which contain a 3D mase,but...why the wall is transparent when I run towards the wall??how can solve this problem?? Moreover,I wonder how to run smoothiy in 3D game??

  • How do I reinstall the free iLife apps to my Macbook Pro?

    I have a late 2008 model MacBook Pro 15. I recently had a hard drive failure. After replacing the hard drive I installed OS X Maverick. When I checked my purchased items list on iTunes the iLife apps were not listed. How do I get the free iLife apps

  • Math / array / matrix-question

    Hallo everybody, first of all: it's not a indesignscripting-  but general math-javascriptquestion. please be patient I've got a first (matrixlike-)array (won't change) var containers = [ 'container11', 'container12', 'container13', 'container14', 'co