#cant call method despite it being there
1 messages ยท Page 1 of 1 (latest)
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Without seeing the specific code, it is difficult to determine the exact cause of the error. However, there are a few common reasons why this error might occur:
-
The method
getFee()may not be defined or accessible in theBabyclass. Make sure that the method is properly declared and implemented in theBabyclass. -
The method
getFee()may be defined with different parameters or return type in theBabyclass compared to where it is being called. Check that the method signature matches in both places. -
The instance of the
Babyclass where you are trying to callgetFee()may not be properly instantiated or initialized. Ensure that you have created an instance of theBabyclass and assigned it to a variable before calling its methods. -
There could be a typo or misspelling in either the method name or its invocation. Double-check for any spelling errors or inconsistencies.
If you provide more specific code examples, I can help pinpoint the exact issue causing the error.
apparently u dont have it there
show the error please
please share the baby class and the full error message
cant call method despite it being there
Changed the title to cant call method despite it being there.
perhaps it also just returns the wrong type
hard to tell. just show the error
and the baby class
just show us the full error log pls
and the full baby class please
dont know how
ok
screenshot the entire error message the IDE shows u please
it likely says more than just "cannot find symbol"
which u omitted
put ur mouse over the red lines, then u get a popup with the error message
either type it out fully or give a screenshot
u can just drag drop the file to discord
wasnt successful
i'll try to type it
screenshot of the error message please
cannot find symbol.....symbol: method getFee().....location: variable b of type Baby
is it because of the arraylist baby?
this isnt helpful at all
can u please upload the full Baby.java and BabyCareCenter.java files
drag drop them here
how would we know without seeing the code
let me try again
thanks
lol
ok i'll save them
._.
which ide are you even using?
all of them
with IDE they meant the program ur using to write java in
majority of people use IntelliJ
it seems ur using sth quite old
hold on .. what about manually copy the code?
at this point, i suspect the issue is not the code u wrote
but that u didnt save
and ur IDE being too stupid to autosave
netBeans
cause its super old likely
yeah... netbeans
thats used by like 3% of java users
(for a reason)
and it cant find the method because it checks the saved file and not the edited not saved file inside the ide
these 3% learnt java at uni like me
did u save all files? is the issue still there?
wow
let me try
just a guess though
wowwww ,its gone!
if its still there, please locate the files on ur disk in ur explorer and drag drop them
ah perfect
๐
lmao
guess netBeanse going to give me headach
anyway thanks guys
quick question, if i remove x=0 ,and just put it as x;..is it correct
when its necessary to initialize variables ?
in case you're doing operations on them, when they're not primitives.
can u explain more about " when they're not primitives."
so is it ok in this case ?
int, byte, short, long, float, double, boolean and char
so here x is not primitive ?
i guess its double
it is a primitive type
so we have to initialize or?
no you dont have to
but if you have a reference type and do some operation on them you need to
primitive types have default values
primitives have a default value
and reference types are null by default
0 in this case
ok ..u mean if i use variable type another class then i have to initialize cause it doesnt have default value?
Also to jump a bit ahead, you don't need that intermediary value. You can also do: list_b.stream().map(Baby::getFee).mapToInt(Integer::intValue).sum()
wouldnt introduce that yet
but its good to know that those exists
CustomType customType = new CustomType() @cursive hazel
but u said we dont have to initialize the primitive type
@native slate indeed, a tad early, I just wanted to already mention the concept.
that looks advanced
yeah, but here I was talking about reference types
hmm is it related to class Object ?
oh thats why we dont have to initialize them ?
thats only the case for fields
there are two types of variables in java:
primitive:
byte
short
int
long
float
double
char
boolean
and reference types which are subclasses of Object
and if you have this for example:
public class Dog {
// implementation
}
and use it like this:
Dog dog;
then its basically this:
Dog dog = null;
local variables never auto initialize
fields do auto initialize for primitives as well
i guess my point is, the reason why init is necessary here is bc its a local var
not bc its a primitive
lets say we are going to use this variable inside the main method ..to use it in a loop ..its gonna be same case here right ?cause its local?
any variable that u didnt define in class-scope is local
class Foo {
int x; // <- field
public void foo() {
int y; // <- local var
}
}
so we have to initialize it ..doesnt matter wither its primitive or not ?
okay ๐
yes
(before u use it)
u can split it into multiple lines. but u have to init it before u use/read it
int x;
...
x = 5;
System.out.println(x);
thats okay, unless u attempt to use/read x beforehand
thats why sometimes we get errors when we use it without initialization ?
is it a method?
what?
didnt get the use/read part
if u attempt to read the value of the variable when its not initialized
int x;
System.out.println(x); // bad
int y = x + 1; // also bad
x++; // also bad
anything that would read what value is behind x wouldnt be allowed
what is allowed then
cause I've been doing these
definitely not
u likely first initialized the variable
int x = 0;
ur question was about what if u dont initialize it
i.e. just int x;
gotta pay attention to the details ๐
aha , is it a syntax error
its a compilation error
with alot of info ..how would i pay attention
okay got it .. thx
"it is necessary cause the variable wont just automatically start with a value like 0", here u mean that because its local ? like u said earlier?
yes
It's a skill issue ๐
You have to save