Marc West

Greenhorn
+ Follow
since Dec 19, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marc West

For anyone who has the same issue: the problem was reusing Intent. I don't know why. But using a new one for each tab sorted this problem.
12 years ago
Hi,

I am trying to create a TabHost gui and I am experience a weird issue where every tab after the 1st (i tried adding more tabs) contains the content of the last tab that is added.




Below are the xml of the tabs, but essentially it is text, button, text. I am seeing text, button, button when I run the app. Would appreciate suggestions.





12 years ago
I am not sure I fully understand what you are trying to communicate.

Tim Moores wrote:While it's obvious to a human observer that "object" is never accessed, it's not to a compiler.


Tim Moores wrote:If the optimizing compiler were to eliminate all traces of MyClass from this code [...]



Looking at the above, perhaps you've misread the code and gave your answer from there? The object does get accessed, but only if it first becomes initialised. So it's not a matter of taking out the second if statement through optimisation process, it's a matter of seeing that the second conditional branch only executes when the first one does.

P.S. In this contrived example, the compiler could even see that on top of that, both if statements always execute, so the statements may as well be extracted into the method block which contains them (I know it's not illustrated but I don't think you can put if statements straight into a class block). But why it doesn't do this , is a second, seperate question unintentionally created by my choice of example.


In my naivity I wrote what I thought was a simplified but accurate example of my actual code without quickly running it. I was wrong. My example code executes without problem. Apparantly the reason it was complaining about potential unitialisation was because within my if statement I was retrieving an object through another class's getter function, but that function itself didn't guarantee I would be returned an initialised object.

I am dully impressed by how thoroughly the IDE checks potential for uninitialised object.
12 years ago
Thanks.

I simply ran into this oddity while writing code for a coursework. The above is just a barebones example. I am sure I have seen this issue before, possibly when doing C++. Curiosity got the better of me.
12 years ago
Hi,

I didn't know whether to put this in the beginner section or not. Hopefully it's the right place.

I'm curious why does below code require variable to be initialised despite code logic only ever accessing it if it has been initialised? Something to do with how Java compiles?

12 years ago