
Error cannot find symbol in java solved
Error cannot find symbol in java solved
How to fix error cannot find symbol in java is shown
Content
0.48 -> so hey hello everyone so this video i'm
going to show you how to solve the error
3.52 -> cannot find symbol in java so there are actually
four conditions or cases that causes this error
8.16 -> so let me show you all the cases that causes this
error and maybe you can just watch them and solve
13.12 -> your error so the first thing is as you can
see here uh here i have a simple code okay
17.44 -> and its showing uh error in system.println r but
i'm actually i have initialized and declared r
24.64 -> okay so here is the int r so why is this error
so in case this error is because of the scope
30 -> of r as i am declaring as i am declaring r
inside a for loop because i am putting int
35.76 -> over here so here is a declaration so this is
uh valid only inside the scope of this for loop
42.08 -> and outside this for loop we have this r so for
this type of if i have declared some variable
47.68 -> inside a loop or a function this type of this can
error can occur but here it's clearly specified as
53.36 -> but uh some may won't be able to find this
error because you think your have declared
57.6 -> or i have initialized r i have done everything
perfect but why it's not working it's because
61.44 -> that the scope of the variable r so the best way
to solve this is just completely remove it okay
66.48 -> and just go over here for loop just type
int r equal to 20. okay so if you're just
71.28 -> assigning some values it's always better to
do outside the loop so as you can see here the
76.08 -> line under my r variable is no missing and if i
just save it now and if i run this code okay javac
81.76 -> to compile and it's compiling fine and if i just
run it so you can get the output as 20. so this is
86.48 -> one method so if this doesn't work for you there's
another way this one caused error for me in
92.48 -> initial stage i used the small s okay i used small
uh s for the string in the void main function and
100.48 -> this caused the error okay so now let me show
you and save it and run it so as you can see now
106.64 -> uh java c so as you can see i'm getting this
error so this i think this is the main reason that
112.24 -> uh many of you are getting this error because
you can't even find this okay you can't guess it
115.92 -> because we haven't used any variable or a function
it's just a string and it's causing there it's
120.96 -> cause he's saying cannot find symbol uh publish
static void main string args but everything here
126.48 -> here i have used it right i have used string
args but it's still crossing the reason is that
130.88 -> you need to use capital s over here okay so as i
have now i have used capital s and i will save it
140.56 -> i will run it again so i'm not getting any errors
and i'm doing it and am getting 20 again so this
146.8 -> is second case and another third case is just
a common stuff if you have used any function in
152 -> uh that has been declared inside the class this
is the main function the error will be caused
157.36 -> and if you have just made any syntactical
error like you haven't initialized r okay
163.04 -> you haven't insulated r and
if you just run this code now
167.36 -> you will get this error but you can find this here
you can rectify it easily because it will show you
170.88 -> the line line number and in this case it's saying
i cannot find symbol because i haven't uh declared
178.48 -> okay i haven't given int okay so if i just save it
it will work another case some people would have
184.4 -> forgot to put out system dot out okay so this will
also cause the error i will just run it for you
192.32 -> okay everything is just i cannot find
symbol okay this is also called there and
198.56 -> i think these are the stuff okay function
variables if you have just used them without
203.28 -> declaring or initializing the error will be caused
and apart from this the is the scope another thing
207.76 -> is you need to check the scope of the variable
that you are used do not uh initialize you know
213.52 -> or declare any variable inside a scope or loop uh
it may cause some scope errors that may be a cause
219.92 -> and the final cost is like the capital e okay
capital string that i have told you over here i
224.56 -> think uh this would have covered most of the cases
and i hope you would have solved your error okay
230.08 -> so that's it for this video and mine is a
programming channel I've done tutorials in
234.56 -> c c plus plus java python blender and
unity so kindly do check other videos of
238.72 -> my channel and please subscribe and
support me and thanks for watching
Source: https://www.youtube.com/watch?v=JOqtplMKqgA