No suitable constructor found for ClassUser(no arguments)












0















I'm new to Java and I'm trying to get my head around inheritance.



The error is no suitable constructor found for ClassUser(no arguments) appears at public ClassAdmin(String data) and I haven't found any solutions of help to me.



This is my a snippet of my ClassUser:



public class ClassUser {

public String id;
public String password;
public String name;
public String address;
public String contact;
public String role;


public ClassUser(String id, String password, String name, String address, String contact, String role){

this.id = id;
this.password = password;
this.name = name;
this.address = address;
this.contact = contact;
this.role = role;
}

public ClassUser(String data){
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.address = dataArray[3];
this.contact = dataArray[4];
this.role = dataArray[5];
}


This is a snippet of my ClassAdmin:



public class ClassAdmin extends ClassUser{

public String email;

public ClassAdmin(String id, String password, String name, String contact,
String email)
{
super(id+password+name+contact);
this.email = email;
}
public ClassAdmin(String data){ //problem
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.contact = dataArray[3];
this.email = dataArray[4];
}









share|improve this question

























  • Please call super constructor first in "public ClassAdmin(String data){"

    – Raheela Aslam
    Nov 22 '18 at 11:46


















0















I'm new to Java and I'm trying to get my head around inheritance.



The error is no suitable constructor found for ClassUser(no arguments) appears at public ClassAdmin(String data) and I haven't found any solutions of help to me.



This is my a snippet of my ClassUser:



public class ClassUser {

public String id;
public String password;
public String name;
public String address;
public String contact;
public String role;


public ClassUser(String id, String password, String name, String address, String contact, String role){

this.id = id;
this.password = password;
this.name = name;
this.address = address;
this.contact = contact;
this.role = role;
}

public ClassUser(String data){
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.address = dataArray[3];
this.contact = dataArray[4];
this.role = dataArray[5];
}


This is a snippet of my ClassAdmin:



public class ClassAdmin extends ClassUser{

public String email;

public ClassAdmin(String id, String password, String name, String contact,
String email)
{
super(id+password+name+contact);
this.email = email;
}
public ClassAdmin(String data){ //problem
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.contact = dataArray[3];
this.email = dataArray[4];
}









share|improve this question

























  • Please call super constructor first in "public ClassAdmin(String data){"

    – Raheela Aslam
    Nov 22 '18 at 11:46
















0












0








0








I'm new to Java and I'm trying to get my head around inheritance.



The error is no suitable constructor found for ClassUser(no arguments) appears at public ClassAdmin(String data) and I haven't found any solutions of help to me.



This is my a snippet of my ClassUser:



public class ClassUser {

public String id;
public String password;
public String name;
public String address;
public String contact;
public String role;


public ClassUser(String id, String password, String name, String address, String contact, String role){

this.id = id;
this.password = password;
this.name = name;
this.address = address;
this.contact = contact;
this.role = role;
}

public ClassUser(String data){
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.address = dataArray[3];
this.contact = dataArray[4];
this.role = dataArray[5];
}


This is a snippet of my ClassAdmin:



public class ClassAdmin extends ClassUser{

public String email;

public ClassAdmin(String id, String password, String name, String contact,
String email)
{
super(id+password+name+contact);
this.email = email;
}
public ClassAdmin(String data){ //problem
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.contact = dataArray[3];
this.email = dataArray[4];
}









share|improve this question
















I'm new to Java and I'm trying to get my head around inheritance.



The error is no suitable constructor found for ClassUser(no arguments) appears at public ClassAdmin(String data) and I haven't found any solutions of help to me.



This is my a snippet of my ClassUser:



public class ClassUser {

public String id;
public String password;
public String name;
public String address;
public String contact;
public String role;


public ClassUser(String id, String password, String name, String address, String contact, String role){

this.id = id;
this.password = password;
this.name = name;
this.address = address;
this.contact = contact;
this.role = role;
}

public ClassUser(String data){
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.address = dataArray[3];
this.contact = dataArray[4];
this.role = dataArray[5];
}


This is a snippet of my ClassAdmin:



public class ClassAdmin extends ClassUser{

public String email;

public ClassAdmin(String id, String password, String name, String contact,
String email)
{
super(id+password+name+contact);
this.email = email;
}
public ClassAdmin(String data){ //problem
String dataArray = data.split(",");
this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.contact = dataArray[3];
this.email = dataArray[4];
}






java inheritance netbeans






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 12:22









Aleksandr Podkutin

2,10711325




2,10711325










asked Nov 22 '18 at 11:45









bk23bk23

103




103













