|
-
January 30th, 2015, 03:33 PM
#1
A simple fix? Java SE Runtime Environment build 1.8.0
Hi Java fanatics,
I'm relatively new to the game, and there's this code that is giving me a few headaches. I was hoping one of you could help me figure out, what's the issue...
This is part of the code:
Code:
public static int addAddress (String[] number, boolean[] front, double[] total) {
int num = 0;
double ffee = 0;
/*boolean value = false;*/
do
{
number[num]= JOptionPane.showInputDialog(null, "Enter number of the cellphone.");
front[num]= defineFront(num);
total[num]= calcIndividualTotal(num, ffee);
}
while (++num < address.length && JOptionPane.showConfirmDialog(null, " another house?")==JOptionPane.YES_OPTION);
return num;
}
public static double defineFront(int num, boolean[] front)
{
double fee = 0;
oceanfront[num]= Boolean.parseBoolean(JOptionPane.showInputDialog(null,
"What's the house's front? Please enter TRUE or FALSE."));
if (oceanfront[num]== true)
{
...
}
return fee;
}
The compiler shows me the following error...
Code:
Inspection.java:33: error: method defineFront in class Inspection cannot be applied to given types;
front[num]= defineFront(num); ^
required: int,boolean[]
found: int
reason: actual and formal argument lists differ in length
1 error
I have tried using the line of code commented out, /*boolean value = false;*/. However, another error is displayed.
The compiler shows the following...
Code:
Inspection.java:33: error: incompatible types: boolean cannot be converted to boolean[]
front[num]= defineFront(num, value);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
error
I know that boolean values are by default stored as false, once you create the array. However, I'm having trouble passing the variable to the method. What do you think is wrong?
-
February 1st, 2015, 07:11 AM
#2
Re: A simple fix? Java SE Runtime Environment build 1.8.0
First you call defineFront with just one parameter but that won't work because it takes two parameters.
Then you supply a second parameter indeed but of the wrong type. If a boolean array is required then pass a boolean array and not a boolean. (Since a boolean array is an object it would be valid to pass null but if you try to use it as a boolean array you'll get a runtime exception because the null reference isn't a boolean array reference).
Last edited by razzle; February 2nd, 2015 at 05:51 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|