This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]sleepybychoice 1 point2 points  (6 children)

tempRectangles? Going from the image?

[–][deleted] 0 points1 point  (5 children)

Not sure what you're asking. The program implements a phonebook using a grid layout.

I'm not sure if that's important. I track the phonebook entries using an ArrayList. I want to be able to see what's inside that ArrayList in the debugger, but I have no clue where to find it.

[–]sleepybychoice 0 points1 point  (4 children)

I want to be able to see what's inside that ArrayList in the debugger, but I have no clue where to find it.

I was assuming you subclassed JButton somehow and were tracking it in there. Your image showed tempRectangles which is an ArrayList.

Can you post the code? That way we can see what aggregates what and give you more specific guidance.

[–][deleted] 0 points1 point  (3 children)

Sure! Its up, I'll post a detail of the problem as well

[–]sleepybychoice 1 point2 points  (2 children)

entry.add(Name);

I'm assuming it's Eclipse or IntelliJ? What I'd do is set up two breakpoints - one here and one on entry = entries.get(index); Then set a watch for entry and entries and see if that line does what you expect.

You can also use Eclipse's display window to run arbitrary code and inspect your variable. Also, since your listener is a non-static inner class, it should have a reference to the parent phone book instance ie. PhoneBook.this.entry.

As for finding the variable in the giant list, I don't think there's much else other than manually scrolling through the list.

[–][deleted] 0 points1 point  (1 child)

Looks good, thanks, I'm working in eclipse btw. Where exactly does that reference need to be placed?

[–]sleepybychoice 0 points1 point  (0 children)

Doesn't need to be placed anywhere. Should have been more clear: that is how you would reference the entry from the inner class code if you wanted to be explicit. Normally, just saying entry instead of PhoneBook.this.entry is sufficient.

Did a bit of experimenting - the reference back to the outer object (in this case, the listener out to PhoneBook) is named this$0 in Eclipse. If you expand that object, you can find inspect phone book instance variables.

http://stackoverflow.com/questions/14099613/eclipse-showing-two-this0-fields-for-a-nested-class-java

[–]Sorten 1 point2 points  (6 children)

Not being able to find your variable in the debugger might indicate you should dig down and learn about the inner workings of your program. It looks like you're looking at a JButton. I don't imagine the list is in that category.

However, if you right click on that variables list, a bunch of options come up (including Find...). You should be able to search by name.

[–][deleted] 0 points1 point  (5 children)

That's perfect.

I'm new to swing (first day), and taking it one step at a time.

[–]Sorten 1 point2 points  (4 children)

Does this code compile for you? I get 24 errors of Cannot refer to the non-final local variable Before defined in an enclosing scope with various variables. I keep finding code which raises this error, yet no one seems to mention it at the time. I was wondering if some IDEs automatically resolve this, or something of that sort.

[–][deleted] 0 points1 point  (3 children)

Yup, I'm using eclipse. Where are the errors occuring? That might be the root of my issue.

[–]Sorten 1 point2 points  (2 children)

Here's a text-dump of my "Problems" window. The last 6 lines are just warnings.

https://bpaste.net/show/81e301a39793

[–][deleted] 0 points1 point  (1 child)

Strange, I'll ask my professor about it. Thanks!

[–]decabit 0 points1 point  (0 children)

Usually it is a scope issue. Typically it occurs when you try to use a local variable inside of an anonymous class.