  • Please call super constructor first in "public ClassAdmin(String data){"

    – Raheela Aslam
    Nov 22 '18 at 11:46





















  • Please call super constructor first in "public ClassAdmin(String data){"

    – Raheela Aslam
    Nov 22 '18 at 11:46



















Please call super constructor first in "public ClassAdmin(String data){"

– Raheela Aslam
Nov 22 '18 at 11:46







Please call super constructor first in "public ClassAdmin(String data){"

– Raheela Aslam
Nov 22 '18 at 11:46














5 Answers
5






active

oldest

votes


















1














You need to call supper constructor into :



public class ClassAdmin extends ClassUser {

public String email;

public ClassAdmin(String id, String password, String name, String contact,
String email) {
super(id + password + name + contact);
this.email = email;
}

public ClassAdmin(String data) { //problem
super(data);
String dataArray = data.split(",");

this.id = dataArray[0];
this.password = dataArray[1];
this.name = dataArray[2];
this.contact = dataArray[3];
this.email = dataArray[4];
}
}





share|improve this answer































    0














    Since there is no default constructor present in ClassUser but parameterised constructor present, so while extending the ClassUser you should call



    ClassUser(data)


    or



    ClassUser(String id, String password, String name, String address, String contact, String role)


    using super super- java docs



    super(data)


    or



    super(id, password, name, address, contact, role)





    share|improve this answer































      0














      You didn't call super() explicitly in the second ClassAdmin constructor so the compiler add super() call without any parameters. You don't have parameterless ClassUser constructor so you are getting the error.



      Add explicit super call



      public ClassAdmin(String data) {
      super(data.split(",")[0] + data.split(",")[1] + data.split(",")[2] + data.split(",")[3]);
      //...
      }


      Or use private ClassAdmin constructor to avoid repeating use of data.split(",") (still two uses though)



      public ClassAdmin(String data) {
      this(data.split(","));
      //...
      }

      private ClassAdmin(String dataArray) {
      super(dataArray[0] + dataArray[1] + dataArray[2] + dataArray[3]);
      }


      Or create parameterless ClassUser constructor



      public ClassUser() { }





      share|improve this answer


























      • @Eran sure, fixed.

        – Guy
        Nov 22 '18 at 11:55



















      0














      You need to add invokes of the parent constructor super(data); to the public ClassAdmin(String data) constructor as well.



      Because if you don't call parent constructor, you can't create child object. First of all, parent object need to be created. And only after that instantiation of the child object can be executed.



      The main reason of the error is that, if you're not providing, explicitly, invocation of the super class constructor, Java compiler tries to find default super class constructor with no argument and in your case there is no default no argument constructor in the ClassUser class.



      You can fix in a two ways:





      • by adding default constructor to the ClassUser:



        public ClassUser() {
        //some additional logic
        }



      • by adding call of the super class constructor:



        public ClassAdmin(String data) {
        super(data);
        String dataArray = data.split(",");
        this.id = dataArray[0];
        this.password = dataArray[1];
        this.name = dataArray[2];
        this.contact = dataArray[3];
        this.email = dataArray[4];
        }



      It depends on your implementation, but be aware that after you will have called super class constructor, you will have overridden some of the properties in your ClassAdmin constructor.






      share|improve this answer

































        0














        This is how it works. When you create an instance of Child Class, you need to instantiate member variables of parent/super class as well. If you have a default constructor in Super class then those member variables gets initialized to their default values. If you don't have a default constructor you will have to make a call to parameterized constructor to initialize them. That is why you require a call to super(date) in your ClassAdmin constructor.



        Also you don't have to initialize super class member variables like id,password,name etc. in ClassAdmnin constructor. Once you add a super(data) call in this constructor, the member variables of parent class will get initialized in parent class constructor itself.



        Moreover your current code will throw NullPointerException as you are getting value from an array based on index without checking the size of array. If you see first constructor of ClassAdmin there is no comma (,) in the string which you are sending to Super class constructor. You can append it like super(id+ "," +password+ "," +name + ","+contact)






        public ClassAdmin(String data){
        super(data); // Add this line and it should fix the problem.
        String dataArray = data.split(",");
        this.id = dataArray[0];
        this.password = dataArray[1];
        this.name = dataArray[2];
        this.contact = dataArray[3];
        this.email = dataArray[4];
        }








        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%2f53430296%2fno-suitable-constructor-found-for-classuserno-arguments%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You need to call supper constructor into :



