Local variable problem

I am making an application that takes an apartment number and number of occupants in that apartment and then displays a number of statistics. So far I haven't had much problem
except on a what is probably a very simple problem.
I have two buttons, and when "store" is clicked the info in the textboxes is input to an array.
My problem is with the next button, "quit", this is where all the info is supposed to be displayed.
All my variables that I need from "store" are local and are recognized in " the if statement in quit. Ive tried declaring them outside of the if statement, but it hasn't been working.
{code}
public void actionPerformed(ActionEvent event)
               Object source = event.getSource();
               Apartment input;
               if (source == store)
                    Integer aptNo = Integer.parseInt(input1.getText());
                    Integer occup = Integer.parseInt(input2.getText());
                    input = new Apartment(aptNo, occup);
                    if(aptNo > BUILDING_SIZE)
                         JOptionPane.showMessageDialog(null, "That apartment number doesn't exist.");
                    else if(occup > MAX_OCCUPANTS)
                         JOptionPane.showMessageDialog(null, "Too many occupants, only 20 are permitted per apartment.");
                    else
                         occupants[aptNo] = occup;
                         input1.setText("");
                         input2.setText("");
                         JOptionPane.showMessageDialog(null, input.getNumber(occupants));
               if (source == quit)
               // I need the variables aptNo and occup in here to put into my methods for output, but I don't know how to get them.     
{code}

EmmCeeVee wrote:
Thank you for all of the responses, it really helps me out.
Obviously my knowledge of local variables is hurting as I switched it around as your said and declared the aptNo and occup outside of the if's.
All I need is for the quit button to look at the array ( which has just been modified by the sotre button) and output a bunch of results.
Heres where im at:Your problem is of scope of the variables.
Here whatever variable you defined in actionPerformed they are local for that method (they are out of scope when the method is finished/called again), Upon this, the actionPerformed is called twice one for store and another time for quit. So you cant expect the value stored at store should be there still when you all quit
If you want those values available on both the actions then make them a class level variables.
Below is a sample program, might help you.
class Employee
     String empName = null;
     int empNo;
     Employee(String eName,int eNmbr)
          this.empName = eName;
          this.empNo = eNmbr;
class CheckVariableScope
        Employee empOb; // Here
     int eNo;
     String eName = null;
     public void checkScope(String action)
                //Instead of defining Employee reference variable, eNo and eName  in checkScope method, define it @ class level.
                // in your case they are Apartment input, Integer aptNo and Integer occup
                 // like above i did.
                 // If i comment the class level variable and uncomment method variable, this program also give the same error.
          //Employee empOb;
          //int eNo;             
          //String eName = null;
          if (action.equals("Store") )
                    eNo = 10;
                    eName = "Bob";
                    empOb = new Employee(eName, eNo);
                    System.out.println("The eName is : "+empOb.empName+" , empNo is : "+empOb.empNo);
               if (action.equals("quit"))
                    System.out.println(" eNO from Object is : "+empOb.empNo);
                    System.out.println(eNo); //Error: may not have been intitialized
     public static void main (String st[])
          CheckVariableScope ob = new CheckVariableScope();
          ob.checkScope("Store");
          ob.checkScope("quit");
}

