Error "illegal start of Expression"

Asked

Viewed 734 times

4

In my main I’m calling the method stats:

user.stats(ctr);

The method stats in itself:

public void stats (int num)
{
    int i;
    float total=0, perc;
    for (i=0;i<num;i++)
    {
        total = total + sensors[i].statistics.getTotalConsumption(sensors[i].statistics.data[]);
    }
}

The class users:

public class Users implements IUsers{
protected int id;
protected String name;
protected int age;
protected String email;
protected String phone;
protected Sensors sensors[] = new Sensors[10];
float cost;
float goal;

public Users()
{

}

public void stats (int num)
{
    int i;
    float total=0, perc;
    for (i=0;i<num;i++)
    {
        total = total + sensors[i].statistics.getTotalConsumption(sensors[i].statistics.data[]);
    }
}
}

The main:

public class UserTest 
{ 
public static void main ( String args[] )
{
    int id, rg, cpf, cnpj, num, age, ctr=0;
    String name, name2, description, description2, email, phone, c, g, sex;
    Sensors sensors[];
    float cost, goal;


    Users user = new Users();
    while (ctr!=num)
    {
        user.sensors[ctr] = new Sensors();
        name2 = JOptionPane.showInputDialog("Nome do aparelho ligado ao sensor");
        description = JOptionPane.showInputDialog ("Localização do aparelho");
        user.sensors[ctr].setNome(name2);
        user.sensors[ctr].setDescription(description);
        ctr++;
    }
    /*exibir estatísticas*/
    user.stats(ctr);
}
}

But both in the method call and in the assignment of the total variable, is giving the error illegal start of expression. If anyone can help I’m grateful.

  • Where and how the declaration of sensors?

  • 1

    See if you’re using the words public or private within one method or if you are declaring one method within another.

  • protected Sensors Sensors[] = new Sensors[10];

  • This statement is being made where? Check my second comment.

  • this statement is within the Users class, as well as the Stats method

  • 1

    post your main and the class that contains the Stats method so that it is better to identify what is happening.

  • ready, updated

  • was just a glitch in copying time

Show 3 more comments

1 answer

3


The error lies in your method stats

public void stats (int num)
{
    int i;
    float total=0, perc;
    for (i=0;i<num;i++)
    {
        total = total + sensors[i].statistics.getTotalConsumption(sensors[i].statistics.data[]);  //<--- não estás a indexar o array data[faltaAquiUmIndice]. Ou data não é um array
    }
}
  • 1

    That’s right! Thanks, man.

  • Glad I could help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.