Higher level as you may already know our application actually has it but so what is this bug.
Let's actually look at this smartphone computer.
You can see that the name of this smartphone computer is actually the iPad.
Right.
So let's go back to android studio.
That makes you double click on the main activity that Java tap in order to make this area wider.
So Enceladus main activity class and inside these uncreate Smurfette you can see that when we created
this object of type smartphone computer.
So here let me tell you that here we are creating a variable of type smartphone computer right.
So this is the data type and this is the name of Aradia But after this assignment operator you can see
that you're saying new smartphone computers so here we are actually creating the actual object of type
actually that smart computer.
And we are assigning the actual object of type Smarthome computer to this valuable type smartphone computer
and the name of this variable is a smartphone computer.
So look at this object here.
Here we see that the name is iPhone 6 s.
So let me show the emulator.
It says The name is i-Pad.
Why.
It is actually outputting the value of this tablet computer.
The name of this tablet computer to this screen.
Not the name of this actually sponsored computer which is iPhone 6.
These six actually or you can see that for example the type of the keyboard is actually a virtual keyboard.
I actually forgot to put r here but you can see that here.
You can't actually see this value here.
So it is actually overlaid.
In other words it is overwriting the values of these smartphone computers.
So let me actually correct this value here.
Now I'm going to actually tell you why.
First I want to actually let you know about debugging in Android.
So in order to actually debug that application we need to use the break point.
So what is a breakpoint here.
A breakpoint is actually a little red circle that we put here inside this a left side bar here inside
is actually a gray area here.
So look at this line of code here in line number 42 and go inside the left sidebar in line number 42
and just click on it and now you can see that we have this letter actually read.
This little red circle here.
So this is actually Bridgeport.
So this means that we had to stop the flow of the application we are going to stop the execution of
the application from this line of code here.
So in this way we are going to control the flow of the application that the execution of the application.
So now at the top menu here you can see that we have this option.
It says debug app right and then click click on it.
Just click on it and it's going to show you this message it says lunching at to switch from run to debug.
The app has to restart.
Continue yes click on restart app and then choose an emulator here and then click on OK let's wait a
little bit here.
So now you can see that our application is actually into the debug mode here.
Now let's see actually what's going on here.
Let me show you the line number first the two here.
So now here we have actually you can see this de-bug area.
We have some options.
The first one is actually this button that says step over.
The second option the second button actually is step into.
Right.
So now let's for example if we actually click on this step into it's going to go inside the execution
it's going to go inside the constructor of this smart phone computer class and it's going to actually
assign these values.
For example the name the type of the screen the type of the keyboard and the operating system and all
the others other values.
So let's click on this that into in order to see what happens.
So as you can see it actually went into the smartphone computer constructed inside this Mathman computer
class and the first line that is going to be executed is this one.
So we have another.
The button insists that over.
So what does that over do.
This that over is going to actually execute this line of code in its entirety.
Right.
Sort of step into it can actually go into the declare it into the declaration of the constructor.
Or of a specific method.
But step over is going to actually execute that's a line of code in its entirety.
So let's actually click on the step over button here and let's see what happens.
So now as you can see this line of code is actually executed in its entirety.
This means that the name is passed.
The screen is passed and the keyboard is passed to the constructor of the superclass which is going
to be the computer class.
Right now it's actually highlighting this constructor again.
Let's click on this.
Step over button again.
So now it's going to execute this statement is going to actually see if the power that is passed to
is constructed is actually less than or equal to zero or not.
So the C.P.R. power that is passed is actually the 500.
If I could hover over to if you power it has Sebille power is 500.
And let me show you the emulator.
So here.
It's not going to show us the value because we are in the debugging mode.
We need to actually go into the smartphone computer.
We need to go into that main activity class actually and inside this uncreate Meffert we need to look
at this much smarter computer construct that we can see that the value of the Sibiu power that is passed
is actually 500.
Right.
So let's go back to smartphone computer so we can see this value here.
So this a solution here evaluates to false.
This means that this statement here is not going to it's not going to be executed.
And as a result this exception here is not going to be actually up front.
So let's click on this so that over again as you can see this statement is not executed because the
Sibiu power is great is actually greater than zero here and we have the ram.
So let's actually look at the value of the Ram.
Let's click on this that over.
If we actually show it here the value of these tablets actually hovered over this and I'm here and you
can see that the value of the ramp is actually not actually less than or equal to zero.
Right.
So now it's going to execute this line of code here the operating system.
So now it's just highlighting this line of code and this means that this line of code is about to be
executed.
So that's why you can see that it says the operating system now is not.
Let's step over.
In order to execute this line of code in its entirety.
So now you can see that the operating system is IOAS.
Why.
Because this line of code is now executed.
Right now it's about to execute this thing and I've got here subpoena power.
Now it is actually zero.
If we actually execute isn't enough what is going to assign 500 to the CPO power instance variable.
Let's click on this is that over.
Now we can see that the spew poverty's 500 here and now it's about to execute this line of code.
Now Ram is 0 right.
Let's click on this that over to execute this line of code here.
Let me actually click on that over.
So now we can see that the van is 400.
Right.
So this line of code is also executed and now it actually reached to this end in the curly braces is
constructed.
If I click on this step over it again it's going to go back to the main activity class and it's going
to highlight that line first to exit.
You know that will actually allow us to execute that line of code in it's in it's actually entirety.
Let's step over.
So now you can see that this line of code here is actually executed in its entirety.
And now it's about to execute this line of that tablet computer right.
So in the debugging mode you are actually in complete control of the execution of the program.
We can't completely control the flow of the program that which line of code is actually executed at
the moment.
So this line of code is executed and these values are passed.
So now it's about to execute this line of code tablet computer.
Let's actually look at these values that I is the name resinous screen virtual keyboard Iowas and these
values right.
If I click on this step over we can see that this line of code is actually executed in its entirety.
But if I actually wanted to look at the constructed of the tablet computer class and if I wanted to
see how that constructed is actually executed I needed to click on this step into right instead of step
over.
So now it's going to introduce a new design of got here.
So the problem of our application is not actually related to the performance because the problem is
actually related to the smartphone computer and the values of the tablet computer is actually overriding
the values of our smartphone computer so we need to solve that so we don't have to actually be worried
about these lines of code that are related to the performance.
So I just need to click on this that over here multiple times in order to execute these lines of code
in their entirety.
And now let's actually look at this at 8.
This is very important.
The problem is here actually so here we have an array of computer objects.
Right.
So here we actually specify the size of this area which is going to be four.
This means that these are it can only accept four objects of type computer.
Right.
Let's click on this.
Step over in order to execute this line of code in its entirety so you can see that we have an array
of objects and we haven't still initialized this out if we just specify that this area can hold for
objects.
It's going to secure this line of code now in line number 44.
We are going to assign in the index zero of this at a the value of this desktop computer right let's
click on it.
So now that this computer is assigned in the index zero of these computers at it you can see this value
here.
This computer right now it's going to include this line of quote.
Laptop computer is going to be assigned into the index.
One of these computers at.
Let's click on this.
Step over it in order to execute this line of code in its entirety so you can see the value here.
Right now it's about to execute this line of code here in line number 46.
It's going to assign the value of this smartphone computer to the index number two of these computers
at a.
Let's click on this.
Step over.
Now you can see that the smartphone computer is actually assigned into their index number to of this
computer.
And now finally we have the tablet computer which is going to be assigned to the index number three
of these computers and let's get to kind of step over.
So now these lines of code are actually executed.
So look at this for this enhanced for loop here.
The problem is actually occurring here.
So now it's going to actually look at this array and it's going on just for example.
See that it's going to iterate over all of the computer objects.
For example the desktop computer a laptop computer a smartphone computer or a tablet computer.
It's going to iterate over all these objects and it's going to actually look at these conditions and
it's good to see what each one of these conditions are met and it's going to execute those if statements.
So the first computer object that is inside of these computers is actually a supercomputer.
So remember arrays are actually on an ordered collection of values that this means that the order matters.
Right.
When we assign this computer into the index 0 this means that this computer is the first computer inside
the site.
So it is going to actually execute when it is going to actually execute these enhanced for loop.
The first computer Optik is actually there's that computer you are completely sure about that.
So let's click on this.
Step over.
So just click on.
Step over.
And now it can actually execute this statement inside this enhanced for loop.
So the first object is this computer right so it can actually look at this computer variable here.
So you know that this is going to be executed for each object inside these computers.
The first one is this computer.
So it's going to look at this object is value but that holds the first object and say this computer's
Ali is going to see that OK if this computer object is actually an instance of type desktop computer
this instance of means that this computer is actually type this computer.
So it is actually right because this computer we have this desktop computer instance right.
It is actually the desktop computer so this condition here this expression evaluates to true.
And it's going to execute the lines of code inside this statement.
So let's click on this.
Step forward in order to execute this statement let's click on it and now we can see that this condition
is met.
This is the second version is actually true.
So now it went into the curly braces of this statement.
So he's going to ask you this then I've put in a number of the free.
Let's click on this.
Step over.
Now you can see that it's going to say that it's going to output.
It's going to create this object here let's can't step over.
So it's going to get this object which is like this a computer and it is completely correct.
Calling this the computer and it's going to output this value to the screen.
This THC this computer that's set text cut into this computer that was three in is going to call the
twisting of the candidates the computer.
Let's go step over.
Now is it actually executed this line of code.
So now it's going to actually look at this condition here.
If the computer is actually an instance of laptop computer so desktop computer is not an instance of
laptop computer wide.
So let's go into the computer class here and you can see that the desktop computer is actually an instance
of computer class not actually a laptop computer.
So let's actually go back to the main activity class so here then it's his computer which is actually
a desktop computer is instance of laptop computer.
This expression he had evaluates to false.
So it's not going to actually execute this line of code here.
Right.
It's not going to execute this statement this if.
He is actually going to be skipped.
Let's step over.
So now you can see that this statement is actually skewed.
So nice going to do look at this if statement here.
If the computer which is actually this that computer is an instance of a smartphone or a computer.
So again this explosion evaluates to false.
Let's step over.
Now you can see that this statement here is actually skipped and it's going to finally look at this.
This statement here.
So it's going to say that if the computer is an instance of tablet computer.
So again this expedition evaluates to false because this computer is not actually an instance of tablet
computer.
So again if I on this step over this if statement is skipped and it's going to actually look at this
condition here it's going to look at this for loop here.
So because this for enhanced for loop is going to be executed for each object that we have inside these
computers.
Now it's actually time for this second object inside this body which is going to be laptop computer.
Right.
So now let's click on that over and it's going to actually look at this condition.
If the computer which is which is actually a laptop computer is an instance of this computer which is
not because laptop is not on this computer so it is a split and evaluates to false here.
If I click on step over you can see that this statement is actually skipped.
And now it's going to say could this if statement here if the computer is an instance of laptop computer
which is actually true.
So it's going to actually execute the lines of code that are inside of the curly braces of this if statement.
This could this step over.
You can see that this line up with it is executed here and the computer is of type Lepp laptop computer.
And if I click on to start over again you can see that now it's going to actually execute this thing
and I've got the laptop computer that said text Cudlitz laptop computer that was stream is going to
call the twisting Meffert of the laptop computer and it's going to output that value to the screen.
So let's click on step over again.
In order to actually execute the other statements you are because we need to do that here and you can
see that they get this expression of too far.
So if this statement is not going to execute it's not going to be executed.
And again we have this condition so again it is going to be false.
If I click on that or you can see that this statement is also skipped.
And now again here it's going to actually highlight the line of what is enhanced for loop.
Now it's time for the word object and say these computers right inside these computers are actually
in the Smart smartphone computer object that is in their index number two of these computers at a.
So here let's click on it.
Step over.
So again this expression here evaluates to false because the smartphone computer is not an object of
this stop computer right.
So they said if they find it's going to be actually skipped Let's get that over so you can see this
is skipped skipped and the lines of code inside the curly braces of this is if statement is not executed.
And we have this condition if the computer is actually on a smartphone computer we can see this computer
here right.
It says iPhone 6.
If the computer which is actually a smartphone computer is an instance of tablet laptop computer.
So it is not.
So this expression evaluates the FARs and it's going on.
Skip this if statement if we actually click on this step over so you can see that is if statement is
actually skipped.
And now we have this statement.
Look at this statement this is very important.
It says if the computer is actually an instance of a smartphone or a computer which is actually completely
true because we have iPhone success and it is off the smartphone computer.
So now it's going to execute the lines of code inside this if statement if I could kind of start over.
Now it's going to try to get this object the current smartphone computer here is going to cast it to
our smartphone computer object.
And now if I could start over again it's going to output the value of the twisting effect of this smartphone
to computer screen TXI the smartphone computer that takes the current smartphone can beat it or twisted
it so you can see that these values for example is iPhone 6 s here right.
So these values are going to be outputted to the screen.
The problem happens when they're actually the tablet computer is going to be actually identified.
So for now let's actually just click on the step over.
So first let me actually to go into the smartphone computer class and let me show you that this smartphone
computer class is an instance of type.
Actually it is inheriting from the computer class.
So this means that the smartphone or computer for instance is actually an instance of the computer class
also.
Right.
So let's go back to the main activity class and now it's about to execute this line of what if the computer
which is actually a smartphone computer we can see that your right is actually an instance of that tablet
computer which is not.
It's going to actually skip this statement because this if statement this expression evaluates to false.
If I can step over we can see that this statement is actually skipped.
And now it's time for the final object inside this area.
This is very important.
Pay your attention here.
This is very important.
Now we have the tablet computer in the index number free which is going to be the final objective for
the Forth object.
And so these Adye tablets computer.
So now let's step over.
So the tablet computer is not an instance of this computer right.
So this statement here is going to be skipped completely.
It's not going to execute this statement because you can see that the computer is of type i-Pad.
OK.
So you can see that this statement is going to be Skipp politically can step over.
So this statement is not executed and now it's going to actually look at this if statement.
If the computer is an instance of laptop computer so it is not because laptop it because actually tablet
is not an instance of laptop computer.
So this statement here is also going to be skipped.
Let's go actually call and click on this.
Step over here and now look at this one here.
This is actually the cause of the problem.
This is the source of the error.
It says if the computer which is actually a tablet computer computer is an instance of type smartphone
computer.
So it is actually this statement here is completely true.
This expression is completely true.
Why.
Let me show you that.
Let's go into the tablet computer class and here you can see that the tablet computer is extending from
the top smartphone computer class.
So this means that there is an ease our relationship between these two classes a tablet computer is
our smartphone computer right.
We specify that explicitly here.
Right.
So this means that an instance of type tablet computer is going to be actually of type tablet computer
and it is going to be also of smartphone computer.
So because there is an inheritance relationship here.
So let's go back to the main activity class and here if I actually click on the step over because this
actually this expression evaluates to true it's going to execute the lines of code here in say the collaborators
of this statement.
Let's click on.
Step where we can see that this expression evaluates to true and it's going to actually execute this
line of what here.
Current smartphone computer.
In other words this statement should not be executed because this is the cause of the error.
If I click on this system over again and now it's going out with this value it's going I think it is
done with here and it's going to output the value of the tablet computer to the text view of the TXI
the smartphone computed of the smartphone computer actually takes a view.
So it's going to call the twistings method of the tablet computer instead of the smart phone computer.
Right because the tablet computer is an instance of smart phone computer.
If I clicked on this start over again and now it's going to actually look at this statement so again
because tablet computer which is actually this one is an instance of top of tablet computer also here.
So it's going to look at these conditions so it this expedition here evaluates to true and it's going
to execute this statement also.
So we can see that this is low enough to here is about to be executed.
And now this one is going out but the value of the tablet computer with it takes the tablet computer.
So let's go because that over and now we can see that all these objects is executed and if you click
on that over you can see that it's actually to reach the final to the ending curly brace of this uncreate
method.
So now you can see that what is the cause of the error.
You actually we actually found out that where the error actually exists the error exists here inside
this statement computer instance of smart phone computer.
So how we can solve this problem in order to solve this problem inside this statement is to create another
statement so if inside parent says here let's actually put a bank here.
These exclamation mark because this exclamation mark is going to reverse the value of a boolean value
if it is actually true it's going to make it false.
And if it is for he's going to make it true.
Let's put a pair of practices here and let's say if bank or exclamation marks we can we can actually
call it bank or exclamation marks right into the apprentice's computer instead of actually tablets computer
then only in that case executes the lines of code here only in that case execute these two lines of
code here.
Right.
So what does this mean.
So this means that the computer is actually off the instance is smarter than a computer.
So it is OK.
It this statement.
And then it's going to go inside the curly braces of this statement.
And it's going to look at this if statement here is going to see that if the computer is not looking
at this bank here is if the computer is not an instance of tablet computer exec could these two lines
of code.
So here we are using that nested if statements here.
Right here we want to make sure that the computer is actually or is not a tablet computer and only in
that case we want to output these values the value of the smartphone computer to the screen.
If I actually don't put this statement here because tablet computer is an instance of type smartphone
computer it's going to actually secure these lines of code and it's going to overwrite the value of
the smartphone computer on the screen.
So now the problem is going to be solved.
Let me actually fall into the break point.
So in order to do the breakpoint you can't just click on it it just they can just click on it and now
the breakpoint is gone.
Let's run our application.
Let me actually click on the start and let me show you the emulator.
So here I just need to actually select one of these devices and then click on OK.
So here you can see that the problem is completely solved and we can see this iPhone 6 as retina screen
virtual keyboard power lab performance.
And we have the tablet computer which is when it's actually specific value use your iPad retina screen
virtual keyboard Sibiu power wrap screen size performance.
Right.
So now the problem is completely solved and we just needed to actually use this statement inside this
statement here.
We have actually a nested IF statement here.
And I was thinking that if the computer that is passed here is not of type tablet computer only in that
case we are going to execute these these two lines of code here.
Right.
So that's it if you want to you can actually create again a breakpoint here in line in line number actually
for 30.
Or it can actually create a regimented in line number 43 and you can control the execution of the program
and see how these lines of code are actually executed.
And I actually completely suggest you to actually do this to practice on your debugging skills because
it is a very important skill in skill in Android If you want to become a professional and the developer
you have to be proficient in the bug in your Android applications.
So that's it.
If you have any questions please post the discussion in the course and then I'll do my best to answer
all of your questions.
Thank you very much for watching and I'll see you in the next tutorial.