Java unreported exception reading an input stream [duplicate]
up vote
-2
down vote
favorite
This question already has an answer here:
Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
5 answers
My code for reading an input stream of numbers and sorts them into an array, returns
error:
unreported exception IOException; must be caught or declared to be thrown
on String lines = br.readLine();
public int inputArr() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}
Any help please on this?
java arrays input compiler-errors
marked as duplicate by Hovercraft Full Of Eels
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-2
down vote
favorite
This question already has an answer here:
Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
5 answers
My code for reading an input stream of numbers and sorts them into an array, returns
error:
unreported exception IOException; must be caught or declared to be thrown
on String lines = br.readLine();
public int inputArr() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}
Any help please on this?
java arrays input compiler-errors
marked as duplicate by Hovercraft Full Of Eels
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Either you add athrows IOExceptionto your method signature or youtry {} catch (IOException e) {}it... You have those two options to report possibleExceptions.
– deHaar
Nov 7 at 20:34
Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
This question already has an answer here:
Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
5 answers
My code for reading an input stream of numbers and sorts them into an array, returns
error:
unreported exception IOException; must be caught or declared to be thrown
on String lines = br.readLine();
public int inputArr() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}
Any help please on this?
java arrays input compiler-errors
This question already has an answer here:
Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
5 answers
My code for reading an input stream of numbers and sorts them into an array, returns
error:
unreported exception IOException; must be caught or declared to be thrown
on String lines = br.readLine();
public int inputArr() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String lines = br.readLine();
String strs = lines.trim().split("\s+");
int a = new int [strs.length];
for (int i = 0; i < strs.length; i++) {
a[i] = Integer.parseInt(strs[i]);
}
return a ;
}
Any help please on this?
This question already has an answer here:
Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
5 answers
java arrays input compiler-errors
java arrays input compiler-errors
asked Nov 7 at 20:33
A.Cvijanovic
21
21
marked as duplicate by Hovercraft Full Of Eels
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Hovercraft Full Of Eels
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 7 at 20:36
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Either you add athrows IOExceptionto your method signature or youtry {} catch (IOException e) {}it... You have those two options to report possibleExceptions.
– deHaar
Nov 7 at 20:34
Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37
add a comment |
Either you add athrows IOExceptionto your method signature or youtry {} catch (IOException e) {}it... You have those two options to report possibleExceptions.
– deHaar
Nov 7 at 20:34
Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37
Either you add a
throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.– deHaar
Nov 7 at 20:34
Either you add a
throws IOException to your method signature or you try {} catch (IOException e) {} it... You have those two options to report possible Exceptions.– deHaar
Nov 7 at 20:34
Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37
Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
BufferedReader.readLine() throws an IOException:
public String readLine() throws IOException {
So any call to it must handle it by either:
- Surrounding with try/catch block
- Declaring that your method also throws that exception.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
BufferedReader.readLine() throws an IOException:
public String readLine() throws IOException {
So any call to it must handle it by either:
- Surrounding with try/catch block
- Declaring that your method also throws that exception.
add a comment |
up vote
0
down vote
BufferedReader.readLine() throws an IOException:
public String readLine() throws IOException {
So any call to it must handle it by either:
- Surrounding with try/catch block
- Declaring that your method also throws that exception.
add a comment |
up vote
0
down vote
up vote
0
down vote
BufferedReader.readLine() throws an IOException:
public String readLine() throws IOException {
So any call to it must handle it by either:
- Surrounding with try/catch block
- Declaring that your method also throws that exception.
BufferedReader.readLine() throws an IOException:
public String readLine() throws IOException {
So any call to it must handle it by either:
- Surrounding with try/catch block
- Declaring that your method also throws that exception.
answered Nov 7 at 20:36
Mike
1,174716
1,174716
add a comment |
add a comment |
Either you add a
throws IOExceptionto your method signature or youtry {} catch (IOException e) {}it... You have those two options to report possibleExceptions.– deHaar
Nov 7 at 20:34
Please Google your error message (please click on link) before asking as most questions have been asked before, and in this case many times before.
– Hovercraft Full Of Eels
Nov 7 at 20:37