Static local variable?

Hi,
Why a local variable can not be declared as static? What is the logic behind this static keyword?
thks.

Hi,
Why a local variable can not be declared as static?
What is the logic behind this static keyword?
thks.In C, a static local variable is used to maintain state between function calls. In Java, the way to maintain state is with a member variable. We have no need of static local variables.
The meaning of the static keyword is "associated with the class as a whole, rather than with any one instance."

Similar Messages

  • Equivalent of "C static local" variable?

    Hi!
    I am trying to write a sub-VI that has multiple call modes
    (init, do1, do2) and needs to remember some variables set in the
    'init' call. When I try the straightforward way of just placing
    indicators as temporary variables on the front panel, these seem
    to reset to the default values every time the VI is called.
    Is there any equivalent of the static local variables used in C?
    Or do I have to use GLOBAL variables?
    Rudolf

    There are several solutions:
    1. Global variables.
    You can create global variable for each of your temorary variables. This is easy to do but I think it's not very convivient way to pass data.
    2. One Global variable.
    If you have many temporary variables you can organize them into cluster and create only one global variable for this cluster. Then you have to read and write this cluster in your SubVI every time you change any of your temporary variables.
    3. Pass data to/from your SubVI.
    If you look at the most of LV VIs you will see that very often they have some practically identical input and output nodes. For example "AI Start.vi" has " task ID in' and "task ID out" nodes. You can make the same thing. Let your subVI reads and writes some cluster of your tempora
    ry variables through its input and output nodes. So you will have the access to this variables in any place ofyour main VI. Also you can change and create your own clusters of temp variables in your main VI. And also you will get the ability to pass these data to your subVI using local variables or shift registers or sequence locals in your main VI
    I think that the last way is the most useful.
    Good luck.
    Oleg Chutko.

  • Final attributes and local variables - performance ??

    Hi all,
    I and a colleague have done some performance testing regarding the use of final attributes and final local variables, e.g.
    with final:
    public class MyClass {
      private final int i;
      public final void myMethod() {
        final int j = 5;
        // do something with i and j
    }vs. non-final:
    public class MyClass {
      private int i;
      public final void myMethod() {
        int j = 5;
        // do something with i and j
    }I couldn't find any speed differences in a small test program, but my colleague did so in his application. Who is right ??
    Still, I will have do some formal testing next week and I will post the results.
    I'd prefer the version using final anyway because I find it better readable, but the issue I am having is whether I'll spend 2-3 days going through the program making everything final or not.

    I made some tests with final arguments to a method: I could not find any difference between final and non-final arguments. code is posted below
    import java.io.*;
    import java.net.*;
    import java.rmi.*;
    import java.util.*;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import junit.framework.*;
    import junit.extensions.*;
    public final class FinalVariablesTest extends TestCase /* from junit */ {
         * Constructors
        public FinalVariablesTest(String name) {
            super(name);
         * helper methods/classes
        protected void setUp() throws Exception {
            super.setUp();
        protected void tearDown() throws Exception {
            super.tearDown();
         * Test Suite
        public static void main(String[] args) {
         junit.textui.TestRunner.run(suite());
        public static Test suite() {
            return new TestSuite(FinalVariablesTest.class);
         * Test Cases
        /** tests the effect of passing an (final or non-final) int parameter
         to a method which uses the variable in a for loop.
         <p>
         Linux System:
         cat /proc/cpuinfo
         processor       : 0
         vendor_id       : GenuineIntel
         cpu family      : 6
         model           : 8
         model name      : Pentium III (Coppermine)
         stepping        : 1
         cpu MHz         : 501.146
         cache size      : 256 KB
         fdiv_bug        : no
         hlt_bug         : no
         sep_bug         : no
         f00f_bug        : no
         coma_bug        : no
         fpu             : yes
         fpu_exception   : yes
         cpuid level     : 2
         wp              : yes
         flags           : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr xmm
         bogomips        : 999.42
         </pre>
         <p>
         Results:
         <pre>
         java version "1.4.0"
         Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
         Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
         final     non-final
         498     500
         491     494
         491     493
         491     494
         534     494
         492     494
         491     494
         492     493
         491     494
         495     494
         4966     4944 (Totals)
         </pre>
        public final void testIntParametersToForLoop() {
         final int RUNS = 10;
         final int INNER = 1000000;
         final int OUTER = 10;
         System.out.println("-----------------------");
         System.out.println("testIntParametersToForLoop");
         for(int i=0; i<RUNS; i++) {
             outerFinalIntParametersToForLoop(INNER, OUTER);
             outerNonFinalIntParametersToForLoop(INNER, OUTER);
        private final void outerFinalIntParametersToForLoop(final int INNER,
                                       final int OUTER) {
         // with final var in for loop
         long start0 = System.currentTimeMillis();
         for(int i=0; i<OUTER; i++) {
             innerFinalIntParametersToForLoop(INNER * i);
         long end0 = System.currentTimeMillis();
         System.out.println("      final:       " +
                      ( end0 - start0 ) + " milliseconds");
        private final void outerNonFinalIntParametersToForLoop(final int INNER,
                                          final int OUTER) {
         // with non-final var in for loop
         long start1 = System.currentTimeMillis();
         for(int i=0; i<OUTER; i++) {
             innerNonFinalIntParametersToForLoop(INNER * i);
         long end1 = System.currentTimeMillis();
         System.out.println("  non final: " +
                      ( end1 - start1 ) + "       milliseconds");
        private final void innerFinalIntParametersToForLoop(final int INNER) {
         for(int i=0; i<INNER; i++) {
             int testVar = i * INNER;
        private final void innerNonFinalIntParametersToForLoop(int loops) {
         for(int i=0; i<loops; i++) {
             int testVar = i * loops;

  • 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");
    }

  • Local variable needs to be declared final

    This is the error code I am getting:
    C:\javacode\Notepad>javac FinalProgram.java
    FinalProgram.java:60: local variable textfield1 is accessed from within inner class; needs to be declared final
    System.out.println("It is detected " + pressed +
    textfield1);
    ^
    1 error
    Here is my code:
    comments relevant to this topic are //ALL IN CAPS
    import java.awt.*; //declare packages needed
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.JMenuBar;
    public class FinalProgram extends JFrame
        implements ActionListener {
    static JFrame frame;
      public void actionPerformed (ActionEvent e) {
          String answer = (e.getActionCommand());
             if (answer == "Get Data") {
              JInternalFrame iFrame = new JInternalFrame("Get Data . ", false, true, false, false);
              iFrame.setLayout(new GridLayout(8,2));
              JLabel label1 = new JLabel("First Name");
              JLabel label2 = new JLabel("Last Name");
              JLabel label3 = new JLabel("Street");
              JLabel label4 = new JLabel("City");
              JLabel label5 = new JLabel("State");
              JLabel label6 = new JLabel("Zip");
              JLabel label7 = new JLabel("Phone");
              JLabel label8 = new JLabel("Click Button to Submit Form -->");
              JTextField textfield1 = new JTextField(10);
              JTextField textfield2 = new JTextField(10);
              JTextField textfield3 = new JTextField(10);
              JTextField textfield4 = new JTextField(10);
              JTextField textfield5 = new JTextField(10);
              JTextField textfield6 = new JTextField(10);
              JTextField textfield7 = new JTextField(10);
              JButton button1 = new JButton("Submit Data");
              //textfield1.addActionListener(this);
              textfield1.addActionListener(this);
              textfield2.addActionListener(this);
              textfield3.addActionListener(this);
              textfield4.addActionListener(this);
              textfield5.addActionListener(this);
              textfield6.addActionListener(this);
              textfield7.addActionListener(this);
              button1.addActionListener(new ActionListener() { //start button1.addActionListener
              public void actionPerformed(ActionEvent a) { //start button1 actionPerformed
                        String pressed = ((JButton) a.getSource()).getText();
                        System.out.println("button press is detected " + pressed + textfield1);  //THIS SYSTEM OUT PRINT IS A TEST, IT WORKS WHEN I DON'T HAVE THE "+ textfield1" PART, IT GIVES ME THE ERROR MESSAGE POSTED ABOVE ABOUT DECLARING IT FINAL.
    I'M A BEGINNER, MY GOAL HERE, IN EASY ENGLISH, IS TO GRAB THE DATA FROM EACH TEXTFIELD AND STORE THEM IN VARIABLES, OR MORE IDEALLY IN AN ARRAY SO THAT THE REST OF MY CODE BELOW CAN WRITE THEM TO FILE, I'VE BEEN TRYING THE PAST FEW DAYS ON THIS EXPERIMENTING AND ANY SUGGESTIONS WOULD BE APPRECIATED
              try {
                   String directoryName = "c:\\javacode\\Notepad";
                   String fileName = "program.txt";
                   File output = new File(directoryName,fileName);
                   output.createNewFile();
              if (! output.isFile()) {
                   System.out.println("File creation of" + output.getPath() + "failed");
            return;
              BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));
              String[] text = {"This is the text that will be written. \r", //we pass an array, which holds the text to append to the file
                    "The text will be written to the file \r",
                    "in append mode. If the file does not \r",
                    "exist it will be created.\r"};  //WHAT YOU SEE HERE IS JUST A TEST, IN PLACE, I WOULD LIKE TO HAVE THE INFORMATION FOR MY TEXTFIELDS SO THAT I CAN PASS THEM THROUGH A FOR LOOP AS BELOW AND WRITE DATA FOR EACH OF THE TEXTFIELDS TO MY EXTERNAL TEXT FILE
                    for(int i = 0; i < text.length; i++) { //using the length of the text message we use out.Write() to write out the data.  Notice that all of the code is placed into a try-catch block so we can check for any IOExceptions that occur
           out.write(text[i] + "\n");
              //Here I create the code to grab the actions(grab the text) from the textFields and store them into variables OR into an array
              //after I have created my container to hold the information for my various textFields, then I want to create a for loop to go through each textField and write that information to a text file, separating each textField on its own line
         out.close();
         catch(IOException d) {
         System.out.println("Error writing to file " + d);
                   }  //end button1.addActionListener
              }  //end button1 actionPerformed
              );     //end actionListener statement     
              //textfield1.setSize(10, 10);
              iFrame.add(label1);
              iFrame.add(textfield1);
              iFrame.add(label2);
              iFrame.add(textfield2);
              iFrame.add(label3);
              iFrame.add(textfield3);
              iFrame.add(label4);
              iFrame.add(textfield4);
              iFrame.add(label5);
              iFrame.add(textfield5);
              iFrame.add(label6);
              iFrame.add(textfield6);
              iFrame.add(label7);
              iFrame.add(textfield7);
              iFrame.add(label8);
              iFrame.add(button1);
              iFrame.setSize(200, 500);
              iFrame.setVisible(true);
              add(iFrame);
              if (answer == "Display Data") {
              JInternalFrame iFrame = new JInternalFrame("Display Data . ", false, true, false, false);
              JTextArea text = new JTextArea();
              JScrollPane scroller = new JScrollPane();
              scroller.getViewport().add(text);
              iFrame.getContentPane().add(scroller);
              iFrame.setSize(200, 150);
              iFrame.setVisible(true);
              add(iFrame);
      public FinalProgram() {
        super ("Menu Example");
        JMenuBar jmb = new JMenuBar();
        JMenu file = new JMenu("Functions");
        JMenuItem item;
        file.add(item = new JMenuItem("Get Data"));
        item.addActionListener (this);
        file.add(item = new JMenuItem("Display Data"));
        item.addActionListener (this);
        jmb.add(file);
        addWindowListener(new ExitListener());    
         setJMenuBar (jmb);
        public static void main(String[] args) {
            FinalProgram window = new FinalProgram();
            window.setTitle("Final Program");
            window.setSize(600, 600);
            window.setVisible(true);
    }

    hi,
    Updated Code,
    import java.awt.*; //declare packages needed
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.JMenuBar;
    public class FinalProgram extends JFrame
        implements ActionListener {
    static JFrame frame;
              JLabel label1 = new JLabel("First Name");
              JLabel label2 = new JLabel("Last Name");
              JLabel label3 = new JLabel("Street");
              JLabel label4 = new JLabel("City");
              JLabel label5 = new JLabel("State");
              JLabel label6 = new JLabel("Zip");
              JLabel label7 = new JLabel("Phone");
              JLabel label8 = new JLabel("Click Button to Submit Form -->");
              JTextField textfield1 = new JTextField(10);
              JTextField textfield2 = new JTextField(10);
              JTextField textfield3 = new JTextField(10);
              JTextField textfield4 = new JTextField(10);
              JTextField textfield5 = new JTextField(10);
              JTextField textfield6 = new JTextField(10);
              JTextField textfield7 = new JTextField(10);
              JButton button1 = new JButton("Submit Data");
      public void actionPerformed (ActionEvent e) {
          String answer = (e.getActionCommand());
             if (answer == "Get Data") {
              JInternalFrame iFrame = new JInternalFrame("Get Data . ", false, true, false, false);
              iFrame.setLayout(new GridLayout(8,2));
              //textfield1.addActionListener(this);
              textfield1.addActionListener(this);
              textfield2.addActionListener(this);
              textfield3.addActionListener(this);
              textfield4.addActionListener(this);
              textfield5.addActionListener(this);
              textfield6.addActionListener(this);
              textfield7.addActionListener(this);
              button1.addActionListener(new ActionListener() { //start button1.addActionListener
              public void actionPerformed(ActionEvent a) { //start button1 actionPerformed
                        String pressed = ((JButton) a.getSource()).getText();
                        System.out.println("button press is detected " + pressed + textfield1.getText()); 
              try {
                   String directoryName = "c:\\javacode\\Notepad";
                   String fileName = "program.txt";
                   File output = new File(directoryName,fileName);
                   output.createNewFile();
              if (! output.isFile()) {
                   System.out.println("File creation of" + output.getPath() + "failed");
            return;
              BufferedWriter out = new BufferedWriter(new FileWriter(output.getPath(), true));
              String[] text = {"This is the text that will be written. \r", //we pass an array, which holds the text to append to the file
                    "The text will be written to the file \r",
                    "in append mode. If the file does not \r",
                    "exist it will be created.\r"};  //WHAT YOU SEE HERE IS JUST A TEST, IN PLACE, I WOULD LIKE TO HAVE THE INFORMATION FOR MY TEXTFIELDS SO THAT I CAN PASS THEM THROUGH A FOR LOOP AS BELOW AND WRITE DATA FOR EACH OF THE TEXTFIELDS TO MY EXTERNAL TEXT FILE
                    for(int i = 0; i < text.length; i++) { //using the length of the text message we use out.Write() to write out the data.  Notice that all of the code is placed into a try-catch block so we can check for any IOExceptions that occur
           out.write(text[i] + "\n");
              //Here I create the code to grab the actions(grab the text) from the textFields and store them into variables OR into an array
              //after I have created my container to hold the information for my various textFields, then I want to create a for loop to go through each textField and write that information to a text file, separating each textField on its own line
         out.close();
         catch(IOException d) {
         System.out.println("Error writing to file " + d);
                   }  //end button1.addActionListener
              }  //end button1 actionPerformed
              );     //end actionListener statement     
              //textfield1.setSize(10, 10);
              iFrame.add(label1);
              iFrame.add(textfield1);
              iFrame.add(label2);
              iFrame.add(textfield2);
              iFrame.add(label3);
              iFrame.add(textfield3);
              iFrame.add(label4);
              iFrame.add(textfield4);
              iFrame.add(label5);
              iFrame.add(textfield5);
              iFrame.add(label6);
              iFrame.add(textfield6);
              iFrame.add(label7);
              iFrame.add(textfield7);
              iFrame.add(label8);
              iFrame.add(button1);
              iFrame.setSize(200, 500);
              iFrame.setVisible(true);
              add(iFrame);
              if (answer == "Display Data") {
              JInternalFrame iFrame = new JInternalFrame("Display Data . ", false, true, false, false);
              JTextArea text = new JTextArea();
              JScrollPane scroller = new JScrollPane();
              scroller.getViewport().add(text);
              iFrame.getContentPane().add(scroller);
              iFrame.setSize(200, 150);
              iFrame.setVisible(true);
              add(iFrame);
      public FinalProgram() {
        super ("Menu Example");
        JMenuBar jmb = new JMenuBar();
        JMenu file = new JMenu("Functions");
        JMenuItem item;
        file.add(item = new JMenuItem("Get Data"));
        item.addActionListener (this);
        file.add(item = new JMenuItem("Display Data"));
        item.addActionListener (this);
        jmb.add(file);
        addWindowListener(new ExitListener());    
         setJMenuBar (jmb);
        public static void main(String[] args) {
            FinalProgram window = new FinalProgram();
            window.setTitle("Final Program");
            window.setSize(600, 600);
            window.setVisible(true);
    class ExitListener extends WindowAdapter {
      public void windowClosing(WindowEvent event) {
        System.exit(0);
    }

  • Catch-22: need to assign a local variable within an anonymous class

    static boolean showMessage(Window parent, String button0, String button1)
        throws HeadlessException {
              final Window w = new Window(parent);
              Panel p = new Panel(new GridBagLayout());
              final Button b[] = new Button[]{new Button(button0), (button1 != null) ? new Button(button1) : (Button)null};
              boolean rval[]; //tristate: null, true, false
              w.setSize(100, 50);
              w.setVisible(true);
              //add b[0
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridx = 0;
              gbc.gridy = 3;
              p.add(b[0], gbc);
              //add b[1]
              if (button1 != null) {
                   gbc.fill = GridBagConstraints.HORIZONTAL;
                   gbc.gridx = 1;
                   gbc.gridy = 3;
                   p.add(b[1], gbc);
              w.add(p);
              w.pack();
            w.setVisible(true);
            //actionListener for button 0
              b[0].addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             if (e.getSource() == b[0]) {
                                  w.setVisible(false);
                                  rval = new boolean[1];
                                  rval[0] = true;
              //actionListener for button 1
              if (button1 != null) {
                   b[1].addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent e) {
                                  if (e.getSource() == b[1]) {
                                       w.setVisible(false);
                                       rval = new boolean[1];
                                       rval[0] = false;
            while (true) {
                 try {
                      if (rval[0] == true || rval[0] == false) //should trigger NullPointerException
                           return rval[0];
                 } catch (NullPointerException e) { }
         }catch-22 is at
    rval = new boolean[1];
    rval = false;javac whines: "local variable rval is accessed from within inner class; needs to be declared final"
    How do I assign to rval if it's declared final?
    Or at the very least, how do I get rid of this error (by all means, hack fixes are okay; this is not C/C++, I don't have to use sanity checks)?
    I'm trying to make a messagebox in java without using JOptionPane and I'm trying to encapsulate it in one method.
    And I'm far too lazy to make a JNI wrapper for GTK.

    dcminter wrote:
    How do I assign to rval if it's declared final?You don't and you can't. You're not allowed to assign to the local variable of the outer class for extremely good reasons, so forget about trying.
    Or at the very least, how do I get rid of this errorIf you don't want the side effect, then just use an inner class variable or a local variable.
    If you want the side effect then use a named class and provide it with a getter and setter.
    Finally, in this specific case because you're using an array object reference, you could probably just initialise the array object in the outer class. I.e.
    // Outer class
    final boolean[] rval = new boolean[1];
    // Anonymous Inner class
    rval[0] = true; // No need to intialize the array.
    I declared it as an array so that it would be a tristate boolean (null, true, false) such that accessing it before initialization from the actionPerformed would trigger a NullPointerException.
    Flowchart:
    is button pressed? <-> no
    |
    V
    Yes->set and return
    Is there a way to accomplish this without creating a tribool class?

  • Thread local variable causes JVM crash through JNI

    Hi All,
    My team developed a JDBC driver which uses some native C codes. (Compiler: cl.exe, O/S: Windows XP)
    I found that JVM crashes at specific point. So I used debugger(Visual Studio 2005) to find the position.
    ==================File1.c=====================
    JNIEXPORT jbyteArray JNICALL
    Java_com_lone_wolf_MyClass_myFunc(
    JNIEnv *env, jclass cls,
    jint msgtype, jbyteArray recvarr)
    jbyteArray outarr;
    int x = 3;
    outarr = my_initializer (int &x);
    return outarr;
    ==================File2.c=====================
    __declspec(thread) int thread_id;
    static jbyteArray my_initializer (int *a)
    thread_id = *a; // HERE JVM CRASHES
    When my_initializer() tries to put *a into thread_id, JVM crashed with the following error message.
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x4931c6bf, pid=3560, tid=848
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_01-b08 mixed mode)
    # Problematic frame:
    # C [hello.dll+0xc6bf]
    --------------- T H R E A D ---------------
    Current thread (0x00037168): JavaThread "main" [_thread_in_native, id=848]
    Stack: [0x00040000,0x00080000), sp=0x0007f494, free space=253k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [hello.dll+0xc6bf]
    C [hello.dll+0xbebb]
    C [hello.dll+0x3c30]
    C [hello.dll+0x18e6]
    C [hello.dll+0x11b8]
    j com.lone.wolf.MyClass.myFunc(I[B)[B+0
    v ~StubRoutines::call_stub
    V [jvm.dll+0x8176e]
    V [jvm.dll+0xd481d]
    V [jvm.dll+0x8163f]
    V [jvm.dll+0x885cd]
    C [java.exe+0x14c0]
    C [java.exe+0x64cd]
    C [kernel32.dll+0x16ff7]
    VM Arguments:
    jvm_args: -Xms128m -Xmx1024m
    java_command: sampler.Sampler
    --------------- S Y S T E M ---------------
    OS: Windows XP Build 2600 Service Pack 2
    CPU:total 4 family 6, cmov, cx8, fxsr, mmx, sse, sse2, ht
    Memory: 4k page, physical 2062180k(1378880k free), swap 4003992k(3252828k free)
    vm_info: Java HotSpot(TM) Client VM (1.5.0_01-b08) for windows-x86, built on Dec 6 2004 19:51:00 by "java_re" with MS VC++ 6.0
    Any idea how to solve this issue will be greatly appreciated.
    Thank you.

    This deffinition ( __declspec(thread) ) of the thread local veriable does not works in some cases (see articles in MSDN how to define thread local variables in C++ code). JVM loads your native module (DLL) with LoadLibrary function. This is one of the cases when __declspec(thread) is wrong in C++ code.

  • Local variable initialization

    How local variables initialized in CVI?
    Are there any default values for local variables?

    Following function is generated by IVI Scope driver generator.
    If the vertical coupling is GND, variable simOffset is used in an equation without being initialised.
    Is this a bug and it must be initialized?
    * Function: TTTTT_FetchWaveformSafe
    * Purpose: This function returns the data from the instrument. You must
    * range-check all parameters and lock the session before calling
    * this function.
    static ViStatus TTTTT_FetchWaveformSafe (ViSession vi, ViConstString channelName,
    ViInt32 waveformSize, ViReal64 waveform[],
    ViInt32 *actualPoints, ViReal64 *initialX,
    ViReal64 *xIncrement)
    ViStatus error = VI_SUCCESS;
    if (!Ivi_Simulating (vi)) /* call only when locked */
    ViSession io = Ivi_IOSession (vi); /* call only when locked */
    ViChar rdBuf[5000];
    checkErr( Ivi_SetNeedToCheckStatus (vi, VI_TRUE));
    /*=CHANGE: ==============================================================*
    Do actual instrument I/O only if not simulating. Example:
    viCheckErr( viPrintf (io, ":WAV %sATA?", channelName));
    viCheckErr( viRead (io, rdBuf, 5000, VI_NULL));
    Change the number of elements in the rdBuf array as appropriate for your
    instrument's maximum record size.
    Convert the rdBuf raw data here to a double precision floating point
    numbers and store the data in the waveform array.
    Read the waveform preamble from the instrument to get the initial X
    and X increment values.
    If the oscilloscope did not resolve all points in the waveform record,
    replace such points with the IVI_VAL_NAN value. The function should
    return the TTTTT__WARN_INVALID_WFM_ELEMENT
    warning in this case.
    *============================================================END=CHANGE=*/
    else
    ViInt32 x;
    ViReal64 yRange, simOffset;
    ViInt32 triggerSlope, vCoup;
    ViReal64 k, level, theta, offset;
    checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL,
    TTTTT_ATTR_HORZ_RECORD_LENGTH,
    0, actualPoints));
    checkErr( Ivi_GetAttributeViReal64 (vi, channelName,
    TTTTT_ATTR_VERTICAL_RANGE,
    0, &yRange));
    checkErr( Ivi_GetAttributeViInt32 (vi, channelName,
    TTTTT_ATTR_VERTICAL_COUPLING,
    0, &vCoup));
    checkErr( Ivi_GetAttributeViReal64 (vi, channelName,
    TTTTT_ATTR_VERTICAL_OFFSET,
    0, &offset));
    checkErr( Ivi_GetAttributeViInt32 (vi, VI_NULL,
    TTTTT_ATTR_TRIGGER_SLOPE,
    0, &triggerSlope));
    checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
    TTTTT_ATTR_TRIGGER_LEVEL,
    0, &level));
    checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
    TTTTT_ATTR_HORZ_TIME_PER_RECORD,
    0, xIncrement));
    checkErr( Ivi_GetAttributeViReal64 (vi, VI_NULL,
    TTTTT_ATTR_ACQUISITION_START_TIME,
    0, initialX));
    theta = asin (2*level/yRange);
    if (triggerSlope == TTTTT_VAL_POSITIVE)
    k = 1.0;
    else
    k = -1.0;
    if( *actualPoints>waveformSize )
    *actualPoints = waveformSize; /* Checking number of points to write */
    *xIncrement /= *actualPoints;
    if (vCoup == TTTTT_VAL_DC)
    simOffset = 0.5;
    if (vCoup == TTTTT_VAL_GND)
    k = 0.0;
    for (x = 0; x < *actualPoints; x++)
    ViReal64 y = simOffset + k * 2.5 * sin (*xIncrement * 12560 * x + k * theta) + // ~2 periods of 1kHz sinewave
    (!(x%20)) * (16384 - rand())/150000.0;
    waveform[x] = (offset + yRange/2) > y ? ((offset - yRange/2) < y ? y : (offset - yRange/2)) : (offset + yRange/2);
    Error:
    return error;

  • While local variable initialized inside try block compiler throws error???

    Check out this code where two local variables(one String and the other int type) is declared at the beginning of the method and initialized inside try block. now when i compile this app, it gives an error sayin' that Variables not been initialized. Can anyone tell me why compiler is throwin' an error message?
    Many thanks.
    import java.io.*;
    public class Test{
    public static void main(String[] args){
    String aa;
    int c;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("EnterAnything:");
    try{
    aa = in.readLine();
    c = 1;
    catch(IOException e){
    System.out.println(e.getMessage());
    System.out.println(aa);
    System.out.println(c);
    }

    jfbriere,
    Thanks to u all.
    that every reference to the variable is necessarily preceded
    by execution of an assignment
    to the variable.But I've initialized the variable c and aa inside try block before referencing it as a parameter of println()?
    Can u clarify this?
    --DM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Local Variable annotation

    hi
    I've written some lines of code:
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.LOCAL_VARIABLE)
    public @interface Testable {
         String test() default "haha";
    public class TestAnnotation {
         public static void main(String[] args) {
              @Testable
              String str = new String();
              printAnnotation(str);
         static void printAnnotation(Object str) {
    in printAnnotation i want to see if the passed variable is annotated with @Testable or not.
    But now I dont know how to complete printAnnotation()
    could anyone help me ?
    tanx

    There was no straightforward way to represent local variables and their
    annotations, so no such representation was defined.To me, that's a completely bogus argument. Sun easily could have defined another attribute, similar to the LocalVariableTable, that contains information about a local variable and its annotation.
    I was really excited about all the possibilities of Java annotations... until I noticed this grave oversight.

  • "abstract" modifier for local variable

    Again, I am studying the SCJP 6 and have a question on avaiable access modifier in local variable (within the method).
    The book said the ONLY access modifier allowed for variable within the method is "final", and for method-local inner class is "abstract" or "final". But for fun I tried to write this code:
    public class NewClass1 {
        public static void method1(){
            abstract String a = "hello";
            System.out.println(a);
        public static void main(String[] args){
            method1();
    }can it compiles and runs fine. Also when I change to this below, I can even "change" the value of a refer to, the behaviour seems ignoring the final access modifier:
    public class NewClass1 {
        public static void method1(){
            abstract final String a = "hello";
            a = "free to change the value";
            System.out.println(a);
        public static void main(String[] args){
            method1();
    }So my question are:
    1. Can local variable use the access modifier "abstract"?
    2. If yes, what is the meaning of it?
    Edited by: roamer on 2009?11?16? ??9:55

    it compiles and runs fine
    As I said in the post they were compiled and ran without any error or exception.
    Yes, when "compiling", I got the compilation error which is same to your message^^
    let's see if I got the same error again in my home.I've seen your future, and it's got a compiler error in it.

  • Unable to see local variable values when debugging java

    Hi,
    I am using JDev 10.1.2 with java version 1.4.2_04.
    I have been using JDev to debug my java programs. But suddenly from this morning I am unable to see local variable values. I am able to see class and instance variables. This has happened to me before and I had restarted my machine couple of time, to get this sorted. But this time, nothing helps. Going thru the forum I found out that Include Debug information (Project Properties -> Compiler Option) need to be turned ON. It is already turned ON for me.
    I would greatly appreciate if you could let me know how to crack this problem.
    Thanks in advance.

    No. The local variables 'used' to show up during debugging. But erratically it doesn't show up local variable values. I had to restart my machine couple of times whenever this happens, inorder to see the local variable values. But this time even restarting doesn't help.
    Is there any preference setup that need to be turned on/off to see local variables?
    Also I can't step into a static method now. Any idea why this happens?

  • Local Variable Probelm

    public class Q275d {
        static int a;
        int b;
        public Q275d() {
            int c;
            c = a;
            a++;
            b += c;
        public static void main(String[] args) {
            new Q275d();
    }Since int c is not initialized . It shud give a compiilation error. But it does not. What is the reason behind this. I thought it was a local variable
    Regards,
    http://www.beginner-java-tutorial.com
    Hemanth

    Since int c is not initialized . It shud give a
    compiilation error. But it does not. What is the
    reason behind this. I thought it was a local
    variableYou're initializing it when you say c = a;Perhaps you thought you had to initialize it on the line where you declare it? As in int c = a;You don't need to do that. You just have to initialize it before you try to read its value. Of course, if you know what value you're going to give it at the point of declaration, it's generally considered good practice to do so.

  • Error_1_Implicitly-typed local variables must be initialized_

    Hi,
    I am to programming and done the self help books.
    I receive an error when running an application - Implicitly-typed local variables must be initialized
    Code below.
    I have also tried to declare Age as int and get the following error
    Error 1 Cannot implicitly convert type 'string' to 'int'
    static void Main(string[] arg)
    string FirstName;
    string Surname;
    var Age;
    Console.WriteLine("What is your first name? ");
    FirstName = Console.ReadLine();
    Console.WriteLine("What is your surname? ");
    Surname = Console.ReadLine();
    Console.WriteLine("Hello "+ FirstName + " " + Surname );
    Console.WriteLine("What is your date of birth?");
    Age = Console.ReadLine();
    if(Age <= 35)
    Console.WriteLine("No Late Joiner Penalties apply.");

    Hi,
    As Ezra94 said, your are in the wrong forum.
    Because it's C#, I advise you to post on this forum : https://social.msdn.microsoft.com/Forums/en-US/home?forum=csharpgeneral.
    Now I'm C# developper so you're problem is on the line
    var Age;
    because you couldn't use "var" without initializing your variable because the compiler can't determine the real type. So to correct your program change the line by :
    int Age;
    But for the next time, choose the good forum, thanks,
    Regards,
    Yan Grenier
    Merci de bien vouloir "Marquer comme réponse", les réponses qui ont répondues à votre question, et de noter les réponses que vous avez trouvé utiles.

  • Debugger: Watchpoint on local variable is triggered upon entering routine?

    Hi
    My problem is perhaps best illustrated in this small program:
    REPORT  zzkc_watchpoint.
    PERFORM form1 USING 'AB'.
    PERFORM form1 USING 'CD'.
    PERFORM form1 USING 'EF'.
    PERFORM form1 USING 'GH'.
    FORM form1  USING    value(p_1).
      DATA: lv_local(3)     TYPE c.
      IF 1 > 2.        <----
    Watchpoint triggered here - regardless of condition
      ENDIF.
      lv_local = p_1.
      IF 1 > 2.       <----
    And here when condition is met.
      ENDIF.
    ENDFORM
    I set a conditional watchpoint (all Module Instncs) on variable lv_local, condition: lv_local = 'EF', BUT: The watchpoint is whenever form form1 is entered. It's also triggered when lv_local eventually is set to 'EF", but why is it triggered upon entering form1???
    Best regards
    Kenneth

    This happens because the visibility of local variable is only in the subroutine. When system calls the subroutines subsequently, it reassigns the content of the local variable. If you watch the watchpoints (Watchpoints tool in the Break/watchpoints), you will see that for each subsequent call, system creates a new data reference and assign it to the Current Variable and Old variable. And it has the similar content (blank value) in the Current Value & Old Value.
    FORM form1 USING value(p_1).
      DATA: lv_local(3) TYPE c.
      IF 1 > 2. " At this point, Current Value and Old Value in the Watch points are same, BLANK.
      ENDIF.
      lv_local = p_1.   " here, After this statement Current Value would change to value of the P_1
      IF 1 > 2.
      ENDIF.
    ENDFORM.
    If you change the variable scope by changing it as the STATICS, it would only stop when it reaches to the EF.
    Check the last section:
    http://help.sap.com/saphelp_erp2005/helpdata/EN/f1/792442db42e22ce10000000a1550b0/frameset.htm
    In the OLD debugger, as soon as the validity of the variable changes, system would remove the watch point on that variable.
    Regards,
    Naimesh Patel

Maybe you are looking for

  • Payment run - without clearing liability/receivable

    Hi! is it possible to tell the payment run not to clear the liability/receivable? Customer wants to clear it when receives the bank statement! Thanks a lot Lothar

  • Requirment Urgent: How to format standard text in Script like two columns.

    Hi, I want to format the text in two columns like this. 1. This is the note. 5. This is the note. 2. This is the note. 6. This is the note. 3. This is the note. 7. This is the note. 4. This is the note. 8. This is the note. I have to include a standa

  • Problem in using TreeSet with a Comparator

    Hello, There seems to be a bug in the implementation of TreeSet, while using a specific Comparator to sort its elements. Here's the problem I got into: the Comparator I use has a type parameter which defines, of course, the type of objects that may b

  • Luxembourg phone number formatting in iOS = 4.0

    Hello, Since upgrading to iOS 4, phone numbers here in Luxembourg are no longer displayed in a readable way, the formatting is incorrect. Example : the correct phone number 26 52 26 52 would be displayed as 2 652 2652. That's bizarre, not logical and

  • Regarding LDB selection screen

    Hi All, I copied a standard LDB program "RCATSCMP". I have a date fields in selection screen. When i debuged the standard program i am getting the date values PN-BEGDA and PN-ENDDA. but when iam debugging my program iam not getting any values for the