Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting "must be caught or declared to be thrown" on my program?
    primarykey
    data
    text
    <p>I have been working on this program for quite sometime and my brain is fried. I could use some help from someone looking in.</p> <p>I'm trying to make a program that reads a text file line by line and each line is made into an <code>ArrayList</code> so I can access each token. What am I doing wrong? </p> <pre><code>import java.util.*; import java.util.ArrayList; import java.io.*; import java.rmi.server.UID; import java.util.concurrent.atomic.AtomicInteger; public class PCB { public void read (String [] args) { BufferedReader inputStream = null; try { inputStream = new BufferedReader(new FileReader("processes1.txt")); String l; while ((l = inputStream.readLine()) != null) { write(l); } } finally { if (inputStream != null) { inputStream.close(); } } } public void write(String table) { char status; String name; int priority; ArrayList&lt;String&gt; tokens = new ArrayList&lt;String&gt;(); Scanner tokenize = new Scanner(table); while (tokenize.hasNext()) { tokens.add(tokenize.next()); } status = 'n'; name = tokens.get(0); String priString = tokens.get(1); priority = Integer.parseInt(priString); AtomicInteger count = new AtomicInteger(0); count.incrementAndGet(); int pid = count.get(); System.out.println("PID: " + pid); } } </code></pre> <p>I am about to poke out my eyeballs. I got three errors:</p> <pre><code>U:\Senior Year\CS451- Operating Systems\Project1 PCB\PCB.java:24: unreported exception java.io.IOException; must be caught or declared to be thrown inputStream.close();} ^ U:\Senior Year\CS451- Operating Systems\Project1 PCB\PCB.java:15: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown inputStream = new BufferedReader(new FileReader("processes1.txt")); ^ U:\Senior Year\CS451- Operating Systems\Project1 PCB\PCB.java:18: unreported exception java.io.IOException; must be caught or declared to be thrown while ((l = inputStream.readLine()) != null) { ^ </code></pre> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload