I'm trying to write a library called "Visione" in Processing using the processing-library-template here.
Unfortunately Eclipse gives me the following error:
[javac] long lastIpCameraRead = millis();
[javac] ^
[javac] symbol: method millis()
[javac] location: class Visione
I noticed the errors also occurs in most of the basics Processing functions like delay(), stroke(), etc.
This is the list of the imports:
import processing.core.*;
import gab.opencv.*;
import ipcapture.*;
import g4p_controls.* ;
import processing.video.*;
import java.awt.* ;
import java.util.*;
Thank you!
If you're in a class other than your main sketch, you can't access Processing's functions directly.
Instead, you'd probably want to pass a PApplet reference into your class, and use that to call Processing's functions. Something like this:
public class MyClass{
public MyClass(PApplet sketch){
long time = sketch.millis();
}
}
Then in your sketch code, you would use the this keyword to pass in a self-reference to the sketch:
void setup(){
size(500, 500);
new MyClass(this);
}
Related
I'm working on a Java Hands-On Exercise, And I ran into this problem where for some reason, It gives me this error whenever I try to call the ItemTaxCalculator class on my Java Test File
Here is the ItemTaxCalculator class
package com.mycompany.taxcalculator;
public class ItemTaxCalculator {
public double CalculateItemTax(double itemPrice, double taxPercent){
double decrease = taxPercent/10.0;
return itemPrice * decrease;
}
}
And this is the ItemTaxCalculatorTest.java
package taxcalculator;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ItemTaxCalculatorTest {
public ItemTaxCalculatorTest() {
}
#Test
public void testCalculateItemTax(){
System.out.println("CalculateItemTax method");
ItemTaxCalculator instance = new ItemTaxCalculator();
double itemPrice = 50.0;
double taxPercent = 1.0;
double expectedResult = 5.0;
double result = instance.CalculateItemTax(itemPrice, taxPercent);
assertEquals(expectedResult, result, 0.0);
}
}
The error occurs on the
ItemTaxCalculator instance - new ItemTaxCalculator(); line.
An error message comes up saying:
cannot find symbol
symbol: class ItemTaxCalculator
location: class ItemTaxCalculatorTest
I can't seem to find an answer for this problem, And this is the only thing that hinders me from running the code. I hope I can find some help, cheers!
Your problem is not netbeans related.
Your original class is in package:
package com.mycompany.taxcalculator;
while your test is in package:
package taxcalculator;
The test would be able to compile and execute as is, but only if both classes were in the same package.
So, there are two ways you can fix your issue.
Put your classes in the same package
Just change one of your package statements so that it matches the other one.
Add an import statement in your test class
import com.mycompany.taxcalculator.ItemTaxCalculator;
Once you do this, the class will be found and can be instantiated.
$ javac Main.java
Main.java:27: error: illegal static interface method call
ProcessHandle.current().allProcesses().mapToLong(w->w.pid()).forEach(System.out::println);
^
the receiver expression should be replaced with the type qualifier 'ProcessHandle'
1 error
Why do I get "the receiver expression should be replaced with the type qualifier 'ProcessHandle'"?
What shall I do instead? Thanks.
import java.lang.System;
import java.io.File;
import java.io.IOException;
import java.util.stream.Stream;
public class Main {
public static void main(String args[]){
System.out.println("visible processes pids are: ");
ProcessHandle.current().allProcesses().mapToLong(w->w.pid()).forEach(System.out::println);
}
}
What are You trying to achieve here? It doesn't seem to make much sense to ask for the current ProcessHandle and then use that to query allProcesses. Both of these are static methods. You probably want to just omit the ".current()".
I am a newbie in Java and writing a very simple program. It looks perfect to me.
I know that java.util.Date contains a Time object that can be used.
This link also provides some documentation on the same.
However when I run the program I get an error. Please help me figure out what's wrong here.
package timestuff;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import java.util.TimeZone;
public class MyDays {
private Time start;
private double temp;
public MyDays(final Time StartTime, final double Temperature) {
start = StartTime;
temp = Temperature;
}
}
I am getting the following error:
MyDays.java:15: error: cannot find symbol
private Time start;
^
symbol: class Time
location: class MyDays
You need to import time class .
import java.sql.Time
The javadoc doesn't say anything about a time class in java.util.Date
You import it.
import java.sql.Time
I'm new to java, and I've been trying to get my program to compile using Netbeans. HelloWorldApp.java uses the Greeter class in Greeter.java. I keep getting errors and I can't figure it out. I understand that you have to include "packages" or something. I don't have a lot of experience with Netbeans either. But I would love for this to work.
Here is the HelloWorldApp.java:
package helloworldapp;
import Greeter
public class HelloWorldApp
{
public static void main(String[] args)
{
Greeter myGreeterObject = new Greeter();
myGreeterObject.sayHello();
}
}
And here is Greeter.java:
public class Greeter
{
public void sayHello()
{
System.out.println("Hello, World!");
}
}
Change the first line of Greeter to
package helloworldapp;
And then remove
import Greeter
from HelloWorldApp. You only need to import classes that are in other packages. Also, an import line is terminated with a semicolon. Finally, import is always optional and a convenience for the developer; as an example,
import java.util.Calendar;
Allows you to write
Calendar cal = Calendar.getInstance();
But, without the import you could still use
java.util.Calendar cal = java.util.Calendar.getInstance();
Just put the Greeter class in the same folder (i.e. package) as the other file and remove the "import Greeter" statement. You should put every class in a package as you did with the HelloWorldApp class.
If you leave classes without package (i.e. in the root folder) you cannot import them.
As long as both are in the same package (folder) there will be no need for the "import Greeter" statement, this should fix it, hope this helps!
I am fairly new to modding.
I want to create a sword that sets mobs or players on fire. I am using the hitEntity method and, I noticed the function is not even running. I tested it using the console. When I use the #Override notation before the hitEntity method it gives me an error:
The method hitEntity(ItemStack, EntityLiving, EntityLiving) of type BlazeSword must override or implement a supertype method
Here is my code:
package com.example.firstMod.tools;
import com.example.firstMod.FirstMod;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
public class BlazeSword extends ItemSword {
public BlazeSword(int id, ToolMaterial blaze) {
super(blaze);
this.setCreativeTab(FirstMod.blazingMod);
this.setUnlocalizedName("blazeSword");
this.setTextureName(FirstMod.MODID+":"+"blaze_sword");
}
public boolean hitEntity(ItemStack par1itemstack, EntityLiving par2entityliving, EntityLiving par3entityliving){
par2entityliving.setFire(20);
return true;
}
}
If you get the error you said with #Override, so there is no such method in ItemSword. Look ItemSword class for the right hit method.
The hitEntity method isn't working because you never call it. You declare that it exists but you never run it. What you need to do is call your hitEntity method in your BlazeSword class using your requested variables.
In your BlazeSword class:
hitEntity(ItemStack par1itemstack, EntityLiving par2entityliving, EntityLiving par3entityliving)
Also, take out #Override since you aren't trying to find the hierarchy of the blaze sword.