-3
public class Gonderi {                                      
    int kullaniciId;                                        
    int gonderiId;                                          

    public void Gonderi(int kullaniciId, int gonderiId) {
        super();
        this.kullaniciId = kullaniciId;
        this.gonderiId = gonderiId;
    }

...

This is a part of my code. Compiler gives an error as "Call to super must be first statement in constructor". But super() is already the first statement at the constructor. How can i solve this problem? Thanks.

Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
Taha Sümer
  • 25
  • 11
  • 5
    That's not a constructor. – tnw Jul 22 '16 at 16:25
  • @tnw what kind of things are constructor? – Taha Sümer Jul 22 '16 at 16:34
  • 5
    @user6551379 Please just ask the almighty Google. This is covered in virtually every introductory tutorial ever for java. If you cannot be bothered to make some attempt research and help yourself, you are going to have a very hard time learning this stuff. – tnw Jul 22 '16 at 17:01
  • Hint: don't engage on Android ... when you have absolutely no clue on Java. Seriously: Android is somehow an "advanced" topic, but understanding what constructors are, how to use them, and why they are different to ordinary methods is **absolutely** basic stuff. Meaning: please step back, and consider learning those basic things first. I guarantee you: if you don't do that, your "Android" experience will be rather frustrating; and probably end soon; because you are hitting "strange" problems no matter what you do. – GhostCat Jul 22 '16 at 17:03
  • @tnw in fact u r mostly right, but wrong about my attempt of research. I just searched about this error and whoever answers they are all telling " thats not a constructer " to askers. So i couldnt get my answer from anywhere so i asked my question myself. Then u answered like that and i was too tired of that kind of answers so i asked what is a constructor with tiredness and without expecting for an answer. So u r right about if someone cant be bothered to search it cant success. But i am not that ones, just was tired and bored – Taha Sümer Jul 22 '16 at 18:15
  • @user6551379 That sounds like just a bunch of excuses to me. This is *very* basic java. You should pick up an introductory tutorial (as I said) if you do not understand what a constructor is or how to write one. – tnw Jul 22 '16 at 18:32

2 Answers2

4

Constructors don't have return value, but you have it (void):

public void Gonderi(int kullaniciId, int gonderiId) {

So remove void and have a proper constructor:

public Gonderi(int kullaniciId, int gonderiId) {

After such change it will be legal to call super() there.

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • it worked, thank you! But doesn't putting nothing like "void", "int" etc. mean that function or method is "void"? – Taha Sümer Jul 22 '16 at 16:32
  • 1
    Please make a minimal effort to find a duplicate before attempting an answer. This question gets asked daily. Either vote to close as a duplicate or as a typo (unintentionally written). – Savior Jul 22 '16 at 16:33
  • 1
    No `void` is used only in methods, constructors have a specific syntax that doesn't allow any return value. – Krzysztof Krasoń Jul 22 '16 at 16:33
2

Remove the void, the one you have mentioned above is not a constructor. It is a function. The constructor should be as below

  public Gonderi(int kullaniciId, int gonderiId) {
   super();
   this.kullaniciId = kullaniciId;
   this.gonderiId = gonderiId;
  }
SamB
  • 1,560
  • 1
  • 13
  • 19