Similar Messages

  • Is This a Global Versus Local Variable Problem?

    I intend to use a variable (myselector) with a text value (e.g. roses, Big Sur, Pacific Grove, night, etc.) for the sort criteria of my photography list.  Selection of a tab from a Tabbed Panel will appropriately define the variable and the selected thumbnails will display in the Content Panel.
    The variable "myselector" is defined in the head section; a function for each tab of the Tabbed Panel will redefine the variable per the selected tab.  Within the function, I am not using "var" to call the variable.  Though the variable "myselector" should be global, the changes to its value are discarded when the function closes.  This indicates that it is functioning like a local variable in the function.  After a bit of reading, I've not found the cause of the global/local discrepancy or a fix for it.
    Diagnosis History - I generated a simplified code.  Variable "myselector" is defined as "abcd"; function "myfilter" is called by onclick of the text "button" and changes "myselector" to "efgh".  At the end of the file, I used "document.write (myselector) to output the "myselector" value.  The script follows.
    The end value of "myselector" does not change.  However, when I add "document.write (myselector)" to the function, then the changed value is displayed.
    I ask someone to explain what I am doing incorrectly or, at least, guide me to a solution.  I thank you for your assistance.
    Scott
    <script type="text/javascript">
    var myselector="abcd";
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    </script>
    </head>
    <body>
    <div id=text>
    <p onclick="MM_callJS('myfilter();')">Button</p>
    <script type="text/javascript">
    function myfilter() {myselector="efgh"; }
    </script>
    <script type="text/javascript">
    document.write (myselector);
    </script>
    </div>

    Dear Ben:
    I thank youfor your patience.  This includes the script using Insert - Syntax Highlighting - Java.
    The coding needs a lot of clean up but I want it to work, first.
    Scott
    <script src="SpryAssets/xpath.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryData.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <script type="text/javascript">
    var dsphotodata = new Spry.Data.XMLDataSet("EM_photo.xml", "/gallery");
    </script>
    <script  type = "text/javascript">
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    </script>
    <script type="text/javascript">
    var dsphoto = new Spry.Data.XMLDataSet("EM_photo.xml", "/gallery/photos/photo");
    dsphoto.filter(subjectfilter);
    var myselector;
    </script>
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    This is a test of Scott's efforts to program his website.
    <br />
    <br />
    <div id="TabbedPanels1" class="TabbedPanels">
      <ul class="TabbedPanelsTabGroup">
        <li class="TabbedPanelsTab" tabindex="0" onclick="MM_callJS('{myselector=\'animal\'}; subjectfilter(); dsphoto.filter(subjectfilter); ')">Tab 1</li>
        <li class="TabbedPanelsTab" tabindex="0" onfocus="MM_callJS('myselector=\&quot;pgbeach\&quot; subjectfilter(); dsphoto.filter(subjectfilter); ')">Tab 2</li>
        <li class="TabbedPanelsTab" tabindex="0">Blank</li>
    </ul>
      <div class="TabbedPanelsContentGroup">
        <div class="TabbedPanelsContent" >Content 1
          <br />
    <br />
    <script> {document.write (myselector)} </script>
          <br />
          <div spry:region="dsphoto dsphotodata"> <img src="{dsphotodata::thumbnail/@base}{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px spry:repeat="dsphoto" onclick="dsphoto.setCurrentRow('{ds_RowID}');" /></div>
        </div>
        <div class="TabbedPanelsContent">Content 2
          <script> {document.write (myselector)} </script>
          <br />
          <div spry:region="dsphoto dsphotodata"> <img src="{dsphotodata::thumbnail/@base}{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px spry:repeat="dsphoto" onclick="dsphoto.setCurrentRow('{ds_RowID}');" /></div>
        </div>
        <div class="TabbedPanelsContent">Content 3  <script> {document.write (myselector)} </script><br />
    <div spry:region="dsphoto dsphotodata"> <img src="{dsphotodata::thumbnail/@base}{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px spry:repeat="dsphoto" onclick="dsphoto.setCurrentRow('{ds_RowID}');" /></div>
    </div>
    </div>
    </div>
    <div id="Selected_Photo" spry:detailregion = "dsphoto dsphotodata"  >
    <img src="Photo-Thumbnails/{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px /><br />
    <img src="Photo-Email/{@path}" width = {@width}px height = {@height}px />
    </div>
    <script type="text/javascript">
    var subjectfilter = function(dataSet, row, rowNumber, criteria) { if (row["@subject"].search (myselector) != -1) return row; return null; };
    <!--
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", {defaultTab:2});
    //-->
    </script>

  • Problem using local variable in event loop

    I have a state machine from which I want to monitor various controls, including "Start" and "Stop" buttons.  Not every state needs to monitor the controls.  At present, most states run timed loops.  In the first state that reads the front panel, I have an Event structure (inside a While loop) that monitors the various controls' Change Value events.  For numeric controls, I update variables (in shift registers) as needed.  The "Start" button is used to end the While loop controlling the Event structure, allowing the State to exit to the next state.
    My problem comes in subsequent states that employ this same idea.  Here, I put a Local Variable bound to the Start button and use the same code, but it frequently happens that when I enter this particular state, I cannot "turn on" the control -- I push the button, but it stays off.  Curiously, if it was On when I enter, I can turn it off, but then I'm stuck not being able to turn it on.
    I mocked up a very simply routine that illustrates this.  There are two sequences (corresponding to the two states).  Both use an Event loop with a local variable bound to my Stop button (really this is an LED control with custom colors).  I've deliberately moved the "initialization" (the declaration of the control in the block diagram) out of the Event loops -- putting it inside the first loop modifies the behavior in another strange way.
    Here's my thinking on how I would expect this to work:  The code outside Event Loop 1 should have little effect.  Assume the Stop button is initially Off.  You will "sit" in Event Loop 1 until you push the Stop button, changing its value to True; this value will be passed out of the Event case and cause the first While loop to exit.  You now enter the second sequence.  As I understand the Exit tunnel, it defaults to "False", so I'd expect to stay in the second Event loop until I turn the Stop button from On to Off, which will pass out a False, and keep me in the While for one more button push.  However, this doesn't happen -- I immediately exit, as though the "True" value of the Stop local variable is being seen and recognized by the Event loop (even though it hasn't changed, at least not in the context of this second loop).
    An even more curious thing occurs if I start this routine with the Stop button turned on.  Now I start in my Event loop waiting for a change, but this time the change will be from On to Off, which won't cause an exit from the frame.  This will be reflected by having the While loop count increment.  We should now be in the state of the example above, i.e. in an Event loop waiting for the control to be pushed again, and turned On.  However, clicking the control has no effect -- I cannot get it to "turn on".
    Where am I going astray in my thinking?  What is it about this method of doing things that violates the Labview paradigm?  As far as I can tell, what I'm doing is "legal", and I don't see the flaw in my reasoning, above (of course not -- otherwise I'd have fixed it myself!).  Note that because I'm using local variables inside Event loops (and I'm doing this because there are two places in my code where I want to do such testing), the Stop control is not latching (as required).  Is there something that gets triggered/set when one reads a latched control?  Do I need to do this "manually" using my local variable?
    I'll try to attach the simple VI that illustrates this behavior.
    Bob Schor
    Attachments:
    Simple Stop Conundrum.vi ‏14 KB

    altenbach wrote:
    Ravens Fan wrote:
    NEVER have multiple event structures that share the same events. 
    Actually, that's OK.  NOT OK is having multiple event structures in the same sequence structure.
    See also: http://forums.ni.com/ni/board/message?board.id=170&message.id=278981#M278981
    That's interesting.  I had always thought I read more messages discouraging such a thing rather than saying it was okay.  Your link lead me to another thread with this message. http://forums.ni.com/ni/board/message?board.id=170&message.id=245793#M245793.  Now that thread was mainly concentrating on registered user events which would be a different, but related animal. 
    So if you have 2 event structures they each have their own event queue?  So if you have a common event, one structure pulls it off its event queue and it does not affect the other structure's event queue?  I guess the inherent problem with this particular VI was that the second event structure locked the front panel.  Since the code never got to that 2nd event structure because the  first loop never stopped because the change was from true to false.  After reading your post and the others, I did some experimentation and turned off the Lock front panel on the 2nd structure, and that prevented the lockup of the program.
    Overall, the example VI still shows problems with the architecture and I think your answer should put the original poster on the right track.  I think as a rule I would probably never put the same event in multiple structures, I feel there are better ways to communicate the same event between different parts of a program,  but I learned something by reading your reply and about how the event structures work in the background.  Thanks.

  • Does a large amount of "local variable" within a vi cause problems?

    Hello -- I am using Labview 7.0 and have a vi where I am going to end up using about 100 "local variables" for indicators that are displaying data. Since I have a lot of true / false case structures I decided to use these local variables instead of having a mess of wiring all over the vi block diagram. It is intimidating though and I was wondering if it causes slowness in vi's?

    I actually only have about 8 indicators -- but I am in the process of creating control algorithms so I have to use many case structures if I want to keep the code all within Labview (simplicity). I am simply referencing the 8 or so indicator values many many times (100 X) I am attaching a copy of the vi like you asked but just take a look at the right hand side of the while loop on the right -- it shows an example of an algorithm I created today that has to reference the data from sensors. I would love to know what a better way to do this. Thanks!
    Attachments:
    ucb drill control daq 1_7.vi ‏666 KB

  • Reference to a local variable object returned by a method is alive?

    I have an instance method getEmployee().
    This method forms a local variable, Employee and returns it.
    public Employee getEmployee()
    Employee e = new Employee();
    e.setSNo(sNo+=);
    e.setMailBox();
    return e;
    There's another instance method in the same class that calls getEmployee() in this manner:-
    Employee newEmployee = getEmployee();
    newEmployee.printDetails();
    I want to know whether the employee returned by getEmployee() is still alive when we are doing newEmployee.printDetails().
    I am confused because in C, the lifetime of a local variable is limited only to the life time of the function. Once the function finishes, the local variable is considered garbage.
    How does it work in case of Java?

    No, It rarely has any use but can be used to unload things (from a cache for example). However I have never needed to do this. All I know is that finallizers can only be relied on to clear up memory. How or why you would do this is another question.
    The GC runs when memory is low (not any other resource). It calls finalizers when it clears up objects. Therefore the only thing you can reliably release in a finalizer is memory. Other resources can become depleted without heap being depleated so you can't use finalizers to relialy clean up non-memory resources.
    Anyway.
    some more info on escape analysis
    a compile time escape analysis
    http://www.excelsior-usa.com/pdf/StackAlloc.pdf
    This can handle some finalizers
    This does not handle finalizers (marks them all as GLOBAL_ESCAPE
    http://delivery.acm.org/10.1145/330000/320386/p1-choi.pdf?key1=320386&key2=0718563811&coll=Portal&dl=ACM&CFID=15151515&CFTOKEN=6184618
    bit more recent and about runtime optimization (finalizers not handled)
    http://ssw.jku.at/Research/Papers/Ko05/Ko05.pdf
    I don't think that not handling finalizers is too much of a problem. Most objects that will benifit from stackability are small objects anyway (especially the built in wrapper types). Most objects that have custom finalizers tend to be pretty complicated.
    matfud

  • How to assign bean value to a local variable in JSP using struts.

    Hi everybody!
    I've a problem that puzzled me on how to assign a bean value to a local variable like String in JSP using struts.
    we can have someting like this to display the value
    <bean:write name="detailService" property="status" />or
    <bean:define id="theStatus" name="detailService" property="status"/>
         This is country: <%=theStatus%>but an error occured when I tried like this:
    String currentStatus = "<bean:define id="theStatus" name="detailService" property="status"/>";
    or
    String currentStatus = "<bean:write name="detailService" property="status" />";Is there a way to do this?.....
    Any help pretty much appreciated

    Java != JSP.
    The <bean:define> and <bean:write> tags are custom tags meant to appear in the HTML section of a JSP file, as opposed to the scriptlet section. They actually get turned into java code as part of the translation process.
    The <bean:write> tag naturally just writes out what you tell it to.
    The <bean:define> tag defines a local variable, and gives it a value.
    this should do it.
    <bean:define id="theStatus" name="detailService" property="status" type="java.lang.String"/>
    <%
      String currentStatus = theStatus;
    %>With the advent of JSTL, you shouldn't really need to use scriptlet code anymore. Personally I am for 0% scriptlet code in any jsp I write.

  • RE: local variable cross-talk?

    Jeff
    A global can be considered as a variable to the entire code, where lots of
    different vi's can operate it. Locals only have any meaning within their
    own vi, or instances of their own vi.
    If anything writes to a particular global, whether in reenterent vi's or
    not, it's available everywhere in the code.
    What you were asking was about locals though. If a vi is non-renentrant
    (i.e. as they come out of the box) then the values in the locals are vi
    specific, no matter where the vi is, where it was last used, it retains the
    data from it's last operation. If it is re-entrant, then the values in the
    locals for each occurance of the vi are its own for EACH instance, i.e. just
    like different locals in different vi's, it doesn't matter where else the vi
    is used, the data held is that from the last operation of that specific
    instance.
    Simple way to demonstrate this. Make a vi that has one numeric control,
    then code in +1 and get it to write to a local variable for that control.
    Throw in an indicator to wire out the result of what is written to the local
    for the control.
    Then take this vi, put it in a for loop, then put another copy in the for
    loop as well. Wire the indicators to the side of the for loop and create
    indicator arrays for them. Get the loop to run 6 times say. Now try
    running this with the vi in the for loop non-reentrant and then reenterrant.
    One way the arrays will contain either all the odd no.s 1,3,5,7,9,11 and
    then the other array 2,4,6,8,10,12 (don't know which array will be which,
    depends which executes first in the for loop of this example). The other
    way they will both be 1,2,3,4,5,6. In the first example, the same vi has
    run 12 times, i.e. one copy of the vi which retains its info and is called
    in many places and therefore only has one set of values, and the other with
    two re-enterant copies where they have their information specific to that
    instance of them i.e. effectively they are different vi's. Both ways are
    useful, depends what you want.
    If you're looking for a use for non-reenterant vi's then consider this:-
    For instance. Supposing you get many things to try to write to a global
    array of numbers, and you have two vi's one "A" writes to the first element
    in the array and the other "B" writes to the second element. Because in LV
    you have to read a global first and then write to it to perform a change,
    these independant vi's "A" and "B" (be they re-enterant versions of the same
    vi, or different vi's), can be performing the tasks simultaneously in the
    code. I.e. "A" reads, "B" reads, "A" writes, and "B" writes over the top
    with a modified version of what it read, and "A"'s changes are lost. This
    is what's known as a "race condition" as "A" hadn't finished and "B" needed
    to know what "A" was going to write before "B" performed "A" read. Try it,
    hours of fun if you code this kind of thing in inadvertantly!
    If the same vi is used, and is not re enterant, it can only run in one
    instance at a time, hence two read / write operations cannot be performed
    together, problem solved. Unless that gives you timing issues of course,
    waiting for one to finish, to write the other......but that's another whole
    can of worms.
    cheers
    Tim Price
    This e-mail, its content and any files transmitted with it are intended
    solely for the addressee(s) and are confidential and may be legally
    privileged. Access by any other party is unauthorised without the express
    prior written permission of the sender. If you have received this e-mail in
    error you may not copy, disclose to any third party or use the contents,
    attachments or information in any way.
    -----Original Message-----
    From: [email protected]
    [mailto:[email protected]]On Behalf Of Jeffrey W Percival
    Sent: 29 November 2001 21:12
    To: [email protected]
    Subject: Re: local variable cross-talk?
    Another useful reply! What a great news group this is.
    One last thing I wanted to ask about, though, is global vs. local. I see
    you talk about globals, but in fact the variables in my subVI's were locals.
    I can easily understand the behavior I observed accompanying the use of
    global variables, But I guess the use of the word "local" stumped me.
    Should I interpret "local" in LabVIEW's sense to mean "local to all
    instances of this VI"? And global to mean "visible to all instances of this
    VI as well as other VI's"?
    -Jeff
    Tim Price wrote:
    This facility is actually very useful, for instances where you want to
    encapsulate some code so that it can only run in one place at a time,
    i.e.
    global arrays that are written to in more than one place. This method
    can
    eradicate race conditions completely for example when used like this.
    There
    are multiple other uses as well.
    However, using a vi as a module of code, to run in more than one
    instance at
    a time simultaneously, re-entrant is the way to go. Just make sure you
    debug it first!!!
    Remember though, just because a vi may be re-eneterant, doesn't mean
    that
    everything inside is; sub-vi's, Globals etc. The classic one I've seen
    is
    where people think that a re-enterant vi is talking to it's own copy of
    any
    Globals used within it, i.e. counters etc., where in actual fact of
    course,
    they are all using the same Globals.
    Worth playing with a few examples to get familiar with it.
    Tim Price
    Jeffrey W Percival, Senior Scientist and Associate Director
    Space Astronomy Laboratory, University of Wisconsin - Madison
    1150 University Ave, Madison, WI 53706 USA
    608-262-8686 (fax 608-263-0361) [email protected]
    http://www.sal.wisc.edu/~jwp

    Tim Price wrote:
    Tim, thanks very much. I'll try the experiment you suggest.
    Thanks for taking the time.
    -Jeff
    Jeffrey W Percival, Senior Scientist and Associate Director
    Space Astronomy Laboratory, University of Wisconsin - Madison
    1150 University Ave, Madison, WI 53706 USA
    608-262-8686 (fax 608-263-0361) [email protected] http://www.sal.wisc.edu/~jwp

  • Sampling local variable and synchroniz​e with DAQmx

    Hello, 
    I made a small change in the set-up I used with labview and now when I wanted to change the code I'm having a rather complicated problem.
    In my old set-up I was measuring three variables: x and y with a QPD and the power of a laser with a power detector. I was using the DAQmx and I was getting a matrix with three columns with n (sample rate) values. Now, for various reasons I had to take out the second detector. So now I want to build the same matrix as constructed before, but instead of putting the measured values of the laser power I want to put the theoretical values (they are in a local variable) as I cannot measure them. The problem is that this local variable, in general, changes during the DAQmx acquisition time and I would need to sample it at the same rate as I acquire the data from DAQ and then combine all them. How I could sample this variable and attach it to my DAQ results? DAQmx doesn't accept local variables.
    Thanks

    A local variable is not something standalone. It is always associated with a control or indicator. Hows is it updated?
    From your description, it is not clear what you are doing. Can you show us some code instead?
    (Also be more clear when using acronyms. QPD cound mean many things)
    LabVIEW Champion . Do more with less code and in less time .

  • Approval task SP09: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'

    Hi everyone,
    I just installed SP09 and i was testing the solution. And I found a problem with the approvals tasks.
    I configured a simple ROLE approval task for validate add event. And when the runtime executes the task, the dispatcher log shows a error:
    ERROR: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'
    And the notifications configured on approval task does not start either.
    The approval goes to the ToDO tab of the approver, but when approved, also the ROLE stays in "Pending" State.
    I downgraded the Runtime components to SP08 to test, and the approvals tasks works correctly.
    Has anyone passed trough this situation in SP09?
    I think there is an issue with the runtime components delivered with this initial package of SP09.
    Suggestions?

    Hi Kelvin,2016081
    The issue is caused by a program error in the Dispatcher component. A fix will be provided in Identity Management SP9 Patch 2 for the Runtime component. I expect the patch will be delivered within a week or two.
    For more info about the issue and the patch please refer to SAPNote 2016081.
    @Michael Penn - I might be able to assist if you provide the ticket number
    Cheers,
    Kristiyan
    IdM Development

  • Local variable's VariableElement not accessible through treepath

    Hi,
    I'm extending TreePathScanner visitor to localize and handle certain annotations associated with variables of any kind (field, parameters and local variables).
    To do so I overrode the visitVariable method that, as far I understand, should be able to obtain the corresponding javax.lang.model's VariableElement for any variable (whatever its kind) based on the current three path, see code bellow.
    It does work well with fields and parameter, however with local variables Trees.getElement simply returns a null. All the information is in fact in the code tree VariableTree node and I could retrieve what I needed from it but rather refrain from using com.sun. ... API if not really necessary and of course implement the processing twice.
    Perhaps the javax.lang.model.... object tree is not built for elements within a method body? or is this a bug? com.sun.source.util.Trees#getElement javadoc only says that a null is returned if the element is not "available".
    Thanks in advance.
    import javax.lang.model.element.VariableElement;
    import com.sun.source.util.TreePathScanner;
    import com.sun.source.util.Trees;
    import com.sun.source.tree.VariableTree;
    import com.sun.source.util.TreePath;
    public class MyVisitor extends TreePathScanner<Object,Trees> {
         @Override
         public Object visitVariable(VariableTree node, Trees trees) {
              TreePath path = getCurrentPath();
              VariableElement ve = (VariableElement) trees.getElement(path);
              if (ve != null) {
                            // The case for parameters and fields.
                            process(ve);
              else {  // Funnily getElement return null for local variables
                            process(node);
              return super.visitVariable(node, trees);
    }

    I had a similar problem where trees.getElement(TreePath) was returning null. In my case it had to do with the fact that symbol resolution wasn't done yet. I was trying to invoke my TreePathScanner after calling javacTask.parse() but I had to switch to after calling javacTask.analyze() otherwise trees.getElement(TreePath) always returned null. My issues was with a TreePath for a method though.

  • GetDescriptions() of an object loaded from local variable 'itemDeploymentResult'

    Hi
    We are urgrading our SAP MII ( purely Java ) systems from 7.31 Sp5 to 7.40 and we got stuck at Configuration phase. We are getting the following error during Queue validation.
    Checking of deployment queue completed with error. java.lang.NullPointerException: while trying to invoke the method com.sap.sdt.j2ee.tools.deploymentmgr.DeploymentManagerItemResultIF.getDescriptions() of an object loaded from local
    variable 'itemDeploymentResult'.
    I looked in the trace files under SUM/sdt/trc directory and found the following information.
    Jul 3, 2014 9:52:16 AM
    [Error]:
    com.sap.sdt.executor.module.ModuleExecutor [Thread[UC-3,5,main]]: A
    problem has occurred:
    com.sap.sdt.executor.exception.StepExecutionException: Problem while
    trying to execute operation on service validate-queue. The following
    problem has occurred java.lang.reflect.InvocationTargetException. CSN
    Component BC-UPG-TLS-TLJ.
    Checking of deployment queue completed with error.
    java.lang.NullPointerException: while trying to invoke the method
    com.sap.sdt.j2ee.tools.deploymentmgr.DeploymentManagerItemResultIF.getDescriptions() of an object loaded from local
    variable 'itemDeploymentResult'
    Jul 3, 2014 9:52:16 AM
    [Error]:
    com.sap.sdt.executor.module.ModuleExecutor [Thread[UC-3,5,main]]:
    Checking of deployment queue completed with error.
    Jul 3, 2014 9:52:16 AM
    [Error]:
    com.sap.sdt.executor.module.ModuleExecutor [Thread[UC-3,5,main]]:
    java.lang.NullPointerException: while trying to invoke the method
    com.sap.sdt.j2ee.tools.deploymentmgr.DeploymentManagerItemResultIF.getDescriptions() of an object loaded from local
    variable 'itemDeploymentResult'
    We have 26 GB left on our Drive and have also upgraded JSPM to 7.31 Sp8. We are using SUM10SP05_9.
    Appreciate your quick help

    Hi Amarnath,
    Where exactly you are getting this error?
    If you are getting at JMS Sender communication channel, try to stop and start the JMS communication channel and see the status, also use XPI Inspector to get the exact error log.
    for reference follow below blogs:
    Michal's PI tips: ActiveMQ - JMS - topics with SAP PI 7.3
    Michal's PI tips: XPI inspector - help OSS and yourself
    XPI Inspector

  • Labview FPGA: Why not have local variable without indicator?

    In Labview FPGA, to transfer data among parallel loops, there are three ways or maybe more, local variable, global variable and block memory. The problem with local variable is that it needs an indicator along with, not like global variable. I was thinking why Labview doesn't make a kind of local variable not need indicator? I guess local variable itself doesn't cost resource much compared to global variable, however when it comes into indicator, it will cost more. Just an idea, though. I guess there is a reason NI doesn't do that. 

    As in Labview document, global variable can be used for transfer data among VIs, which local variable isn't capable of. 
    Global variable is not always a better solution. From my experience, it is still unclear among different compilations using local vs global in terms of resources. A thread here http://forums.ni.com/t5/LabVIEW/FPGA-global-variables-vs-front-panel-items/td-p/1407282 talks about that too.
    Stephen, is there any documents say that global makes timing worse? I didn't see this noticeable.

  • Custom class loader and local class accessing local variable

    I have written my own class loader to solve a specific problem. It
    seemed to work very well, but then I started noticing strange errors in
    the log output. Here is an example. Some of the names are in Norwegian,
    but they are not important to this discussion. JavaNotis.Oppstart is the
    name of my class loader class.
    java.lang.ClassFormatError: JavaNotis/SendMeldingDialog$1 (Illegal
    variable name " val$indeks")
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:431)
    at JavaNotis.Oppstart.findClass(Oppstart.java:193)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at JavaNotis.SendMeldingDialog.init(SendMeldingDialog.java:78)
    at JavaNotis.SendMeldingDialog.<init>(SendMeldingDialog.java:54)
    at JavaNotis.Notistavle.sendMelding(Notistavle.java:542)
    at JavaNotis.Notistavle.access$900(Notistavle.java:59)
    at JavaNotis.Notistavle$27.actionPerformed(Notistavle.java:427)
    JavaNotis/SendMeldingDialog$1 is a local class in the method
    JavaNotis.SendMeldingDialog.init, and it's accessing a final local
    variable named indeks. The compiler automatically turns this into a
    variable in the inner class called val$indeks. But look at the error
    message, there is an extra space in front of the variable name.
    This error doesn't occur when I don't use my custom class loader and
    instead load the classes through the default class loader in the JVM.
    Here is my class loading code. Is there something wrong with it?
    Again some Norwegian words, but it should still be understandable I hope.
         protected Class findClass(String name) throws ClassNotFoundException
             byte[] b = loadClassData(name);
             return defineClass(name, b, 0, b.length);
         private byte[] loadClassData(String name) throws ClassNotFoundException
             ByteArrayOutputStream ut = null;
             InputStream inn = null;
             try
                 JarEntry klasse = arkiv.getJarEntry(name.replace('.', '/')
    + ".class");
                 if (klasse == null)
                    throw new ClassNotFoundException("Finner ikke klassen "
    + NOTISKLASSE);
                 inn = arkiv.getInputStream(klasse);
                 ut = new ByteArrayOutputStream(inn.available());
                 byte[] kode = new byte[4096];
                 int antall = inn.read(kode);
                 while (antall > 0)
                     ut.write(kode, 0, antall);
                     antall = inn.read(kode);
                 return ut.toByteArray();
             catch (IOException ioe)
                 throw new RuntimeException(ioe.getMessage());
             finally
                 try
                    if (inn != null)
                       inn.close();
                    if (ut != null)
                       ut.close();
                 catch (IOException ioe)
         }I hope somebody can help. :-)
    Regards,
    Knut St�re

    I'm not quite sure how Java handles local classes defined within a method, but from this example it seems as if the local class isn't loaded until it is actually needed, that is when the method is called, which seems like a good thing to me.
    The parent class is already loaded as you can see. It is the loading of the inner class that fails.
    But maybe there is something I've forgotten in my loading code? I know in the "early days" you had to do a lot more to load a class, but I think all that is taken care of by the superclass of my classloader now. All I have to do is provide the raw data of the class. Isn't it so?

  • How to use local variables to pass an image mask correctly

    I'm kind of new to labview but i'll try to explain the problem as best as i can: I'm trying to pass an image mask (basically an image) to the next iteration of a while loop using local variables. I think the image passes through the loop with the local variable but i can't read from it correctly for some reason. And I don't think the problem has to do with local variables because i've tried using shift registers and that didnt work either. I think the problem is that you need to do something to read the image correctly again, like using IMAQ copy or something (that didnt work tho), but i can't figure out what the problem is. Does anyone know what the problem is? I know this isnt a great explanation and if its too confusing i could send some snapshots of the program or something. Any help would be greatly appreciated though.
    Thanks,
    Will

    So i attached 2 snapshots of the program to give a better idea of the problem. The first snapshot shows an image getting written to the local variable SavedMask. The second snapshot, which is run on the next iteration of a while loop, shows the local variable SavedMask being read to other image operations. When i run the program, the SavedMask image is always displayed correctly on the front panel, but i can't read from it for whatever reason. I think the problem could be like you said, that im only passing an imaq reference, and i think theres a certain way to extract the image data. Do you know the correct way to extract the image data or how to pass the image data and not just a reference to the data.
    Attachments:
    first.jpg ‏81 KB
    second.jpg ‏68 KB

  • Local variable without frontpanel object

    is there a possibility to create local variables without the need of a frontpanel object? I need zhem for program ccontrolontrol but don't want to show them to the user.
    Thanks a lot,
    greetings from Germany
    Karin

    Lynn, Marc, and "tbob",
    Thanks for your replies.  I detect the common theme of keeping my variables in bundles, but I'm not experienced enough to see how to apply this to my problem of communicating between parallel event handlers.  If you have the time and patience, I have attached a very simple example of what goes on in my program.
    I have three independent systems:  a motion system that carries around a microscope and digital camera.  Each system has its own event handler.  The motion system responds to user commands to move the microscope around, the microscope handler responds to changes in focus, zoom, etc, and the camera event handler continuously snaps pictures to provide a "live" image.
    But sometimes the loops need to talk to each other. For example, autofocusing is handled by the camera event handler, because it is based on image contrast, and that is the event handler that is acquiring the images.  So that means the camera event handler should take over the microscope during auto focus.  So the microscope event handler needs to be prevented from trying to get in on the act.
    So here is what the example illustrates:  some motion has just ended "normally".  The timeout event in the motion system signals the camera system to perform an auto focus (and waits for the focus to complete before allowing any movement).  The camera system signals the microscope system to perform a "stop" event, does the auto focus, releases the microscope from the stop event, and signals back to the motion loop that auto focus is done. 
    I, of course, thought this kind of thing was very clever!  More experienced Labviewistas may have other opinions....
    -Geoff
    Attachments:
    too many indicators.vi ‏24 KB

Maybe you are looking for