Accessing class level variable in other class.

Hi All,
I have one variable declared at class level i.e. global variable (non-static). In one method I am setting one value in this variable.Now I want to access this variable with this new set value in other class.
Can anybody tell me how to do this?
Thanks in advance.
Neha

Neha_20 wrote:
Thanks for your reply. But its business req. to have byte[] as return type.
Pls suggest me other approches as well.Comments embedded.
Neha_20 wrote:
*Decode.java*
class Decode
byte[] decodeMessage(byte []datatoReceive)
for(int i=0,j=6; i<dataLen && j<j+responseData.length;i++,j++)
responseData[i] = datatoReceive[j];
System.out.println("Response Data [ "+i +" ]"+responseData);
Syntax syntaxObj1 = new Syntax(); // this creates a Syntax instance     
syntaxObj1.returnData(responseData); // this populates it
return responseData; // now it goes out of scope and disappears
Neha_20 wrote:
*User.java*
class User
public static void main(String args[])
// this creates a new unpopulated Syntax instance
Syntax syntaxObj = new Syntax();
for(int i =0;i<syntaxObj.dataRet.length;i++)
System.out.println("dataRet [ "+i+ " ]"+syntaxObj.dataRet);

Similar Messages

  • How to access variables from other class

        public boolean inIn(Person p)
            if  (name == p.name && natInsceNo == p.natInsceNo && dateOfBirth == p.dateOfBirth)
                 return true;
            else
                 return false;
        }//returns true if Person with same name/natInsceNo/dateOfBirth as phello,
    here am trying to compare the existing object with another object.
    could you please tell me how to access the variables of other class because i meet this error?
    name cannot be resolved!
    thank you!

    public class Person
        protected String name; 
        protected char gender;      //protected attributes are visible in the subclass
        protected int dateOfBirth;
        protected String address;
        protected String natInsceNo;
        protected String phoneNo;
        protected static int counter;//class variable
    //Constractor Starts, (returns a new object, may set an object's initial state)
    public Person(String nme,String addr, char sex, int howOld, String ins,String phone)
        dateOfBirth = howOld;
        gender = sex;
        name = nme;
        address = addr;
        natInsceNo = ins;
        phoneNo = phone;
        counter++;
    public class Store
        //Declaration of variables
        private Person[] list;
        private int count;
        private int maxSize;
    //constructor starts
        public Store(int max)
             list = new Person[max];//size array with parameters
             maxSize = max;
             count = 0;
        }//end of store
    //constructor ends
    //accessor starts  
        public boolean inIn(Person p)
           return (name == p.name && address == p.address && natInsceNo == p.natInsceNo);
        }//returns true if Person with same name/natInsceNo/dateOfBirth as phope it helps now!

  • How to access class variables in anonymous class??.

    I have a boolean class level variable. Fom a button action , this boolean will set to true and then it used in anonymous class. In anonymous class, I am getting default value instead of true. Could u anyone help in this plzzz.

    first of all, you don't want parent because that is something that Containers use to remember their containment hierarchy. you are thinking of super which is also incorrect, because that has to do with inheritance.
    the problem here is a scoping problem. you generally would use final if you were accessing variables in an anonymous class that are in the local scope. in this case, you just need to create some test code and play with it. snip the code below and play with it. it shows both the given examples and some additional ways to change/display class variables.
    good luck, hackerx
    import javax.swing.*;
    import java.awt.event.*;
    public class Foo extends JPanel
         private boolean the_b = true;
         public static void main(String[] args)
              Foo f = new Foo();
              JFrame frame = new JFrame();
              frame.getContentPane().add(f);
              frame.pack();
              frame.show();
         public Foo()
              // get your button
              JButton b = new JButton("Not!");
              b.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent ae)
                        // *** uncomment these to play around ***
                        // Foo.this.the_b = false; // this will work, but unnecessary
                        // the_b = false; // this works fine too
                        notFoo();
              this.add(b);
              // something to show the value that accesses a class variable
              // using an inner class instead of final nonsense
              DisplayThread t = new DisplayThread();
              t.start();
         private void notFoo()
              the_b = !the_b;
         class DisplayThread extends Thread
              public void run()
                   while(true)
                        System.err.println("boolean value: " + the_b);
                        try {
                        sleep(1000);
                        } catch(InterruptedException ie) {}
    }

  • Accessing a private variable from a public method of the same class

    can anyone please tell me how to access a private variable, declared in a private method from a public method of the same class?
    here is the code, i'm trying to get the variable int[][][] grids.
    public static int[][] generateS(boolean[][] constraints)
      private static int[][][] sudokuGrids()
        int[][][] grids; // array of arrays!
        grids = new int[][][]
        {

    Are you sure that you want to have everything static here? You're possibly throwing away all the object-oriented goodness that java has to offer.
    Anyway, it seems to me that you can't get to that variable because it is buried within a method -- think scoping rules. I think that if you want to get at that variable your program design may be under the weather and may benefit from a significant refactoring in an OOP-manner.
    If you need more specific help, then ask away, but give us more information please about what you are trying to accomplish here and how you want to do this. Good luck.
    Pete
    Edited by: petes1234 on Nov 16, 2007 7:51 PM

  • Accessing Managed Bean Variables in Entity Impl Class

    How can I access managed bean variables in the entity Impl class .
    While inserting a new record in DB , i want to set few entity properties values . The values of those properties are available in the managed bean .
    How can i access those values from Managed Bean and set them the entity Impl class to override the create method.
    Or is there any better recommended approaches ?
    Jdev - 11.1.1.5

    >
    While inserting a new record in DB , i want to set few entity properties values .
    >
    you can user CreateWithparams
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/13-create-with-params-169140.pdf
    http://andrejusb.blogspot.com/2011/02/createwithparams-operation-for-oracle.html

  • Use of variables from other class

    hallo,
    i have two classes A and B
    i would like to access a variable of the class B out of A class
    without class A extends B or
    A classA = new A();
    to use
    i attempted it with a constructor
    class A{
        B klb;
        public A(B b1){
        this.klb = b1;
       int a;
       a= klb.varausB;
    }with that I get, however, a NullPointerException
    in a similar form i saw it already once and it functioned
    somebody can help me?

    that is it what I mean
    public class ClassA {
    ClassB clb;
    public ClassA (ClassB cb){
    this.clb = cb;
    public static void main(String[] args) {
    System.out.println("Var from class B:
    class B: "+clb.varb1);// there is an error, i know
    but how it is right?
    public class ClassB {
    public String varb1 ="var b1";
    }nevertheless so similarly it should function, or?So if you create an instance of ClassA, clb will be initialized. But you don't do that in main. Hence your errors:
    1) You're not calling the constructor, so clb is null
    2) You're trying to access an instance variable without having an instance, so clb is not only null, it actually doesn't exist.
    public static void main(String[] args) {
      Class A myA = new ClassA();
      System.out.println("Var from class B: "+ myA.clb.varb1);
    }You're outside of any object, ehnce you need to address clb through an instance of ClassA.

  • How to access the int variable in the inner class

    hi all,
    i can't access the int variable in the inner class. can any one help me
    int count = 0;
    MouseMoveListener mouseMove = new MouseMoveListener() {
         public void mouseMove(MouseEvent e) {
              count1++;
              System.out.println(count);
    };how to access count variable
    thanks

    for this how can i access the countIf the count variable is a local variable you can't access it from within the
    inner class. Make it a member variable of the outer class instead:public class Outer {
       private int count;
       MouseMoveListener mouseMove= new MouseMoveListener() {
          public void mouseMove(MouseEvent me) {
             count++;
             System.out.println(count);
    }Alternatively, if you don't need that count variable anywhere else, you
    could simply make it a member variable of the inner class itself:public class Outer {
       MouseMoveListener mouseMove= new MouseMoveListener() {
          private int count;
          public void mouseMove(MouseEvent me) {
             count++;
             System.out.println(count);
    }kind regards,
    Jos

  • Can one obj access a private variable of another obj of the same class

    Can one object access a private variable of another object of the same class?
    If so, how?

    Declaring variable private means you can not access this variable outside class
    But other objects of same class can access it. Because each object have separate copy of variable and may have diff. contents for same variable.

  • Accessing a public variable between classes

    Hi there,
    I've got two classes running...one is a document class (EgoGame.as) and another is a class linked to several similar movie clips (Ball.as).
    I'm trying to access a public variable from Ball.as which has been declared in the doucment class EgoGame.as.
    When I run the test the outputs states the following...
    1120: Access of undefined property _ballPlaced.
    Here's my code.  What I'm trying to do is remove the event listeners from the Ball.as when the _ballPlaced variable is true, so that the user can't drag and drop the balls after they've been placed in a zone....any pointers greatly appreciated!
    Document Class
    EgoGame.as
    package
        import flash.display.MovieClip;
        import flash.display.DisplayObject;
        import flash.events.MouseEvent;
        import Ball;
        public class EgoGame extends MovieClip
            public var __zoneFull:Array = new Array(false, false, false);
            public var __ballPlaced:Array = new Array(false, false, false);
            public function EgoGame()
                ball0_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
                ball1_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
                ball2_mc.addEventListener(MouseEvent.MOUSE_DOWN, zoneEmpty);
                ball0_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
                ball2_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
                ball1_mc.addEventListener(MouseEvent.MOUSE_UP, zoneFill);
                ball0_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
                ball1_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
                ball2_mc.addEventListener(MouseEvent.MOUSE_UP, playMovie);
            private function zoneEmpty(event:MouseEvent):void
                if(event.target.hitTestObject(zone0_mc) && _zoneFull[0] == true)
                    _zoneFull[0] = false;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
                else if(event.target.hitTestObject(zone1_mc) && _zoneFull[1] == true)
                    _zoneFull[1] = false;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
                else if(event.target.hitTestObject(zone2_mc) && _zoneFull[2] == true)
                    _zoneFull[2] = false;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
                else
                    event.target.x = event.target._startX;
                    event.target.y = event.target._startY;
                    _ballPlaced[event.target.name.substring(4,5)] = false;
            private function zoneFill(event:MouseEvent):void
                if(event.target.hitTestObject(zone0_mc) && _zoneFull[0] == false)
                    event.target.x = zone0_mc.x;
                    event.target.y = zone0_mc.y;
                    _zoneFull[0] = true;
                    _ballPlaced[event.target.name.substring(4,5)] = true;
                else if(event.target.hitTestObject(zone1_mc) && _zoneFull[1] == false)
                    event.target.x = zone1_mc.x;
                    event.target.y = zone1_mc.y;
                    _zoneFull[1] = true;
                    _ballPlaced[event.target.name.substring(4,5)] = true;
                else if(event.target.hitTestObject(zone2_mc) && _zoneFull[2] == false)
                    event.target.x = zone2_mc.x;
                    event.target.y = zone2_mc.y;
                    _zoneFull[2] = true;
                    _ballPlaced[event.target.name.substring(4,5)] = true;
                else
                    event.target.x = event.target._startX;
                    event.target.y = event.target._startY;
                    _ballPlaced[event.target.name.substring(4,5)] =false;
            private function playMovie(event:MouseEvent):void
                if (_ballPlaced[0] == true)
                    ball0_mc.gotoAndPlay(2);
                else
                    ball0_mc.gotoAndStop(1);
                if (_ballPlaced[1] == true)
                    ball1_mc.gotoAndPlay(2);
                else
                    ball1_mc.gotoAndStop(1);
                if (_ballPlaced[2] == true)
                    ball2_mc.gotoAndPlay(2);
                else
                    ball2_mc.gotoAndStop(1);
    Ball.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.display.DisplayObject;
        import EgoGame;
        public class Ball extends MovieClip
            // public var _hitTarget:MovieClip;
            public var _startX:Number;
            public var _startY:Number;
            public function Ball()
                _startX = this.x;
                _startY = this.y;
                this.buttonMode = true;
                this.addEventListener(MouseEvent.MOUSE_DOWN, dragIt);
                this.addEventListener(MouseEvent.MOUSE_UP, dropIt);
            private function dragIt(event:MouseEvent):void
                this.startDrag();
            public function dropIt(event:MouseEvent):void
                this.stopDrag();
            public function lockBall(event:MouseEvent):void
                if(_ballPlaced[this.name.substring(4,5)] == true)
                    this.removeEventListener(MouseEvent.MOUSE_DOWN, dragIt);
                    this.removeEventListener(MouseEvent.MOUSE_UP, dropIt);

    every place you have a ball reference you can access the lockBall() method.  so, if ball0_mc is a Ball class member, you can use:
    ball0_mc.lockBall();

  • Java Access Classes

    Hi -
    Saw an interesting reference to Java Access Classes in a paper about Oracle Lite 3.0 (http://technet.oracle.com/products/8i_lite/htdocs/olja_bwp.htm?found)
    Can anybody point me to resources about how to/can I use Java Access Classes with 8iEE?
    Thanks!
    -best-darr-

    I just checked the link out you provided. However I dont have xml files when I access my REST service, I get JSON objects returned. I dont think this wizard can handle that.
    Anyways my version is 11.1.2.2.0 Generic on Mac.
    I have a Service lets say at http://99.99.99.99/daily_meals/yyyy-MM-dd, where the last level stands for the different days that you can request and the service then replies with a JSON object containing all the possible meals for this specific date. I then parse the JSON objects in java to fill the list. All this happens in the constructor of the class but I dont know how to have it set dynamically. I thought about using beans, but I cant iterate through a list in a bean as nicely as with data-controls.
    Maybe Bind Variables and Named Critera are the answer? Haven't figured those out yet.
    Thanks,
    Pascal
    Edited by: Pascal B on Jul 4, 2012 6:46 AM

  • Unable to access classes in third party jar files packaged with my ejb.jar

    I have packaged some third party jar files in my xxx_ejb.jar file.  The third party jar file contains classes that are accessed by some custom classes which are in turn accessed by my bean classes.  I get the following error when my custom classes attempt to use any of the classes in one of the third party jar files:
    java.lang.NoClassDefFoundError: com/Ostermiller/util/CSVParser
    Shouldn't I be able to access classes in jar files that are packaged with my xxx_ejb.jar file?  I see the xxx_ejb.jar file as a resource of the application classloader that contains it but I don't see the third party jar files.

    As per the Java EE specification, additional JAR files should be packaged on the EAR level. Only WAR files' WEB-INF/lib folder is scanned for JAR files to be added to the classloader.

  • Access class attribute by class name

    Hi experts,
    Can anyone help me in next situation.
    I need access class static attribute by class name and attribute name. I have two initialized variables
    DATA: class_name(30) TYPE c,
    attr_name(30) TYPE c.
    In another words, I need to do attribute initializing like
    ZCL_IM_BM_VPA10_IMPL=>P_VAR_ZPLV_CLM = loc_var_range-low.
    but using char variables insead of reference to class.
    Thanks in advance,
    Max.

    You want dynamic access to a static attribute?  If these are your own Z classes, then rather than access the attributes directly, write getter and setter methods.
    Then you can use (as it is in the ABAP help on dynamic call methods ).
    TRY.
        CALL METHOD (class)=>(meth)
          PARAMETER-TABLE
            ptab
          EXCEPTION-TABLE
            etab.
        CASE sy-subrc.
          WHEN 1.
        ENDCASE.
      CATCH cx_sy_dyn_call_error INTO exc_ref.
        exc_text = exc_ref->get_text( ).
        MESSAGE exc_text TYPE 'I'.
    ENDTRY.
    btw - next time, post in the ABAP objects forum.
    matt

  • Default access class

    I tried searching for this but couldn't find it. If you have a package-access class, are there any special rules on access modifiers allowable for variables and methods?
    Thanks.

    No.Good answer.
    http://java.sun.com/docs/books/tutorial/java/java
    OO/accesscontrol.html
    http://java.sun.com/docs/books/tutorial/java/java
    OO/classdecl.html
    http://java.sun.com/docs/books/tutorial/java/java
    OO/index.html
    http://java.sun.com/docs/books/jls/third_edition/
    html/j3TOC.html
    Offset your good answer with these useless links.
    So, why is there no restriction? If you have a default-access classes but public (or protected?) members, wouldn't they still not be accessible for that class? Though it could just be another "simply memorize it" rule, are there any reasons you might think of for why it's done like that?

  • Cannot access class java.nio.ByteBuffer

    Hi All -
    I'm trying to compile a java sample code.
    I keep getting the error described in the subject line
    cannot access class java.nio.ByteBuffer; file java\nio\ByteBuffer.class not found
    I have un-ziped the java sdk 1.4.1 src.zip to a directory under c:\ and added the java\nio directory to the project setting and compile with jdk runtime 1.4.1 and yet get the same error....
    I've tried by redirecting to src.zip and didn't work either....
    I would appreciate your feedbacks and sorry for the lame question, consider it as a newcomer to Java world.
    thanks in advance

    You test it by running the following line....
    java java.nio.ByteBuffer
    If it says "main not found" then your problem has nothing to do with the java install nor the classpath. The code you are trying to compile is wrong.
    If it says class not found then you use this line next....
    java -version
    If this returns nothing then you are not using the Sun VM (you are using the MS one.) If it returns a version below 1.4 then your PATH statement is wrong (and you should uninstall all sun versions then reinstall.) You can fix the MS VM problem by altering the path so the java path is first.
    If it does say 1.4 then you need to uninstall and reinstall because something is messed up.

  • Non-admin user cannot access Essbase server level variables

    Version 11.1.1.3
    Essbase Substitution variables are created at server level. Users are getting error in FR report that uses the Subsitution Variable -- Essbase Error(1051085): You do not have sufficient access to get this substitution variable. Also, users cannot access Substitution variable in SmartView. However, users can access variables created at database level. Users are provisioned as "Server Access" to Essbase and filter access to ASO application "MGTRPTG", where MGTRPTG is an ASO essbase application for reporting. We tried the same provisioning in two other environments and it seems to be working fine.
    User is type "Essbase and Planning" provisioned with essbase "server access", application mgtrptg "filter", Reporting and Analysis "analyst", "dynamic viewer" and "Explorer". In addition, it is given a filter "REP_DME_GALB" which restricts 2 dimensions (Division and Geography).
    Steps taken to resolve:
    1. Existing users were deprovisioned and reprovisioned with no effect.
    2. Created brand new identically provisioned users in Prod and QA. QA user can access the server level var and Prod user cannot
    3. Created a brand new server level variable in Prod and this cannot be accessed.
    4. All services have already been restarted several times.
    5. SR has been opened.
    Temporary workaround:
    By creating a duplicate of the same set of variables at the database level, the reports work. This can only be a temporary workaround as the client cannot be expected to maintain two sets of substitution variables since there are 3 applications using these server level variables.
    Thank you for any ideas!
    Jennifer

    You have stumbled on a defect which is resolved in the Hyperion Planning 9.3.1 patch 6 and above. If you have your planning preferences set to indent members it will cause forms which have page selections to show as invalid in SmartView.
    You can either patch Planning or turn off the preference. The patches are available from http://metalink3.oracle.com and require account which has been associated with your client ID.
    P.S. Usually it's not a good practice to use the admin id.
    Regards,
    -John
    Edited by: Jbooth on Nov 3, 2008 2:12 PM

Maybe you are looking for

  • Windows 7 Word 2010 with EPS A4 Acrobat X Pro Paper Size Issue

    I'm running into the following issue trying to create a PDF. Word 2010 A4 page size. Document has some Illustrator EPS images used in it. When I go to make the PDF using Acrobat from the top menu and then Create PDF, the page size of the PDF is A4, b

  • Source name not file name

    Hi Everyone... Lost and replaced a drive... Now I need to recapture... But then the ensuing dialogue informs me (for every selected offline clip) that another file called " " already exists. Sure enough, the clips' item properties tell me their sourc

  • SQL Loader error: SQL*Loader-926. Please help

    Hi, While loading some files to my database table, I am getting the following error. I am using 'Truncate' option while loading the file: Error: ==== SQL*Loader-926: OCI error while executing delete/truncate (due to REPLACE/TRUNCATE keyword) for tabl

  • G5 just won't start up

    Can anyone help me? My G5 Powermac is less than two years old. Under warranty, after a power cut, it refused to start. It was mended by Apple. I bought a power surge protector. Today, the same thing happened again. Although the little light is on, th

  • Hi, about table maintainance

    How  can  we enter the values in the table with out using th option table maintainance allowed.