          public class ClassAdmin extends ClassUser {

          public String email;

          public ClassAdmin(String id, String password, String name, String contact,
          String email) {
          super(id + password + name + contact);
          this.email = email;
          }

          public ClassAdmin(String data) { //problem
          super(data);
          String dataArray = data.split(",");

          this.id = dataArray[0];
          this.password = dataArray[1];
          this.name = dataArray[2];
          this.contact = dataArray[3];
          this.email = dataArray[4];
          }
          }





          share|improve this answer




























            1














            You need to call supper constructor into :



            public class ClassAdmin extends ClassUser {

            public String email;

            public ClassAdmin(String id, String password, String name, String contact,
            String email) {
            super(id + password + name + contact);
            this.email = email;
            }

            public ClassAdmin(String data) { //problem
            super(data);
            String dataArray = data.split(",");

            this.id = dataArray[0];
            this.password = dataArray[1];
            this.name = dataArray[2];
            this.contact = dataArray[3];
            this.email = dataArray[4];
            }
            }





            share|improve this answer


























              1












              1








              1







              You need to call supper constructor into :



              public class ClassAdmin extends ClassUser {

              public String email;

              public ClassAdmin(String id, String password, String name, String contact,
              String email) {
              super(id + password + name + contact);
              this.email = email;
              }

              public ClassAdmin(String data) { //problem
              super(data);
              String dataArray = data.split(",");

              this.id = dataArray[0];
              this.password = dataArray[1];
              this.name = dataArray[2];
              this.contact = dataArray[3];
              this.email = dataArray[4];
              }
              }





              share|improve this answer













              You need to call supper constructor into :



              public class ClassAdmin extends ClassUser {

              public String email;

              public ClassAdmin(String id, String password, String name, String contact,
              String email) {
              super(id + password + name + contact);
              this.email = email;
              }

              public ClassAdmin(String data) { //problem
              super(data);
              String dataArray = data.split(",");

              this.id = dataArray[0];
              this.password = dataArray[1];
              this.name = dataArray[2];
              this.contact = dataArray[3];
              this.email = dataArray[4];
              }
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 22 '18 at 11:58









              Raheela AslamRaheela Aslam

              36211




              36211

























                  0














                  Since there is no default constructor present in ClassUser but parameterised constructor present, so while extending the ClassUser you should call



                  ClassUser(data)


                  or



                  ClassUser(String id, String password, String name, String address, String contact, String role)


                  using super super- java docs



                  super(data)


                  or



                  super(id, password, name, address, contact, role)





                  share|improve this answer




























                    0














                    Since there is no default constructor present in ClassUser but parameterised constructor present, so while extending the ClassUser you should call



                    ClassUser(data)


                    or



                    ClassUser(String id, String password, String name, String address, String contact, String role)


                    using super super- java docs



                    super(data)


                    or



                    super(id, password, name, address, contact, role)





                    share|improve this answer


























                      0












                      0








                      0







                      Since there is no default constructor present in ClassUser but parameterised constructor present, so while extending the ClassUser you should call



                      ClassUser(data)


                      or



                      ClassUser(String id, String password, String name, String address, String contact, String role)


                      using super super- java docs



                      super(data)


                      or



                      super(id, password, name, address, contact, role)





                      share|improve this answer













                      Since there is no default constructor present in ClassUser but parameterised constructor present, so while extending the ClassUser you should call



                      ClassUser(data)


                      or



                      ClassUser(String id, String password, String name, String address, String contact, String role)


                      using super super- java docs



                      super(data)


                      or



                      super(id, password, name, address, contact, role)






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 22 '18 at 11:55









                      secret super starsecret super star

                      975114




                      975114























                          0














                          You didn't call super() explicitly in the second ClassAdmin constructor so the compiler add super() call without any parameters. You don't have parameterless ClassUser constructor so you are getting the error.



                          Add explicit super call



                          public ClassAdmin(String data) {
                          super(data.split(",")[0] + data.split(",")[1] + data.split(",")[2] + data.split(",")[3]);
                          //...
                          }


                          Or use private ClassAdmin constructor to avoid repeating use of data.split(",") (still two uses though)



                          public ClassAdmin(String data) {
                          this(data.split(","));
                          //...
                          }

                          private ClassAdmin(String dataArray) {
                          super(dataArray[0] + dataArray[1] + dataArray[2] + dataArray[3]);
                          }


