1
import java.io.*;

class Main0
{
    public static void main(String args[])
    {
        String onoma, epitheto, key01;
        short AriMit, EtosEis, AM, key02;
        int i, pos;
        Foititis pinakas[] = new Foititis(3);
        for (i = 0; i < pinakas.length; i++)
        {       
            System.out.println("Ola ta stoixeia na einai taksinomimena symfwna me ton Arithmo Mitroou." + "\n" + "Dwste Onoma.");
            do
            {
                onoma = FUserInput.getString();
                if (onoma == "x")
                    System.out.println("Mh egkyrh timh. Epanalagete");
            } while (onoma == "x");

            System.out.println("Dwste Epitheto.");
            do
            {
                epitheto = FUserInput.getString();
                if (epitheto == "x")
                    System.out.println("Mh egkyrh timh. Epanalagete");
            } while (epitheto == "x");

            System.out.println("Dwste Arithmo Mitrwou.");
            do
            {
                AriMit = FUserInput.getshort();
                if (AriMit == -1)
                    System.out.println("Mh egkyrh timh. Epanalagete");
            } while (AriMit == -1);

            System.out.println("Dwste Etos Eisagwghs.");
            do
            {
                EtosEis = FUserInput.getshort();
                if (EtosEis == -1)
                    System.out.println("Mh egkyrh timh. Epanalagete");
            } while (EtosEis == -1);

            pinakas[i] = new Foititis(onoma, epitheto, AriMit, EtosEis);
        }
        pos = 1;
        System.out.println(Foititis.toString(pos, pinakas));
    }
}

class Foititis      
{
    private String onoma, epitheto;
    private short AriMit, EtosEis;

    public Foititis (String on, String ep, short AM, short EE)
    {
        onoma = on;
        epitheto = ep;
        AriMit = AM;
        EtosEis = EE;
    }

    public String getEpwnymo()      //alles klaseis
    {
        return epitheto;
    }

    public String toString(int j, Foititis b[])
    {
        String emf;
        emf = b[j].onoma;
    }
}

class FUserInput        
 /*dedomenwn kateli3a na xrisimopoihsw thn "FUserInput" gia ola ta dedomena, anti na kanw "catch" to "exception" gia kathe scanner ksexwrista, kathws eixa skopo na xrisimopoihsw mono scanner)*/
{
    static String getString() 
    { 
        String line;
        InputStreamReader eisodosDouble = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(eisodosDouble);
        try
        {
            line = br.readLine();
            return line;
        }
        catch(Exception e) 
        {   
            return "x";
        }
    }

    static short getshort() 
    { 
        String line;
        InputStreamReader eisodosDouble = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(eisodosDouble);
        try
        {
            line = br.readLine();
            short i = Short.parseShort(line);
            return i;
        }
        catch(Exception e) 
        {   
            return -1;
        }
    }
}

This is not a duplicate of anything, I am not asking about my string equations but about the toString method that I want to use!!!!

So I have this code... all it does is to create an array of objects of type Foititis, named pinakas and having the four attributes. If you look at class named Foititis you will notice a toString method, all I want to do is to use the toString method to show something on the screen (at this example it is simplified to the onoma attribute of the array-object). Note that I also want to send the certain position of the array that I want to be seen(pos -> j), at this example the position is fixed (set to 1) but in the actual code it won't.

I try to compile it and I get these 2 errors, the second one is probably justified because I haven't written the code in the proper way, but what about the first? I have done the same thing again and I had no problem (at creating an array of objects).

The error

Moses 7D
  • 39
  • 5
  • Also http://stackoverflow.com/questions/4969171/cannot-make-static-reference-to-non-static-method – fabian Mar 03 '16 at 14:50
  • @MarounMaroun Even though his `== "x"` in his if's and while's should be replaced with `.equals("x")`, it isn't what he was asking in his question. In his error that he linked at the bottom he has a problem with his array (see answer below by @mikea), and he has a problem with a static call on a non-static method (the `System.out.println(Foititis.toString(pos, pinakas));` should be relaced with `System.out.println(pinakas[pos].toString());` and the `toString` method in `Foititis` should be replaced with `public String toString(){ return onoma; }` – Kevin Cruijssen Mar 03 '16 at 15:02
  • @KevinCruijssen Thank you very much! IT WORKED! and – Moses 7D Mar 03 '16 at 16:47

1 Answers1

1

You are trying to declare an array, so it should be:

Foititis pinakas[] = new Foititis[3];
mikea
  • 6,537
  • 19
  • 36