1.11M Members

<identifier> expected error... Help!

 
0
 

Can anybody tell me why I keep getting this error?

Asig02_Attempt2.java:37: <identifier> expected
public void sincronizarCanal(canal)

Am I mixing a class with a method? This is just a small program that simulates a TV. I'm trying to pass a number (chanel) to a method that tells the user that they are now watching chanel (whatever number I passed)...

import java.util.Scanner;

class Televisor
{
	int	canales,
		volumen,
		canal,
		vol;
			
			
	public Televisor()
	{
		canales = 5;
		volumen = 10;
	}
	
	public void encender()
	{
		System.out.println("Televisor Encendido.");
	}
	
	public void apagar()
	{
		System.out.println("Televisor Apagado. Adios...");
	}
	
	public void sincronizarCanal(canal)
	{
	  System.out.println("El canal ha sido sincronizado al canal" + canal);
	}
	
	public void ajustarVolumen()
	{
	  System.out.println("El volumen ha sido ajustado.");
	}
}

public class Asig02_Attempt2
{
	public static void main(String arguments[]) 
	{ 
	             Scanner input = new Scanner( System.in ); 
	
	             Televisor myTVSet = new Televisor();
	
		myTVSet.encender();
	
		System.out.print("Sincronizar al canal --> ");
		myTVSet.canales = input.nextInt();
		myTVSet.sincronizarCanal(myTVSet.canales);
	
		System.out.print("\n");
	
		System.out.print("Ajustar el volumen a --> ");
		myTVSet.volumen = input.nextInt();
		myTVSet.ajustarVolumen();
	
		myTVSet.apagar();
	}
}
 
0
 

You are not telling the compiler what type "canal" is. I am guessing that "canal" is an integer, but you don't specify this:

public void sincronizarCanal(canal)

If canal is an integer, you should change it to this:

public void sincronizarCanal(int canal)

However, this also won't work since you have a data member CALLED "canal". If it is the data member "canal" you are intending here, then don't pass the function anything, like this:

public void sincronizarCanal()

I'm not exactly sure what you are trying to do. It looks like you ARE trying to pass the function something. If so, if it is an integer, which appears to me to be your intent, I would rename it to some other name that is not the name of a data member, and place an "int" in front of that variable name, like this:

public void sincronizarCanal(int someIntegerName)
 
0
 

well, now I feel dumb... :-D I should have known that! Thanks a lot!!

Question Answered as of 6 Years Ago by VernonDozier
 
0
 

I hsve error as identifier expeced error at
"synchronize public void static debit(float ba)" this line plz reply as early as possible

class Demo
{

    Acc a1,a2;
String tot;
    AccU au1,au2;
    public static void main(String args[])  
    {
    a1=new Acc(1000,10000);
    a2=new Acc(50,50000);
    au1=new Acc(a1,"Ganesh","d");
    au1=new Acc(a2,"Vinayak","c");
    }
}
class AccU extends Thread
{
Acc u1;

String name,tot1;
    AccU(Acc u2,String na,String tot2)
    {
        u1=u2;
        name=na;
        tot1=tot2;

    }   


    public void run()
    {
    u1.start();
    u1.join();  
    if(tot1.equals("d"))
    u1.debit(u1.bal);           

    if(tot1.equals("c"))
    u1.crdt(u1.bal);    

    }

}

class Acc
{
    int acno;
    float bal,crbal;

    Acc(int an,float b)
    {
    acno=an;
    bal=b;
    }


    synchronize public void  static debit(float ba)
        {
        System.out.println("Bal before trans="+ba);
        crbal=crbal+ba;
        System.out.println("Bal after trans="+crbal);
        bal=crbal;
        }

    synchronize static public void  static crdt(float ba)
    {
    System.out.println("Bal before trans="+ba);
    crbal=crbal-ba;
    System.out.println("Bal after trans="+crbal);
    bal=crbal;
    }

}
 
0
 

I hsve error as identifier expeced error at
"synchronize public void static debit(float ba)" this line plz reply as early as possible

class Demo
{

    Acc a1,a2;
String tot;
    AccU au1,au2;
    public static void main(String args[])  
    {
    a1=new Acc(1000,10000);
    a2=new Acc(50,50000);
    au1=new Acc(a1,"Ganesh","d");
    au1=new Acc(a2,"Vinayak","c");
    }
}
class AccU extends Thread
{
Acc u1;

String name,tot1;
    AccU(Acc u2,String na,String tot2)
    {
        u1=u2;
        name=na;
        tot1=tot2;

    }   


    public void run()
    {
    u1.start();
    u1.join();  
    if(tot1.equals("d"))
    u1.debit(u1.bal);           

    if(tot1.equals("c"))
    u1.crdt(u1.bal);    

    }

}

class Acc
{
    int acno;
    float bal,crbal;

    Acc(int an,float b)
    {
    acno=an;
    bal=b;
    }


    synchronize public void  static debit(float ba)
        {
        System.out.println("Bal before trans="+ba);
        crbal=crbal+ba;
        System.out.println("Bal after trans="+crbal);
        bal=crbal;
        }

    synchronize static public void  static crdt(float ba)
    {
    System.out.println("Bal before trans="+ba);
    crbal=crbal-ba;
    System.out.println("Bal after trans="+crbal);
    bal=crbal;
    }

} 

end quote.

I think the error is with the order of your declaration:
It is "public static void" . Also I don't believe that you spelled synchronize correctly. Also check some tutorials as where you need to place it when declaring a method

 
0
 

I have a similar problem.. HELP PLEASE... heres my code

//By coolman5659
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;

import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSNPC;

@ScriptManifest(authors = {"coolman5659"}, name = "CowMurderer", version = 1.0, description = "A script that kills Cows in Lumbridge.")
public class CowMurderer extends Script implements PaintListener{

    private static RSNPC Cow = null;

    //Paint
    public long startTime = System.currentTimeMillis();
    public int startexp;

    //Cow/IDs
    public int[]; cowIDs = {12362, 12363, 12364, 12365};

    //Cow/Drop IDs
    public int cowDrops = 1739;

    //AntiBan
    public void cameraAntiBan() {
        int randomTurn = random(1,2);
        final int GambleInt4 = random(1,1000);
        if (GambleInt4 >= 930) {
                switch(randomTurn) {
                    case 1:
                        new CameraRotateThread().start();
                        break;
                    case 2:
                        int randomFormation = random(0,2);
                        if(randomFormation == 0) {
                            new CameraRotateThread().start();
                        } else {
                            new CameraRotateThread().start();
                            new CameraRotateThread().start();
                        }
                }
        }
    }

    public class CameraRotateThread extends Thread {
        @Override
        public void run() {
            char LR = KeyEvent.VK_RIGHT;
            if (random(0, 2) == 0) {
                LR = KeyEvent.VK_LEFT;
            }
            keyboard.pressKey(LR);
            try {
                Thread.sleep(random(450, 2600));
            } catch (final Exception ignored) {
            }
            keyboard.releaseKey(LR);
        }
    }

    public boolean onStart() {  
     startTime = System.currentTimeMillis();
           log("Thanks for choosing CowMurderer!");
           return true;
    }

    public int loop() {
        cameraAntiBan();
        cowkiller();

        RSGroundItem cowDrops = groundItems.getNearest(cowIDs);
        if(cowDrops != null && !inventory.isFull() && getMyPlayer().getInteracting() == null) {
            if(cowDrops.isOnScreen()) {
                cowDrops.doAction("Take");
                sleep(1000,2000);
                while(getMyPlayer().isMoving()){
                    sleep(300,500);
                }
            }
            cameraAntiBan();

            return random(300,400); 
        }   
        return random(300,400); 
    }

    public void cowkiller() {
        Cow = npcs.getNearestFreeToAttack(cowIDs);
        if(Cow != null){
            if(Cow.isOnScreen() && getMyPlayer().getInteracting() == null){
                Cow.doAction("Attack Cow");
                sleep(1000,2000);
            }else if(!Cow.isOnScreen() && getMyPlayer().getInteracting() == null){
                walking.walkTileMM(Cow.getLocation(), 3256, 3282);
                sleep(1000,2000);

            }
        }
    }

public void onRepaint(Graphics g) {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    {
        int xpGained = 0;
        if ( startexp == 0) {
             startexp = skills.getCurrentExp(Skills.STRENGTH);
        }
        xpGained = skills.getCurrentExp(Skills.STRENGTH) - startexp;
        long millis = System.currentTimeMillis() - startTime;
        long hours = millis / (1000 * 60 * 60);
        millis -= hours * (1000 * 60 * 60);
        long minutes = millis / (1000 * 60);
        millis -= minutes * (1000 * 60);
        long seconds = millis / 1000;
        long minutes2 = minutes + (hours * 60);
        g.setColor(Color.red);
        g.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
        g.drawString("Time running: " + hours + ":" + minutes + ":"
                + seconds + "." , 9, 315);
        g.drawString("XP Gained: " + xpGained, 12, 284);
        g.drawString("", 9, 299);
        g.drawString(" " , 9, 327);
    }
}
public void onFinish(){
    log("Again, thanks for choosing CowMurderer!");
}
}
 