                          Or create parameterless ClassUser constructor



                          public ClassUser() { }





                          share|improve this answer


























                          • @Eran sure, fixed.

                            – Guy
                            Nov 22 '18 at 11:55
















                          0














                          You didn't call super() explicitly in the second ClassAdmin constructor so the compiler add super() call without any parameters. You don't have parameterless ClassUser constructor so you are getting the error.



                          Add explicit super call



                          public ClassAdmin(String data) {
                          super(data.split(",")[0] + data.split(",")[1] + data.split(",")[2] + data.split(",")[3]);
                          //...
                          }


                          Or use private ClassAdmin constructor to avoid repeating use of data.split(",") (still two uses though)



                          public ClassAdmin(String data) {
                          this(data.split(","));
                          //...
                          }

                          private ClassAdmin(String dataArray) {
                          super(dataArray[0] + dataArray[1] + dataArray[2] + dataArray[3]);
                          }


                          Or create parameterless ClassUser constructor



                          public ClassUser() { }





                          share|improve this answer


























                          • @Eran sure, fixed.

                            – Guy
                            Nov 22 '18 at 11:55














                          0












                          0








                          0







                          You didn't call super() explicitly in the second ClassAdmin constructor so the compiler add super() call without any parameters. You don't have parameterless ClassUser constructor so you are getting the error.



                          Add explicit super call



                          public ClassAdmin(String data) {
                          super(data.split(",")[0] + data.split(",")[1] + data.split(",")[2] + data.split(",")[3]);
                          //...
                          }


                          Or use private ClassAdmin constructor to avoid repeating use of data.split(",") (still two uses though)



                          public ClassAdmin(String data) {
                          this(data.split(","));
                          //...
                          }

                          private ClassAdmin(String dataArray) {
                          super(dataArray[0] + dataArray[1] + dataArray[2] + dataArray[3]);
                          }


                          Or create parameterless ClassUser constructor



                          public ClassUser() { }





                          share|improve this answer















                          You didn't call super() explicitly in the second ClassAdmin constructor so the compiler add super() call without any parameters. You don't have parameterless ClassUser constructor so you are getting the error.



                          Add explicit super call



                          public ClassAdmin(String data) {
                          super(data.split(",")[0] + data.split(",")[1] + data.split(",")[2] + data.split(",")[3]);
                          //...
                          }


                          Or use private ClassAdmin constructor to avoid repeating use of data.split(",") (still two uses though)



                          public ClassAdmin(String data) {
                          this(data.split(","));
                          //...
                          }

                          private ClassAdmin(String dataArray) {
                          super(dataArray[0] + dataArray[1] + dataArray[2] + dataArray[3]);
                          }


                          Or create parameterless ClassUser constructor



                          public ClassUser() { }






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 22 '18 at 12:08

























                          answered Nov 22 '18 at 11:50









                          GuyGuy

                          18.5k72149




                          18.5k72149













                          • @Eran sure, fixed.

                            – Guy
                            Nov 22 '18 at 11:55



















                          • @Eran sure, fixed.

                            – Guy
                            Nov 22 '18 at 11:55

















                          @Eran sure, fixed.

                          – Guy
                          Nov 22 '18 at 11:55





                          @Eran sure, fixed.

                          – Guy
                          Nov 22 '18 at 11:55











                          0














                          You need to add invokes of the parent constructor super(data); to the public ClassAdmin(String data) constructor as well.



                          Because if you don't call parent constructor, you can't create child object. First of all, parent object need to be created. And only after that instantiation of the child object can be executed.



                          The main reason of the error is that, if you're not providing, explicitly, invocation of the super class constructor, Java compiler tries to find default super class constructor with no argument and in your case there is no default no argument constructor in the ClassUser class.



                          You can fix in a two ways:





                          • by adding default constructor to the ClassUser:



                            public ClassUser() {
                            //some additional logic
                            }



                          • by adding call of the super class constructor:



                            public ClassAdmin(String data) {
                            super(data);
                            String dataArray = data.split(",");
                            this.id = dataArray[0];
                            this.password = dataArray[1];
                            this.name = dataArray[2];
                            this.contact = dataArray[3];
                            this.email = dataArray[4];
                            }



                          It depends on your implementation, but be aware that after you will have called super class constructor, you will have overridden some of the properties in your ClassAdmin constructor.






                          share|improve this answer






























                            0














                            You need to add invokes of the parent constructor super(data); to the public ClassAdmin(String data) constructor as well.



