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

Similar Messages

  • Passing values between methods in the same class

    Hi,
    How to pass internal tables or values between methods in the same class.
    How to check if the internal method in another method is initial or not.
    How to see if the method has already been executed.
    Thanks.

    Just declare the internal table as an attribute in the class - that way every method in this class has access to it.
    Since any method has access to all class attributes you can easily check if the internal table is initial or not.
    I am not aware of any standard functionality if a method has already been executed or not, one way would be to declare a class attribute for each method and set it once the method has been executed. That way every method in that class would know which method has already been executed or not.
    Hope that helps,
    Michael

  • Remote devive access and acquiring signals from a different PC in the same LAN

    Well, I'm still interested in knowing if the way to see the DAQ channels from one PC to another located in the same LAN is the Remote device acess RDA?
    If the answer is yes I would appreciate the information from sombody who has done it.
    Thanks

    Please don't create another question. I answered you to a previous one that is the same than this. Here is also the response.
    Hello,
    the only easy way in order to do that is to use RDA ( Remote Device Access ). This is a component that is installed when you install NI-DAQ. Currently, RDA is only supported by Traditional NI-DAQ. So, if you have programmed your application using NI-DAQmx, it might be more dificult because you will have to use networking communication VIs as Datasocket,TCP/IP, ....
    Here you have a link about RDA. There, there is a link to an Application Note called Networking Two PCs for Remote Data Acquisition
    http://digital.ni.com/public.nsf/websearch/5CC9792C6CD4A34C862565BC0072D5DF?OpenDocument
    I hope this helps.
    Regards
    crisR

  • How does a method extend another method in the same class ??

    hi everybody, I want to know if it is possible to have such code as:
    void foo(){
    // foo process
    void bar <<extend>> foo{
    //foo process
    //bar process
    thanks for helping me

    Since you want different names for each of your so-called "child" methods, then neither overloading nor overriding in a subclass will work as each relies on the same method names. Perhaps the following will suffice:
    public class MyClass
       //some stuff
       private myMethodThatDoesSomeStuff()
          //do some stuff that all the other methods must also do
       private methodA(int q, byte z)
          myMethodThatDoesSomeStuff();
          // continue with this method.
       private methodL(short v, float g23)
          myMethodThatDoesSomeStuff();
          // continue with this method.
    }If not, you need to do some design work.

  • Accessing html field value from pl/sql code, in the same package

    hi friends,
    my pl/sql web application is working fine. but now i need a small requirment.
    ie, basicaly i need to access the user entered value of an element in html based form from pl/sql code, which is developed using pl/sql toolkit.
    Here is the scenario:-
    User entered a value in field1, then navigate to field2, and click a button for list of values,
    when he clicks the button, internaly it is opening a cursor, where i want to pass field1's value to my cursor as a parameter. So in my pls/sql code , i want to access the value of field1. If you know, please help.
    see the snippet of code.
    htp.p('
    function f1()
    if (parseInt(learnIdx) ==1 )
    for i in dev_Need('1')/*here i want to pass html form element value as a parameter */
    loop
    htp.p('content += "<option value='''||a.version_name||'''>'||a.version_name
    ||'</option>''"; ');
    end loop;
    thanks in advance.
    Zameer.N.A

    Hi,
    Here's my suggestion
    If you wanna access the dll check out "external procedures", you can search it everywhere in OTN.
    However it's easier to use Heterogenous Services to connect database with other sources.
    Check out http://asktom.oracle.com/pls/ask/f?p=4950:8:13454621522426176943::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:4406709207206,
    Tak Tang answer on May, 25, 2004 rules!

  • Access AM in Model from a different project inside the same applictaion

    Hi
    I am using JDeveloper 11.1.1.6.0
    I am tryiing to create an AM instance in a java class which is inside the a project
    The structure of my APP is as shown below
    MYAPP
    |___Model
    |___MyProject
    |___ViewController
    the Java class is inside the MyProject and I am trying to create an APpp Module insance using
    ApplicationModule am = Configuration.createRootApplicationModule("model.AppModule", "AppModuleLocal");  But it is returning an error like
    INFO: MDS-00013: no metadata found for metadata object "/model/common/bc4j.xcfg"
    Exception in thread "main" oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.ConfigException, msg=JBO-33001: Configuration file /model/common/bc4j.xcfg is not found in the classpath.
         at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:529)
         at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1508)
         at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1485)
         at com.myapp.PlanlWithDecisionPointUsingPreloadedDictionary.runWithPreloadedDictionary(PlanlWithDecisionPointUsingPreloadedDictionary.java:67)
         at com.myapp.PlanlWithDecisionPointUsingPreloadedDictionary.main(PlanlWithDecisionPointUsingPreloadedDictionary.java:50)
    Caused by: oracle.jbo.ConfigException: JBO-33001: Configuration file /model/common/bc4j.xcfg is not found in the classpath.
         at oracle.jbo.client.Configuration.loadFromClassPath(Configuration.java:467)
         at oracle.jbo.common.ampool.PoolMgr.loadConfiguration(PoolMgr.java:600)
         at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:526)
         ... 4 more
    ## Detail 0 ##
    oracle.jbo.ConfigException: JBO-33001: Configuration file /model/common/bc4j.xcfg is not found in the classpath.
         at oracle.jbo.client.Configuration.loadFromClassPath(Configuration.java:467)
         at oracle.jbo.common.ampool.PoolMgr.loadConfiguration(PoolMgr.java:600)
         at oracle.jbo.common.ampool.PoolMgr.findPool(PoolMgr.java:526)
         at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1508)
         at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1485)
         at com.myapp.PlanlWithDecisionPointUsingPreloadedDictionary.runWithPreloadedDictionary(PlanlWithDecisionPointUsingPreloadedDictionary.java:67)
         at com.myapp.PlanlWithDecisionPointUsingPreloadedDictionary.main(PlanlWithDecisionPointUsingPreloadedDictionary.java:50)Why is this happening ?
    Thanks
    Nigel.

    Configuration file /model/common/bc4j.xcfg is not found in the classpath.
    is that the full path .. ? ? ? ? model.appModule

  • Running different set of methods on the same class via threads

    Hello all,
    I have this issue that I am trying to deal with. It looks pretty simple to me, but maybe just a mental block I guess :)
    Now the code below will give you an idea of what I am trying to achieve. I am not sure if its possible or if there is some other better way to do this. Any help will be appreciated.
    Thanks
    public class TestClass extends Thread{
         public TestClass(){
         // Assume something goes in here.
         public void abc(){
              System.out.println("In abc");
         public void xyz(){
              System.out.println("In xyz");
         public void run(){
         //What do I put here, since my call is specific.
         public static void main(String args[]){
              TestClass t1 = new TestClass();
              t1.start();// I want t1 to call only abc()
              TestClass t2 = new TestClass();
              t2.start();// I want t2 to call only xyz
    }Edited by: mikkin on Mar 12, 2009 3:00 PM

    kogose wrote:
    you can use the Reflection API to make the desired method an instance variable:Whoa, that's a pretty big case of over-engineering (or under-engineering, depending on how you look at it) and abuse of Reflection. The real problem in the original post is that Thread isn't being used properly. You almost never want to subclass Thread, for reasons like these: your runnable target should be separate from the thread. I would organize your code like this:
    public class TestClass {
       public TestClass() {
          // Assume something goes in here.
       public void abc() {
          System.out.println("In abc");
       public void xyz() {
          System.out.println("In xyz");
       public static void main(String args[]) {
          final TestClass t1 = new TestClass();
          final TestClass t2 = new TestClass();
          new Thread(new Runnable() {
             public void run() { t1.abc(); }
          }, "t1Thread").start();
          new Thread(new Runnable() {
             public void run() { t2.xyz(); }
          }, "t2Thread").start();                   
       }

  • Accessing super class  private variables from derived class

    posted November 01, 2005 08:20 PM Profile for kenji mapes Email kenji mapes Send New Private Message Edit/Delete Post Reply With Quote Assume I have a default and a param constructor in both a subclass and a super class. The members are private.
    So after validation logic in the sub class param. constructor, I want to access an instance variable of the super class's default constructor to set the subclass's matching variable to the default in the super class.
    Is there anyway I can do this. Of course, I have inherited setters and getters.
    Thanks.

    posted November 01, 2005 08:20 PM Profile for
    kenji mapes Email kenji mapes Send New Private
    Message Edit/Delete Post Reply With QuoteI suppose this is the result of an attempted crossposting from another forum. :)

  • Inhiterance:unknow down-cast exception.Access a private attrib.from subclas

    Hi guys,
    I need your help.
    Many examples, shows that i can create a sub-class inheriting from a super-class, add methods and attributes, make something like : <subclass variable> ?= <superclass instance> and then call method of the subclass (that are able to access to protect data of superclass instance for example).
    But when i try to do the same with a class derived from cl_gui_alv_grid, i have always a casting type exception in the down-cast instruction.
    Example :
    field-symbols: <outtab> type standard table.
    data : gos_alv type ref to cl_gui_alv_grid.
    *       CLASS lcl_gui_alv_grid DEFINITION
    class lcl_gui_alv_grid definition inheriting from cl_gui_alv_grid.
      public section.
        methods : get_tab_line.
    endclass.                    "lcl_gui_alv_grid DEFINITION
    *       CLASS lcl_gui_alv_grid IMPLEMENTATION
    class lcl_gui_alv_grid implementation.
      method get_tab_line.
    * mt_outtab is the data table held as a protected attribute
    * in class cl_gui_alv_grid.
        assign me->mt_outtab->* to <outtab>. "Original data
      endmethod.                    "get_tab_line
    endclass.                    "lcl_gui_alv_grid IMPLEMENTATION
    data : l_alv type ref to lcl_gui_alv_grid.
    But when i do a downcast like this (gos_alv was already created with "create object" istruction):
    l_alv ?= gos_alv.
    I have an exception of casting error. I cannot understand why and how to solve the problem.
    Thank you very much for your collaboration.
    Andrea

    Hi Andrea,
    I suggest you to tweak a code a litte bit as I guess the point is to get mt_outtab table, right?
    CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
      PUBLIC SECTION.
        CLASS-METHODS get_tab_line IMPORTING o_alv TYPE REF TO cl_gui_alv_grid.    "declare method as static one
    ENDCLASS.                   
    CLASS lcl_gui_alv_grid IMPLEMENTATION.
      METHOD get_tab_line.
        FIELD-SYMBOLS <outtab> TYPE STANDARD TABLE.
        assign me->mt_outtab->* to <outtab>.
        "your desired coding here
      ENDMETHOD.                   
    ENDCLASS.                   
    Now all you need to do is to call static method get_tab_line providing your actual alv reference
    data : gos_alv type ref to cl_gui_alv_grid.
    CREATE OBJECT gos_alv ....
    lcl_gui_alv_grid=>get_tab_line( gos_alv ).     
    As for your question, why this code
    l_alv ?= gos_alv.
    triggeres an exception cx_sy_move_cast_error .
    If you use this coding
      TRY.
          l_alv ?= gos_alv.
        CATCH.
          cx_sy_move_cast_error
    "system will end up here
      ENDTRY.
    ...you would prevent the system to dump out, but the exception will be triggered anyway. You will just catch it.
    The problem arises simply from fact that down cast checks wheterer these two reference variables l_alv and gos_alv are on the same level. This is why you put there question mark ? asking the system if gos_alv in fact contains appropriate reference. You can only evaluate it during program execution.
    When it comes to down cast always image such situation.
    You have VEHICLE class (your cl_gui_alv_grid ). The class which inherits from it is PLANE (your lcl_gui_alv_grid). Now you can always do such assingnment
    VEHICLE = PLANE (cl_gui_alv_grid = lcl_gui_alv_grid)    "up cast - narrow cast
    but you never can do this
    PLANE = VEHICLE (lcl_gui_alv_grid = cl_gui_alv_grid)  "down cast
    It is becasue plane is always a vehicle, but vehicle doesn't have to be a plain. It can be either a truck, ship or a plane.
    Therefore for down cast you always has to ask system if VEHICLE really contains (during exection) reference to a PLANE. That's why you write it like
    PLANE ?= VEHICLE (lcl_gui_alv_grid ?= cl_gui_alv_grid)
    The system checks then if vehicle really contains plane reference inside.
    Thought it might be not useful for first sight, it is a basis of polimorphism, but it is a talk for another time;)
    Regards
    Marcin

  • 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.

  • How do I access Captivate 6 variables from a playbar?

    I need to access Captivate 6 variables from a playbar. Does anybody know how? I know the parent/child relationship has changed from previous versions.

    Dear Herod,
    Thanks for the request, To program a FPGA target you must have the module
    Labview FPGA. So you cannot directly access the FPGA with LabWindows/CVI.
    But there is a way. Firstly create with Labview a Host VI that communicate with
    the FPGA target and compile this VI into a dll and then call it from CVI program.
    See the following link:
    Can I Use a Programming Language
    Other Than LabVIEW with a Reconfigurable I/O Board?
    LabWindows/CVI support for PXI 7831 R
    Best regards,
    Nick_CH

  • Passing variables from php to flash and the opposite

    Hi guys, im trying weeks now to solve this problem but nothing yet
    If someone could just tell me how to pass variables from flash to php and the opposite i would be thankful!!! Please help!

    I have recently had to learn this, so this may not be the best way but it worked for me
    I suggest looking at the code below stripping out everything you don't need (e.g. the databse stuff) and just get a simple string going back and forward
    have a go and post any problems here and I'll try and help
    in flash i have
    private function getBalanceAndXP():void
              var request:URLRequest = new URLRequest("utils.php");
              request.method = URLRequestMethod.POST;
              var variables:URLVariables = new URLVariables();
              variables.func = "getBalance";
              variables.fbid = userID;
              request.data = variables;
              var loader:URLLoader = new URLLoader();
              loader.dataFormat = URLLoaderDataFormat.VARIABLES;
              loader.addEventListener(Event.COMPLETE, onBalanceComplete);
              loader.load(request);
    private function onBalanceComplete(e:Event):void
              var loader:URLLoader = e.target as URLLoader;
              loader.removeEventListener(Event.COMPLETE, onBalanceComplete);
              var variables:URLVariables = new URLVariables(loader.data);
              _balance = parseInt(variables.balance); // class variable
              _experience = parseInt(variables.experience); // class variable
    public function setBalanceAndXP(balance:int, experience:int):void
                _balance = balance;
              _experience = experience;
              var request:URLRequest = new URLRequest("utils.php");
              request.method = URLRequestMethod.POST;
              var variables:URLVariables = new URLVariables();
              variables.func = "setBalance";
              variables.fbid = userID;
              variables.balance = _balance;
              variables.experience = _experience;
              request.data = variables;
              var loader:URLLoader = new URLLoader();
              loader.dataFormat = URLLoaderDataFormat.VARIABLES;
              loader.load(request);
    and then I have my php file
    <?php
    $func = $_POST["func"];
    $fbid = $_POST["fbid"];
    $balance = $_POST["balance"];
    $experience = $_POST["experience"];
    $numVariables = 0;
    $link = mysql_connect("localhost","username","password");
    mysql_select_db("databaseName");
    if ($func == "getBalance")
              getBalance($fbid);
    else if ($func == "setBalance")
              setBalance($fbid, $balance, $experience);
    mysql_close($link);
    function getBalance($fbid)
              $query = "SELECT balance, experience FROM tableName WHERE fbid = '".$fbid."'";
              $result = mysql_query($query);
              $row = mysql_fetch_row($result);
              writeVariable("balance", $row[0]);
              writeVariable("experience", $row[1]);
    function setBalance($fbid, $balance, $experience)
              $query = "UPDATE tableName SET balance = ".$balance.", experience = ".$experience." WHERE fbid ='".$fbid."'";
              mysql_query($query);
    function writeVariable( $name, $value )
              global $numVariables;
              if ( $numVariables > 0 )
                        echo "&";
              echo $name . "=" . urlencode($value);
              $numVariables++;
    ?>

  • How do I call methods with the same name from different classes

    I have a user class which needs to make calls to methods with the same name but to ojects of a different type.
    My User class will create an object of type MyDAO or of type RemoteDAO.
    The RemoteDAO class is simply a wrapper class around a MyDAO object type to allow a MyDAO object to be accessed remotely. Note the interface MyInterface which MyDAO must implement cannot throw RemoteExceptions.
    Problem is I have ended up with 2 identical User classes which only differ in the type of object they make calls to, method names and functionality are identical.
    Is there any way I can get around this problem?
    Thanks ... J
    My classes are defined as followes
    interface MyInterface{
         //Does not and CANNOT declare to throw any exceptions
        public String sayHello();
    class MyDAO implements MyInterface{
       public String sayHello(){
              return ("Hello from DAO");
    interface RemoteDAO extends java.rmi.Remote{
         public String sayHello() throws java.rmi.RemoteException;
    class RemoteDAOImpl extends UnicastRemoteObject implements RemoteDAO{
         MyDAO dao = new MyDAO();
        public String sayHello() throws java.rmi.RemoteException{
              return dao.sayHello();
    class User{
       //MyDAO dao = new MyDAO();
       //OR
       RemoteDAO dao = new RemoteDAO();
       public void callDAO(){
              try{
              System.out.println( dao.sayHello() );
              catch( Exception e ){
    }

    >
    That's only a good idea if the semantics of sayHello
    as defined in MyInterface suggest that a
    RemoteException could occur. If not, then you're
    designing the interface to suit the way the
    implementing classes will be written, which smells.
    :-)But in practice you can't make a call which can be handled either remotely or locally without, at some point, dealing with the RemoteException.
    Therefore either RemoteException must be part of the interface or (an this is probably more satisfactory) you don't use the remote interface directly, but MyInterface is implemented by a wrapper class which deals with the exception.

  • I have the app "viPlay" on my iPad and iPhone. Is there any way that it could be available for the Apple TV? I'd like to access my personal videos from my hard drive using the Apple TV through the 'viPlay' app.

    I have the app "viPlay" on my iPad and iPhone. Is there any way that it could be available for the Apple TV? I'd like to access my personal videos from my hard drive using the Apple TV through the 'viPlay' app.

    Welcome to the Apple Community.
    Nobody here will have any information about that since the community is only made up of users like you or I. Anything else is mere speculation and speculation is not permitted here under the Terms of Use for these communities.
    Any responses you may receive may well be removed and would be wholly unreliable in any case.
    If you believe that Apple's product may be enhanced in anyway you can leave feedback here.

  • HT1918 I cannot access files I uploaded from an old computer.  The email account to which some tracks are connected is deleted. For some reason my birth date doesn't work either. Is there some way to transfer the files to my current address?

    I cannot access files I uploaded from an old computer. The email account to which some tracks are connected is deleted. For some reason my birth date doesn't work either. Is there some way to transfer the files to my current address and username?

    Most likely you have Office 2004 which are PPC-only applications and will not work in Lion. Upgrade to Office 2011. Other alternatives are:
    Apple's iWork suite (Pages, Numbers, and Keynote.)
    Open Office (Office 2007-like suite compatible with OS X.)
    NeoOffice (similar to Open Office.)
    LibreOffice (a new direction for the Open Office suite.)

Maybe you are looking for

  • Problem in F.05 in foreign currency valuation

    Hi all we are facing some problem in the F.05..that is we are getting some amount  difference in one company code 6000 but we do not have any issues with the forex revaluation. We are following the same process for both the company codes i. e 4000 an

  • Repeating Header and Footer on each page in Sub-Report

    Post Author: Jimbob CA Forum: General I am formatting a report that has subreports.  I can get the header on every page, but the footer only appears on the last page.  How do I get a header and footer to print on each page of the subreport? Thanks fo

  • Symbian S^3/Anna Calendar Meeting Request (Invitee...

    First... I want to explain how this came about. I've never sent out a Meeting Invite from my Nokia N8 (PR1.2) to anyone before. However, in the days of collaboration, people send & receive Calendar Appointments to and from different Email/PIM Clients

  • Error in RSRV

    Hi I am getting a short dump while uploading to an ODS On some analysis i was suggested for transaction RSRV I m getting the following error on "checking consistency of PSA with SAP administrator" Inconsistency: High value for table /BIC/B0000590000:

  • CS5 "Locked"

    Well, CS5 is not treating me well, so far. When I go to to Workspaces/New in CS5 and when I quit , I get a message like this: "Could not save Preferences because the file is locked or you do not have the necessary access privileges. Use the 'Get Info