Cannot find symbol Time in Java - java

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

Related

NetBeans cannot find a specified class within the same project

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.

Kotlin to java conversion DefaultConstructorMarker is not public in kotlin.jvm.internal

I Downloaded a kotlin file from github and wanted to convert it to a java file. I did this by Tools>Kotlin>Show kotlin ByteCode and then Decompiling. The Kotlin File is below:
package io.pokemon.core
import io.pokemon.model.Card
import io.pokemon.util.random.Randomiser
import io.pokemon.viewmodel.Round
class RoundFactoryImpl(private val randomiser: Randomiser) : RoundFactory {
override fun buildRound(cards: List<Card>): Round = Round()
}
After Copying the Decompiled kotlin Code into a java file I got the error: DefaultConstructorMarker is not public in kotlin.jvm.internal; cannot be accessed from outside package.
I attempted to fix this by adding the code inside DefaultConstructorMarker However this failed to fix the error.
package io.pokemon.core;
import io.pokemon.model.Card;
import io.pokemon.util.random.Randomiser;
import io.pokemon.viewmodel.Round;
import java.util.List;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
#Metadata(
...
)
public final class RoundFactoryImpl implements RoundFactory {
private final Randomiser randomiser;
#NotNull
public Round buildRound(#NotNull List cards) {
Intrinsics.checkParameterIsNotNull(cards, "cards");
return new Round((List)null, (Card)null, 3, (DefaultConstructorMarker)null);
}
public RoundFactoryImpl(#NotNull Randomiser randomiser) {
super();
Intrinsics.checkParameterIsNotNull(randomiser, "randomiser");
this.randomiser = randomiser;
}
}

How to obtain all ProductTypes created in my commercetools project?

I need to obtain all the ProductType that have been defined in my commercetools project because I have to use the localized value of the "name" to perform a search in a file system.
Basically I need to use the JVM SDK to extract the list of ProductTypes and traverse it.
Can someone give me some clue how to achieve it?
Thanks in advance.
Yep it is pretty feasible using the jvm sdk, here is a code snippet of how to do it
package io.sphere.sdk.deletemeplese;
import io.sphere.sdk.producttypes.ProductType;
import io.sphere.sdk.producttypes.queries.ProductTypeQuery;
import io.sphere.sdk.queries.PagedQueryResult;
import io.sphere.sdk.test.IntegrationTest;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat;
public class SomeIntegrationTest extends IntegrationTest {
#Test
public void test(){
final int PAGE_SIZE = 500;
final long totalProductTypes = client().executeBlocking(ProductTypeQuery.of().withLimit(0)).getTotal();
List<ProductType> allProductTypes = IntStream.range(0,(int)(totalProductTypes/PAGE_SIZE) +1)
.mapToObj(i->i)
.map(i -> ProductTypeQuery.of().withLimit(500).withOffset(i*PAGE_SIZE))
.map(client()::executeBlocking)
.map(PagedQueryResult::getResults)
.flatMap(List::stream)
.collect(Collectors.toList());
assertThat(allProductTypes).hasSize((int)totalProductTypes);
}
}
I hope this answers your question.
You could use the class QueryExecutionUtils.
CompletionStage<List<ProductType>> allProductTypesStage =
QueryExecutionUtils.queryAll(client, ProductTypeQuery.of());

Import millis() in processing library

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);
}

Change lib source code without destroying it

So, as I found the patched source code for BodyEditorLoader.java, I am not able to do any changes in the .java file. How to I edit it without destroying the library? Thanks!
I hope to explain well, a simple way would be to create a new class, copy the contents of the BodyEditorLoader class, except class package name package aurelienribon.bodyeditor;, and rename public class BodyEditorLoader by the name of your class, for example MyBodyEditorLoader. example:
//package aurelienribon.bodyeditor; --> change or delete for your packege name
package com.tynibattles04.game; //--> in your case for example.
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.JsonReader;
import com.badlogic.gdx.utils.JsonValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MyBodyEditorLoader {
//...other code
public MyBodyEditorLoader(FileHandle file) {
//...other code
}
public MyBodyEditorLoader(String str) {
//...other code
}
//..other code
and used (and import, if you need it necessary):
MyBodyEditorLoader loader = new MyBodyEditorLoader(
Gdx.files.internal("tankA.json"));

Categories

Resources