                            Because if you don't call parent constructor, you can't create child object. First of all, parent object need to be created. And only after that instantiation of the child object can be executed.



                            The main reason of the error is that, if you're not providing, explicitly, invocation of the super class constructor, Java compiler tries to find default super class constructor with no argument and in your case there is no default no argument constructor in the ClassUser class.



                            You can fix in a two ways:





                            • by adding default constructor to the ClassUser:



                              public ClassUser() {
                              //some additional logic
                              }



                            • by adding call of the super class constructor:



                              public ClassAdmin(String data) {
                              super(data);
                              String dataArray = data.split(",");
                              this.id = dataArray[0];
                              this.password = dataArray[1];
                              this.name = dataArray[2];
                              this.contact = dataArray[3];
                              this.email = dataArray[4];
                              }



                            It depends on your implementation, but be aware that after you will have called super class constructor, you will have overridden some of the properties in your ClassAdmin constructor.






                            share|improve this answer




























                              0












                              0








                              0







                              You need to add invokes of the parent constructor super(data); to the public ClassAdmin(String data) constructor as well.



                              Because if you don't call parent constructor, you can't create child object. First of all, parent object need to be created. And only after that instantiation of the child object can be executed.



                              The main reason of the error is that, if you're not providing, explicitly, invocation of the super class constructor, Java compiler tries to find default super class constructor with no argument and in your case there is no default no argument constructor in the ClassUser class.



                              You can fix in a two ways:





                              • by adding default constructor to the ClassUser:



                                public ClassUser() {
                                //some additional logic
                                }



                              • by adding call of the super class constructor:



                                public ClassAdmin(String data) {
                                super(data);
                                String dataArray = data.split(",");
                                this.id = dataArray[0];
                                this.password = dataArray[1];
                                this.name = dataArray[2];
                                this.contact = dataArray[3];
                                this.email = dataArray[4];
                                }



                              It depends on your implementation, but be aware that after you will have called super class constructor, you will have overridden some of the properties in your ClassAdmin constructor.






                              share|improve this answer















                              You need to add invokes of the parent constructor super(data); to the public ClassAdmin(String data) constructor as well.



                              Because if you don't call parent constructor, you can't create child object. First of all, parent object need to be created. And only after that instantiation of the child object can be executed.



                              The main reason of the error is that, if you're not providing, explicitly, invocation of the super class constructor, Java compiler tries to find default super class constructor with no argument and in your case there is no default no argument constructor in the ClassUser class.



                              You can fix in a two ways:





                              • by adding default constructor to the ClassUser:



                                public ClassUser() {
                                //some additional logic
                                }



                              • by adding call of the super class constructor:



                                public ClassAdmin(String data) {
                                super(data);
                                String dataArray = data.split(",");
                                this.id = dataArray[0];
                                this.password = dataArray[1];
                                this.name = dataArray[2];
                                this.contact = dataArray[3];
                                this.email = dataArray[4];
                                }



                              It depends on your implementation, but be aware that after you will have called super class constructor, you will have overridden some of the properties in your ClassAdmin constructor.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 22 '18 at 12:20

























                              answered Nov 22 '18 at 11:50









                              Aleksandr PodkutinAleksandr Podkutin

                              2,10711325




                              2,10711325























                                  0














                                  This is how it works. When you create an instance of Child Class, you need to instantiate member variables of parent/super class as well. If you have a default constructor in Super class then those member variables gets initialized to their default values. If you don't have a default constructor you will have to make a call to parameterized constructor to initialize them. That is why you require a call to super(date) in your ClassAdmin constructor.



                                  Also you don't have to initialize super class member variables like id,password,name etc. in ClassAdmnin constructor. Once you add a super(data) call in this constructor, the member variables of parent class will get initialized in parent class constructor itself.



                                  Moreover your current code will throw NullPointerException as you are getting value from an array based on index without checking the size of array. If you see first constructor of ClassAdmin there is no comma (,) in the string which you are sending to Super class constructor. You can append it like super(id+ "," +password+ "," +name + ","+contact)






                                  public ClassAdmin(String data){
                                  super(data); // Add this line and it should fix the problem.
                                  String dataArray = data.split(",");
                                  this.id = dataArray[0];
                                  this.password = dataArray[1];
                                  this.name = dataArray[2];
                                  this.contact = dataArray[3];
                                  this.email = dataArray[4];
                                  }








                                  share|improve this answer






























                                    0














