NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
denisk
Joined: 31 May 2011 Posts: 2
|
Posted: Tue May 31, 2011 10:30 am Post subject: How does 'Evaluate expression' work? |
|
|
Hi, I'm very new to netbeans, I was using IntelliJ before.
How does 'Evaluate expression' (CTRL + F9) work? If I type something like
| Code: |
String s = "Hello";
s + " world!"
|
... I see an error like
"String" is not a known variable in the current context
If I change it to be
| Code: |
java.lang.String s = "Hello";
s + " world!"
|
... I see an error
No expression to evaluate
Am I doing something wrong? I need a way to evaluate arbitrary expressions in runtime, is it possible with netbeans?
Thanks |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Tue May 31, 2011 12:46 pm Post subject: Re: How does 'Evaluate expression' work? |
|
|
| denisk wrote: | Hi, I'm very new to netbeans, I was using IntelliJ before.
How does 'Evaluate expression' (CTRL + F9) work? If I type something like
| Code: |
String s = "Hello";
s + " world!"
|
... I see an error like
"String" is not a known variable in the current context
If I change it to be
| Code: |
java.lang.String s = "Hello";
s + " world!"
|
... I see an error
No expression to evaluate
Am I doing something wrong? I need a way to evaluate arbitrary expressions in runtime, is it possible with netbeans?
Thanks |
First, the second line is in error. It would need to be something like:
| Code: |
String s = "Hello";
s = s + " world!";
|
To use "Evaluate Code" you need to set a breakpoint in your code somewhere then debug the project or file and after you reach a breakpoint you can select expressions in your code and evaluate them. The selected expression will show up in an "Evaluate Code" window then when you press the button at the bottom right the expression will be evaluated in the "Variables" window. You will have needed to step through your code far enough that the expression to be evaluated has come into scope.
-- Mark |
|
| Back to top |
|
 |
denisk
Joined: 31 May 2011 Posts: 2
|
Posted: Tue May 31, 2011 1:17 pm Post subject: Re: How does 'Evaluate expression' work? |
|
|
| markwade wrote: |
To use "Evaluate Code" you need to set a breakpoint in your code somewhere then debug the project or file and after you reach a breakpoint you can select expressions in your code and evaluate them. The selected expression will show up in an "Evaluate Code" window then when you press the button at the bottom right the expression will be evaluated in the "Variables" window. You will have needed to step through your code far enough that the expression to be evaluated has come into scope.
-- Mark |
I evaluate it during a breakpoint stop. And it works with the variables identified in the code scope my breakpoint hits. I need to have an ability to evaluate arbitrary code - let's say, I have my code like this:
| Code: | String someString = "Hello";
int i = 0; //breakpoint here |
Now, when the breakpoint hits, I try to evaluate the following:
| Code: | String s = " World!";
someString + s; |
What I need to see is Hello World!, but I can't make it work without declaring additional variable |
|
| Back to top |
|
 |
markwade
Joined: 04 Dec 2010 Posts: 140
|
Posted: Wed Jun 01, 2011 12:30 am Post subject: How does 'Evaluate expression' work? |
|
|
On May 31, 2011, at 9:17 AM, denisk wrote:
| Quote: |
markwade wrote:
| Quote: |
To use "Evaluate Code" you need to set a breakpoint in your code
somewhere then debug the project or file and after you reach a
breakpoint you can select expressions in your code and evaluate
them. The selected expression will show up in an "Evaluate Code"
window then when you press the button at the bottom right the
expression will be evaluated in the "Variables" window. You will
have needed to step through your code far enough that the
expression to be evaluated has come into scope.
-- Mark
|
I evaluate it during a breakpoint stop. And it works with the
variables identified in the code scope my breakpoint hits. I need to
have an ability to evaluate arbitrary code - let's say, I have my
code like this:
Code:
String someString = "Hello";
int i = 0; //breakpoint here
Now, when the breakpoint hits, I try to evaluate the following:
Code:
String s = " World!";
myString + s;
What I need to see is Hello World!, but I can't make it work
|
That's because "myString + s;" isn't valid code, and I believe you
meant that to be "someString + s;"
You can't concatenate someString and s without assigning it to a
variable of type String.
In the "Evaluate Code" window enter:
String s = " World!";
String str = someString + s;
Press CTRL-Enter and it will, indeed, evaluate to "Hello World!"
-- Mark |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|