printf error can't launch java eclipse - java

My printf contains an error. The rest of my code is done, but because of the error in my printf, I can't launch Java. Please help. My main class already done.
package id.web.aditya;
public class Roda {
private int diameter;
private String warna;
private String Merk;
private String Keterangan;
public String getMerk() {
return Merk;
}
public void setMerk(String merk) {
Merk = merk;
}
public int getDiameter() {
return diameter;
}
public void setDiameter(int diameter) {
this.diameter = diameter;
}
public String getWarna() {
return warna;
}
public void setWarna(String warna) {
this.warna = warna;
}
public String getKeterangan() {
return Keterangan;
}
public void setKeterangan(String keterangan) {
this.Keterangan = keterangan;
}
public void tampilanKeterangan(){
System.out.printf("Roda %s Merk: %s Warna: %s Diameter: %d \n ",
Keterangan, Merk, warna, diameter);
}
public void Berhenti(){
tampilanKeterangan();
System.out.println("Kurangi Kecepatan");
System.out.println("mulai berhenti..");
System.out.println("Akhirna berhenti");
System.out.println("--------------------");
}
public void berputar(){
tampilanKeterangan();
System.out.println("mulai berputar");
System.out.println("berputar");
System.out.println("berputar makin cepat");
System.out.println("----------------------");
}
}
package id.web.aditya;
public class Mobil {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Roda rodaUntukDitest = new Roda();
rodaUntukDitest.setDiameter(80);
rodaUntukDitest.setMerk("Achiles");
rodaUntukDitest.setWarna("Hitam");
rodaUntukDitest.setKeterangan("");
rodaUntukDitest.Berhenti();
rodaUntukDitest.berputar();
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation
problem: The method printf(Locale, String, Object[]) in the type
PrintStream is not applicable for the arguments (String, String,
String, String, int)

String format feature is introduced in java 1.5. You are apparently using a java version or a compilation option prior to that version.
If you are using eclipse open the project properties (ALT + Enter on the project). Look at the tab java compiler.
Here you can set your compiler compliance level. You probably have a newer java version installed. In this case eclipse shows you the above mention error.
I would expect to show you something like "The method printf(String, String, String, String, Integer) is undefined for the type PrintStream". but it doesn't so this might be a little bit confusing.

Related

How to pass a Default and Optional Parameter into a function like a python in the Java

I am trying to migrate the python library into the java native script but I facing extreme complexity with the parameters while migration.
Here the code I need to migrate the python method with the default & optional parameters with different datatypes into the java method:
def connect_network(self,
bssid=None,
proto="http",
check_redirect_code=True,
redirect_code='302',
portal_url=None,
subscriber_portal='scg',
expect_href_list_zd_sp='google',
check_user_block=False,
redirect_url='',
tnc_content="",
path="/tmp/"):
pass
Here is my example code which I tried in java equivalent:
public class LinuxClientUtils {
public void DefaultNameParameter1(HashMap<Integer, String> params){
System.out.Println(params.toString());
}
public void DefaultNameParameter2(Map.Entry<String, String>... params){
System.out.Println(params.toString());
}
public void DefaultNameParameter3(Optional<String> name, Optional<String> age){
System.out.Println(name.toString());
}
}
I will import that Java library in the robot framework and call the method like this,
*** Settings ***
Library test.LinuxClientUtils
*** Test Cases ***
Testing
[tags] service
[Documentation] Add Network
Default Name Parameter3 req_network_id=89
Still, None of the methods didn't work.
I have tried few Methods from the following URLs Link-1
Link-2 But I am unable to figure it out from those links.
I'm new to JAVA programming and haven't been able to fix this one. Any help would be great, thanks.
Create a new class for a parameter object. It will have each of the parameters as a field.
The constructor of this parameter class has no parameters. Instead, each field has a default value. (null and false are automatically assigned by default for object and boolean fields, anyway.)
Your function will just take a parameter object as a single parameter.
public class A {
static class ParameterObject {
public ParameterObject(){
//empty
}
private int x;
private boolean b;
private String s;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public boolean isB() {
return b;
}
public void setB(boolean b) {
this.b = b;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
}
public static void f(ParameterObject o){
//Do something with object
}
public static void main(String[] args) {
ParameterObject paramObj=new ParameterObject();
paramObj.setX(10);
f(paramObj);
}
}

How to #link to overridden Enum method in JavaDoc?

Suppose I have an enum structure as follows:
public enum TransportMode {
BYCICLE {
#Override
public double speedFactor() { return .7; }
},
CAR {
#Override
public double speedFactor() { return 1; }
},
TRAIN {
/**
* Faster than train (see also {#link TransportMode#CAR#speedFactor()}).
*/
#Override
public double speedFactor() { return 1.3; }
};
public abstract double speedFactor();
}
When generating Javadoc with maven-source-plugin 3.0.1, I get the following warning:
[WARNING] D:\path\TransportMode.java:000: warning - Tag #see: can't
find CAR#speedFactor() in TransportMode
I get the same result when leaving out the class altogether.
Is this a bug? IntelliJ seems to resolve the path fine.

Bukkit plugin Syntax error, multiple classes

i'm trying to create plugin with multiple classes, but when I type the command in Minecraft, it shows me command syntax error msg (Syntax error! Simply type /ct create.). I think it is silly misstake somewhere, but i can't find it.
My core.java:
public class Core extends JavaPlugin {
public ArrayList<Block> chests = new ArrayList<>();
public boolean createMode = false;
public void onEnabled() {
getCommand("ct").setExecutor(new Commands(this));
getServer().getPluginManager().registerEvents(new Listeners(this), this);
}
}
My Commands.java:
public class Commands implements CommandExecutor {
private Core plugin;
public Commands(Core core) {
this.plugin = core;
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("ct")) {
sender.sendMessage("lol");
if(args.length > 0) {
sender.sendMessage("hi");
if(args[0].equalsIgnoreCase("create")) {
plugin.createMode = true;
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Now rightclick the chest");
}
} else {
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Too few arguments!");
}
}
return false;
}
}
My plugin.yml:
name: ChestTreasure
description: this plugin...
main: me.sudoman281.chestTreasure.Core
version: 1.0
author: sudoman281
commands:
ct:
description: ...
permission: ct.create
usage: Syntax error! Simply type /ct create.
You have to correctly override the method by having the same exact name and method signature/return type. To do this you must do the following:
Your onEnabled method should be onEnable per the Bukkit API
You should always use the #Override annotation to signify that you are overriding a superclass method. (Optional but highly recommended for finding errors and convention. It will work without this)
Your onEnable should look like this:
#Override
public void onEnable() {
/* Do stuff when plugin starts */
}

Error: 'void' type not allowed here [duplicate]

This question already has answers here:
What causes "'void' type not allowed here" error
(7 answers)
Closed 10 months ago.
I'm learning to use classes and part of my assignment is to make this Car class. I'm getting an error on line 6 where I attempt to print of the results of the methods within the class. I think this means that I'm attempting to print something that doesn't exist and I suspect it's the mileage method. I tried changing it to return miles, but that didn't work either. Any ideas?
public class TestCar {
public static final void main(String args[]) {
Car c = new Car ();
c.moveForward(4);
System.out.println ("The car went" + c.mileage() + "miles."); // <-- L6
}
}
class Car {
public int miles = 2000;
public void moveForward(int mf) {
if (miles != 2000) {
miles += mf;
}
}
public void mileage() {
System.out.print(miles);
}
}
The error message is telling you exactly what is wrong -- you're trying to extract a result from a method that does not return a result.
Instead, have the mileage() method return a String, not print out a String.
public String mileage() {
return String.valueOf(miles);
}
Myself, I'd make this a getter method, and instead would do:
public int getMiles() {
return miles;
}
Car.mileage() is void, i.e., does not return anything. It needs to return something, like in:
public int mileage() {
return miles;
}

Eclipse compilation error for generic method

I'm getting a compilation error in Eclipse, while using a generic method, which doesn't appear when using javac. I'm guessing it's a compiler option in Eclipse, but I can't see a relevant item in the Preferences window.
The example I'm working with is from Thinking In Java 4th Edition, the relevant code is below, copied and pasted from the downloadable examples from the book's website.
//: generics/Generators.java
// A utility to use with Generators.
import java.util.*;
import net.mindview.util.*;
public class Generators {
public static <T> Collection<T>
fill(Collection<T> coll, Generator<T> gen, int n) {
for(int i = 0; i < n; i++)
coll.add(gen.next());
return coll;
}
public static void main(String[] args) {
Collection<Coffee> coffee = fill(
new ArrayList<Coffee>(), new CoffeeGenerator(), 4);
for(Coffee c : coffee)
System.out.println(c); }
}
Generator, Coffee and CoffeeGenerator are defined elsewhere, but I don't believe they are relevant to my issue.
This code gives me the compiler error: 'The method fill(Collection, Generator, int) in the type Generators is not applicable for the arguments (ArrayList, CoffeeGenerator, int)'.
Any ideas which option I can change to make Eclipse compile the same as when I use javac from the command line?
Many thanks in advance! I did do a search (here and Google) and couldn't find an answer - apologies if this is a repeat.
Code for CoffeeGenerator:
//: generics/coffee/CoffeeGenerator.java
// Generate different types of Coffee:
import java.util.*;
import net.mindview.util.*;
public class CoffeeGenerator
implements Generator<Coffee>, Iterable<Coffee> {
private Class[] types = { Latte.class, Mocha.class,
Cappuccino.class, Americano.class, Breve.class, };
private static Random rand = new Random(47);
public CoffeeGenerator() {}
// For iteration:
private int size = 0;
public CoffeeGenerator(int sz) { size = sz; }
public Coffee next() {
try {
return (Coffee)
types[rand.nextInt(types.length)].newInstance();
// Report programmer errors at run time:
} catch(Exception e) {
throw new RuntimeException(e);
}
}
class CoffeeIterator implements Iterator<Coffee> {
int count = size;
public boolean hasNext() { return count > 0; }
public Coffee next() {
count--;
return CoffeeGenerator.this.next();
}
public void remove() { // Not implemented
throw new UnsupportedOperationException();
}
};
public Iterator<Coffee> iterator() {
return new CoffeeIterator();
}
}
Code for Generator:
//: net/mindview/util/Generator.java
// A generic interface.
package net.mindview.util;
public interface Generator<T> { T next(); } ///:~

Categories