Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Problem with parseInt and entering in array
Lio Liov
Ranch Hand
Posts: 33
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am trying to run this code and I have problem with adding integers in the ArrayList
Could you tell me why
The exception happens on the last line
import java.io.*; import java.util.*; public class FileReader { private File fileToOpen; private Scanner scan; private ArrayList<Integer> values = new ArrayList<Integer>(); public FileReader(String openFile) { File f = new File("jobs/" + openFile + ".txt"); if (!f.exists()) { System.out.println("The file doesnt exist"); } else { fileToOpen=f; openFile(); readFile(); } } public ArrayList getArray() { return values; } private void openFile() { try { scan = new Scanner(fileToOpen); } catch (Exception e) { System.out.println("Job doesn't exist"); } } private void readFile() { try { while (scan.hasNext()) { String line = scan.nextLine(); String lineIn = line.substring(line.indexOf(':') + 1); int input=Integer.parseInt(lineIn); values.add(input); } } catch (Exception e) {System.out.println("Problem"); ////////this exception } } }
Michal Plutynski
Greenhorn
Posts: 14
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Could you give and example of file you are using (openFile.txt)?
Lio Liov
Ranch Hand
Posts: 33
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This is the file:
ram size:111
expected time:1000
priority:3
Michal Plutynski
Greenhorn
Posts: 14
I like...
posted 11 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Do not 'eat' the exception. Maybe throw 'Exception e' to the console, then you will find out what is the problem or just post your exception here.
Lio Liov
Ranch Hand
Posts: 33
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks.My problem was that I didnt trim the
string
before I parse it
But enableing the exception help me figurate the problem:)
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
NullPointerException
File.exists() Problem
Help with ArrayList error
Giving runtime error
How to extract the value?
More...