#cant call method despite it being there

1 messages ยท Page 1 of 1 (latest)

lyric pythonBOT
#

<@&987246399047479336> please have a look, thanks.

#

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:

  1. The method getFee() may not be defined or accessible in the Baby class. Make sure that the method is properly declared and implemented in the Baby class.

  2. The method getFee() may be defined with different parameters or return type in the Baby class compared to where it is being called. Check that the method signature matches in both places.

  3. The instance of the Baby class where you are trying to call getFee() may not be properly instantiated or initialized. Ensure that you have created an instance of the Baby class and assigned it to a variable before calling its methods.

  4. 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.

spiral chasm
#

apparently u dont have it there

soft crystal
#

show the error please

spiral chasm
#

please share the baby class and the full error message

lyric pythonBOT
#

cant call method despite it being there

#

Changed the title to cant call method despite it being there.

spiral chasm
#

perhaps it also just returns the wrong type

#

hard to tell. just show the error

#

and the baby class

cursive hazel
#

ok hold on

#

the error is cannot find symbol

native slate
spiral chasm
#

and the full baby class please

cursive hazel
cursive hazel
spiral chasm
#

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

spiral chasm
cursive hazel
cursive hazel
cursive hazel
spiral chasm
#

screenshot of the error message please

cursive hazel
#

cannot find symbol.....symbol: method getFee().....location: variable b of type Baby

#

is it because of the arraylist baby?

native slate
#

this isnt helpful at all

spiral chasm
#

can u please upload the full Baby.java and BabyCareCenter.java files

#

drag drop them here

native slate
cursive hazel
#

let me try again

spiral chasm
#

thanks

spiral chasm
#

no

#

u uploaded entirely empty files

native slate
#

lol

#

I think you didnt save your files in your ide

spiral chasm
#

or that

#

hit ctrl+s in all ur files

native slate
#

lol

cursive hazel
#

ok i'll save them

cursive hazel
native slate
#

which ide are you even using?

cursive hazel
#

19

#

do i need to save each class or one of them

native slate
#

all of them

spiral chasm
#

with IDE they meant the program ur using to write java in

#

majority of people use IntelliJ

#

it seems ur using sth quite old

cursive hazel
#

hold on .. what about manually copy the code?

spiral chasm
#

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

spiral chasm
#

cause its super old likely

#

yeah... netbeans

#

thats used by like 3% of java users

#

(for a reason)

native slate
cursive hazel
#

these 3% learnt java at uni like me

spiral chasm
#

did u save all files? is the issue still there?

cursive hazel
native slate
#

just a guess though

cursive hazel
#

wowwww ,its gone!

spiral chasm
#

if its still there, please locate the files on ur disk in ur explorer and drag drop them

#

ah perfect

#

๐Ÿ™‚

native slate
#

lmao

cursive hazel
#

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 ?

worn pumice
#

in case you're doing operations on them, when they're not primitives.

cursive hazel
#

can u explain more about " when they're not primitives."

cursive hazel
worn pumice
#

int, byte, short, long, float, double, boolean and char

cursive hazel
#

i guess its double

native slate
#

it is a primitive type

cursive hazel
#

so we have to initialize or?

native slate
#

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

worn pumice
#

primitives have a default value

native slate
#

and reference types are null by default

worn pumice
#

0 in this case

native slate
#

and you cant do operations with null

#

like calling a method

cursive hazel
#

ok ..u mean if i use variable type another class then i have to initialize cause it doesnt have default value?

worn pumice
#

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()

native slate
#

but its good to know that those exists

worn pumice
#

CustomType customType = new CustomType() @cursive hazel

cursive hazel
worn pumice
#

@native slate indeed, a tad early, I just wanted to already mention the concept.

cursive hazel
native slate
worn pumice
#

Primitive types cannot be null

#

only Objects can be

cursive hazel
cursive hazel
spiral chasm
native slate
#

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;
spiral chasm
#

local variables never auto initialize

native slate
#

yeah I simplify a bit

#

but tbh quite important to know

spiral chasm
#

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

cursive hazel
spiral chasm
#
class Foo {
  int x; // <- field

  public void foo() {
    int y; // <- local var
  }
}
cursive hazel
spiral chasm
#

(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

cursive hazel
#

thats why sometimes we get errors when we use it without initialization ?

cursive hazel
spiral chasm
cursive hazel
spiral chasm
#

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

cursive hazel
#

what is allowed then

spiral chasm
#

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 ๐Ÿ˜›

cursive hazel
#

aha , is it a syntax error

spiral chasm
#

its a compilation error

cursive hazel
cursive hazel
cursive hazel
#

"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?

soft crystal