                                    This is how it works. When you create an instance of Child Class, you need to instantiate member variables of parent/super class as well. If you have a default constructor in Super class then those member variables gets initialized to their default values. If you don't have a default constructor you will have to make a call to parameterized constructor to initialize them. That is why you require a call to super(date) in your ClassAdmin constructor.



                                    Also you don't have to initialize super class member variables like id,password,name etc. in ClassAdmnin constructor. Once you add a super(data) call in this constructor, the member variables of parent class will get initialized in parent class constructor itself.



                                    Moreover your current code will throw NullPointerException as you are getting value from an array based on index without checking the size of array. If you see first constructor of ClassAdmin there is no comma (,) in the string which you are sending to Super class constructor. You can append it like super(id+ "," +password+ "," +name + ","+contact)






                                    public ClassAdmin(String data){
                                    super(data); // Add this line and it should fix the problem.
                                    String dataArray = data.split(",");
                                    this.id = dataArray[0];
                                    this.password = dataArray[1];
                                    this.name = dataArray[2];
                                    this.contact = dataArray[3];
                                    this.email = dataArray[4];
                                    }








                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      This is how it works. When you create an instance of Child Class, you need to instantiate member variables of parent/super class as well. If you have a default constructor in Super class then those member variables gets initialized to their default values. If you don't have a default constructor you will have to make a call to parameterized constructor to initialize them. That is why you require a call to super(date) in your ClassAdmin constructor.



                                      Also you don't have to initialize super class member variables like id,password,name etc. in ClassAdmnin constructor. Once you add a super(data) call in this constructor, the member variables of parent class will get initialized in parent class constructor itself.



                                      Moreover your current code will throw NullPointerException as you are getting value from an array based on index without checking the size of array. If you see first constructor of ClassAdmin there is no comma (,) in the string which you are sending to Super class constructor. You can append it like super(id+ "," +password+ "," +name + ","+contact)






                                      public ClassAdmin(String data){
                                      super(data); // Add this line and it should fix the problem.
                                      String dataArray = data.split(",");
                                      this.id = dataArray[0];
                                      this.password = dataArray[1];
                                      this.name = dataArray[2];
                                      this.contact = dataArray[3];
                                      this.email = dataArray[4];
                                      }








                                      share|improve this answer















                                      This is how it works. When you create an instance of Child Class, you need to instantiate member variables of parent/super class as well. If you have a default constructor in Super class then those member variables gets initialized to their default values. If you don't have a default constructor you will have to make a call to parameterized constructor to initialize them. That is why you require a call to super(date) in your ClassAdmin constructor.



                                      Also you don't have to initialize super class member variables like id,password,name etc. in ClassAdmnin constructor. Once you add a super(data) call in this constructor, the member variables of parent class will get initialized in parent class constructor itself.



                                      Moreover your current code will throw NullPointerException as you are getting value from an array based on index without checking the size of array. If you see first constructor of ClassAdmin there is no comma (,) in the string which you are sending to Super class constructor. You can append it like super(id+ "," +password+ "," +name + ","+contact)






                                      public ClassAdmin(String data){
                                      super(data); // Add this line and it should fix the problem.
                                      String dataArray = data.split(",");
                                      this.id = dataArray[0];
                                      this.password = dataArray[1];
                                      this.name = dataArray[2];
                                      this.contact = dataArray[3];
                                      this.email = dataArray[4];
                                      }








                                      public ClassAdmin(String data){
                                      super(data); // Add this line and it should fix the problem.
                                      String dataArray = data.split(",");
                                      this.id = dataArray[0];
                                      this.password = dataArray[1];
                                      this.name = dataArray[2];
                                      this.contact = dataArray[3];
                                      this.email = dataArray[4];
                                      }





                                      public ClassAdmin(String data){
                                      super(data); // Add this line and it should fix the problem.
                                      String dataArray = data.split(",");
                                      this.id = dataArray[0];
                                      this.password = dataArray[1];
                                      this.name = dataArray[2];
                                      this.contact = dataArray[3];
                                      this.email = dataArray[4];
                                      }






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Nov 22 '18 at 12:26

























                                      answered Nov 22 '18 at 12:15









                                      vinay khuranavinay khurana

                                      763




                                      763






























                                          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%2f53430296%2fno-suitable-constructor-found-for-classuserno-arguments%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

                                          Create new schema in PostgreSQL using DBeaver

                                          Deepest pit of an array with Javascript: test on Codility

                                          Costa Masnaga