How to let a derived class in a parameterized constructor chain access fields of the base class that are initialized using the derived constructorInitialize class fields in constructor or at declaration?Accessing constructor of an anonymous classOrder of constructors for a C# class: parameterized, default, and static?C# constructor chaining? (How to do it?)While constructing the default constructor can not handle exception : type Exception thrown by implicit super constructorchaining constructors in Java without throwing exceptions from the default constructorWhy Java StringReader throws IOException?Chain Constructor from parents classAll reflection methods accessing constructor of class generated through ASM throw NoClassDefFoundError if class references primitive type

Is there a command-line tool for converting html files to pdf?

Plotting Autoregressive Functions / Linear Difference Equations

How do I handle a DM that plays favorites with certain players?

On the consistency of different well-polished astronomy software

Why is Heisenberg shown dead in Negro y Azul?

Write The Shortest Program to Calculate Height of a Binary Tree

Why is the Vasa Museum in Stockholm so Popular?

Is there any difference between "result in" and "end up with"?

How to win against ants

When using the Proficiency Dice optional rule, how should they be used in determining a character's Spell Save DC?

How to check a file was encrypted (really & correctly)

Is it uncompelling to continue the story with lower stakes?

What is the difference between "un plan" and "une carte" (in the context of map)?

Is there a general term for the items in a directory?

How does Geralt transport his swords?

How do I know when and if a character requires a backstory?

The warlock of firetop mountain, what's the deal with reference 192?

how to change dot to underline in multiple file-names?

Why does capacitance not depend on the material of the plates?

Can a Sikh enter a buddhist temple with a turban?

The Game of the Century - why didn't Byrne take the rook after he forked Fischer?

What printing process is this?

How easy is it to get a gun illegally in the United States?

How to design an effective polearm-bow hybrid?



How to let a derived class in a parameterized constructor chain access fields of the base class that are initialized using the derived constructor


Initialize class fields in constructor or at declaration?Accessing constructor of an anonymous classOrder of constructors for a C# class: parameterized, default, and static?C# constructor chaining? (How to do it?)While constructing the default constructor can not handle exception : type Exception thrown by implicit super constructorchaining constructors in Java without throwing exceptions from the default constructorWhy Java StringReader throws IOException?Chain Constructor from parents classAll reflection methods accessing constructor of class generated through ASM throw NoClassDefFoundError if class references primitive type






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a class Feedforward with a parameterized constructor of a configuration file:



public Feedforward(String cfg) throws Exception {

super(cfg);
String tempstr = "";
int currNeuronNum = 0;
int currEdgeNum = 0;
int currLayerID = 0;
int count = 0;

if (!(type).equals("feedforward"))
throw new Exception("cfgError: specify proper type")
//more code



where the super(cfg) calls the constructor of the Network class, where I handle file parsing and storage of universal fields:



protected Network(String cfgPath) throws IOException, Exception 

String type;
String activationFunction;
double bias;
/*file reading stuff; checked with print statements and during
the creation of a Feedforward class, successfully prints
"feedforward" after reading type from file
*/



and when I run a test, it throws a NullPointerException. The type variable in Feedforward is not assigned with the value stored in the file at cfgPath/cfg, hence the exception. Why doesn't constructor chaining do this, and how can I do things differently?










share|improve this question






























    0















    I have a class Feedforward with a parameterized constructor of a configuration file:



    public Feedforward(String cfg) throws Exception {

    super(cfg);
    String tempstr = "";
    int currNeuronNum = 0;
    int currEdgeNum = 0;
    int currLayerID = 0;
    int count = 0;

    if (!(type).equals("feedforward"))
    throw new Exception("cfgError: specify proper type")
    //more code



    where the super(cfg) calls the constructor of the Network class, where I handle file parsing and storage of universal fields:



    protected Network(String cfgPath) throws IOException, Exception 

    String type;
    String activationFunction;
    double bias;
    /*file reading stuff; checked with print statements and during
    the creation of a Feedforward class, successfully prints
    "feedforward" after reading type from file
    */



    and when I run a test, it throws a NullPointerException. The type variable in Feedforward is not assigned with the value stored in the file at cfgPath/cfg, hence the exception. Why doesn't constructor chaining do this, and how can I do things differently?










    share|improve this question


























      0












      0








      0


      0






      I have a class Feedforward with a parameterized constructor of a configuration file:



      public Feedforward(String cfg) throws Exception {

      super(cfg);
      String tempstr = "";
      int currNeuronNum = 0;
      int currEdgeNum = 0;
      int currLayerID = 0;
      int count = 0;

      if (!(type).equals("feedforward"))
      throw new Exception("cfgError: specify proper type")
      //more code



      where the super(cfg) calls the constructor of the Network class, where I handle file parsing and storage of universal fields:



      protected Network(String cfgPath) throws IOException, Exception 

      String type;
      String activationFunction;
      double bias;
      /*file reading stuff; checked with print statements and during
      the creation of a Feedforward class, successfully prints
      "feedforward" after reading type from file
      */



      and when I run a test, it throws a NullPointerException. The type variable in Feedforward is not assigned with the value stored in the file at cfgPath/cfg, hence the exception. Why doesn't constructor chaining do this, and how can I do things differently?










      share|improve this question














      I have a class Feedforward with a parameterized constructor of a configuration file:



      public Feedforward(String cfg) throws Exception {

      super(cfg);
      String tempstr = "";
      int currNeuronNum = 0;
      int currEdgeNum = 0;
      int currLayerID = 0;
      int count = 0;

      if (!(type).equals("feedforward"))
      throw new Exception("cfgError: specify proper type")
      //more code



      where the super(cfg) calls the constructor of the Network class, where I handle file parsing and storage of universal fields:



      protected Network(String cfgPath) throws IOException, Exception 

      String type;
      String activationFunction;
      double bias;
      /*file reading stuff; checked with print statements and during
      the creation of a Feedforward class, successfully prints
      "feedforward" after reading type from file
      */



      and when I run a test, it throws a NullPointerException. The type variable in Feedforward is not assigned with the value stored in the file at cfgPath/cfg, hence the exception. Why doesn't constructor chaining do this, and how can I do things differently?







      java object constructor constructor-chaining






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 2:52









      Duncan WDuncan W

      113 bronze badges




      113 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0














          Because type is local variable of a method (in this case constructor), though Network is a super class but we cannot access a local variable of any method out side it.



          you can make String type=""; as a variable out side constructor , then just assign the value in side Network constructor.



          and you can use it in Feedforward class.



          public class Network 
          String type="";
          protected Network(String cfgPath) throws IOException, Exception

          type=cfgPath;
          String activationFunction=cfgPath;
          double bias;
          /*file reading stuff; checked with print statements and during
          the creation of a Feedforward class, successfully prints
          "feedforward" after reading type from file
          */







          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369079%2fhow-to-let-a-derived-class-in-a-parameterized-constructor-chain-access-fields-of%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Because type is local variable of a method (in this case constructor), though Network is a super class but we cannot access a local variable of any method out side it.



            you can make String type=""; as a variable out side constructor , then just assign the value in side Network constructor.



            and you can use it in Feedforward class.



            public class Network 
            String type="";
            protected Network(String cfgPath) throws IOException, Exception

            type=cfgPath;
            String activationFunction=cfgPath;
            double bias;
            /*file reading stuff; checked with print statements and during
            the creation of a Feedforward class, successfully prints
            "feedforward" after reading type from file
            */







            share|improve this answer





























              0














              Because type is local variable of a method (in this case constructor), though Network is a super class but we cannot access a local variable of any method out side it.



              you can make String type=""; as a variable out side constructor , then just assign the value in side Network constructor.



              and you can use it in Feedforward class.



              public class Network 
              String type="";
              protected Network(String cfgPath) throws IOException, Exception

              type=cfgPath;
              String activationFunction=cfgPath;
              double bias;
              /*file reading stuff; checked with print statements and during
              the creation of a Feedforward class, successfully prints
              "feedforward" after reading type from file
              */







              share|improve this answer



























                0












                0








                0







                Because type is local variable of a method (in this case constructor), though Network is a super class but we cannot access a local variable of any method out side it.



                you can make String type=""; as a variable out side constructor , then just assign the value in side Network constructor.



                and you can use it in Feedforward class.



                public class Network 
                String type="";
                protected Network(String cfgPath) throws IOException, Exception

                type=cfgPath;
                String activationFunction=cfgPath;
                double bias;
                /*file reading stuff; checked with print statements and during
                the creation of a Feedforward class, successfully prints
                "feedforward" after reading type from file
                */







                share|improve this answer













                Because type is local variable of a method (in this case constructor), though Network is a super class but we cannot access a local variable of any method out side it.



                you can make String type=""; as a variable out side constructor , then just assign the value in side Network constructor.



                and you can use it in Feedforward class.



                public class Network 
                String type="";
                protected Network(String cfgPath) throws IOException, Exception

                type=cfgPath;
                String activationFunction=cfgPath;
                double bias;
                /*file reading stuff; checked with print statements and during
                the creation of a Feedforward class, successfully prints
                "feedforward" after reading type from file
                */








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 3:33









                purvaBpurvaB

                494 bronze badges




                494 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369079%2fhow-to-let-a-derived-class-in-a-parameterized-constructor-chain-access-fields-of%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현