0
 

I have a similar problem.. HELP PLEASE... heres my code

//By coolman5659
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;

import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSNPC;

@ScriptManifest(authors = {"coolman5659"}, name = "CowMurderer", version = 1.0, description = "A script that kills Cows in Lumbridge.")
public class CowMurderer extends Script implements PaintListener{

    private static RSNPC Cow = null;

    //Paint
    public long startTime = System.currentTimeMillis();
    public int startexp;

    //Cow/IDs
    public int[]; cowIDs = {12362, 12363, 12364, 12365};

    //Cow/Drop IDs
    public int cowDrops = 1739;

    //AntiBan
    public void cameraAntiBan() {
        int randomTurn = random(1,2);
        final int GambleInt4 = random(1,1000);
        if (GambleInt4 >= 930) {
                switch(randomTurn) {
                    case 1:
                        new CameraRotateThread().start();
                        break;
                    case 2:
                        int randomFormation = random(0,2);
                        if(randomFormation == 0) {
                            new CameraRotateThread().start();
                        } else {
                            new CameraRotateThread().start();
                            new CameraRotateThread().start();
                        }
                }
        }
    }

    public class CameraRotateThread extends Thread {
        @Override
        public void run() {
            char LR = KeyEvent.VK_RIGHT;
            if (random(0, 2) == 0) {
                LR = KeyEvent.VK_LEFT;
            }
            keyboard.pressKey(LR);
            try {
                Thread.sleep(random(450, 2600));
            } catch (final Exception ignored) {
            }
            keyboard.releaseKey(LR);
        }
    }

    public boolean onStart() {  
     startTime = System.currentTimeMillis();
           log("Thanks for choosing CowMurderer!");
           return true;
    }

    public int loop() {
        cameraAntiBan();
        cowkiller();

        RSGroundItem cowDrops = groundItems.getNearest(cowIDs);
        if(cowDrops != null && !inventory.isFull() && getMyPlayer().getInteracting() == null) {
            if(cowDrops.isOnScreen()) {
                cowDrops.doAction("Take");
                sleep(1000,2000);
                while(getMyPlayer().isMoving()){
                    sleep(300,500);
                }
            }
            cameraAntiBan();

            return random(300,400); 
        }   
        return random(300,400); 
    }

    public void cowkiller() {
        Cow = npcs.getNearestFreeToAttack(cowIDs);
        if(Cow != null){
            if(Cow.isOnScreen() && getMyPlayer().getInteracting() == null){
                Cow.doAction("Attack Cow");
                sleep(1000,2000);
            }else if(!Cow.isOnScreen() && getMyPlayer().getInteracting() == null){
                walking.walkTileMM(Cow.getLocation(), 3256, 3282);
                sleep(1000,2000);

            }
        }
    }

public void onRepaint(Graphics g) {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    {
        int xpGained = 0;
        if ( startexp == 0) {
             startexp = skills.getCurrentExp(Skills.STRENGTH);
        }
        xpGained = skills.getCurrentExp(Skills.STRENGTH) - startexp;
        long millis = System.currentTimeMillis() - startTime;
        long hours = millis / (1000 * 60 * 60);
        millis -= hours * (1000 * 60 * 60);
        long minutes = millis / (1000 * 60);
        millis -= minutes * (1000 * 60);
        long seconds = millis / 1000;
        long minutes2 = minutes + (hours * 60);
        g.setColor(Color.red);
        g.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
        g.drawString("Time running: " + hours + ":" + minutes + ":"
                + seconds + "." , 9, 315);
        g.drawString("XP Gained: " + xpGained, 12, 284);
        g.drawString("", 9, 299);
        g.drawString(" " , 9, 327);
    }
}
public void onFinish(){
    log("Again, thanks for choosing CowMurderer!");
}
}

end quote.

Do some studying, start a new thread, use code tags and state what is the error and where are you having it

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article