cannot find symbol when running unit test on Android - java

I'm not very familiar with Andorid and Gradle. I'm trying to run this unit test from the same project after removing the #Ignore annotation. But I'm getting the following error
java.lang.AssertionError: Compilation produced the following errors:
/SOURCE_OUTPUT/com/example/MainActivity$$Aftermath.java:6: error: cannot find symbol
import org.michaelevans.aftermath.IAftermathDelegate;
^
symbol: class IAftermathDelegate
location: package org.michaelevans.aftermath
/SOURCE_OUTPUT/com/example/MainActivity$$Aftermath.java:8: error: cannot find symbol
public class MainActivity$$Aftermath<T extends com.example.MainActivity> implements IAftermathDelegate<T> {
^
symbol: class IAftermathDelegate
can someone please point out to me how to solve the problem?

Related

Can someone help me fixing this cannot find symbol error [duplicate]

This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 1 year ago.
I just started to learn programming with a book I got recently and it teaches me to write plugins for minecraft with java.The first task is to copie the following code it´s supposed to say Hallo Welt when I enter the minecraft world
import org.bukkit.plugin.java.JavaPlugin;
public class HalloWeltPlugin extends JavaPlugin {
public void onEnable() {
this.getLogger().info("Hallo Welt!");
}
public void onDisable() {
}
}
But when i try to compile the code it shows following error:
HalloWeltPlugin.java:1: error: cannot find symbol
import org.bukkit.plugin.java.JavaPlugin;
^
symbol: class JavaPlugin
location: package org.bukkit.plugin.java
HalloWeltPlugin.java:3: error: cannot find symbol
public class HalloWeltPlugin extends JavaPlugin {
^
symbol: class JavaPlugin
HalloWeltPlugin.java:5: error: cannot find symbol
this.getLogger().info("Hallo Welt!");
^
symbol: method getLogger()
3 errors
As i said i have no idea of programming yet and i would be happy if someone could tell me what the mistake is.
The Problem seems to be that the Class JavaPlugin can't be resolved hence it is a symbol which can not be found. Did you include the package org.bukkit.plugin.java into your project via maven/gradle or directly?
When you starting out with programming, I'd suggest you to start with the basics instead of jumping right into coding plugins for Minecraft.
A beginners guide to Java like this would suite you better.

Flapping compilation error gradle java build

I've never seen anything like this before and have asked everyone at work and they are not sure either. I am getting a compilation error on a ./gradlew assemble build but it does not occur consistently. The error is shown below. What is particularly confusing about this is both AbstractDateRangeConfig and DynamicRequestComponent are used throughout the code base in other classes and these compile fine consistently. DynamicRequestComponent is a spring annotation the other class is an internal class. There is another class with an almost identical setup, the only difference I can see is that there is also an inner class with a #Configuration annotation in the class which fails compilation. Does anyone have any suggestion on what might cause a flapping compilation error like this?
:frontend:compileJava/mnt/jenkins/workspace/frontend/src/main/java/com/frontend/app/controller/group/forecast/NewGroupForecastReport.java:358: error: cannot find symbol
public static class NewGroupForecastReportConfig extends AbstractDateRangedConfig {
^
symbol: class AbstractDateRangedConfig
location: class NewGroupForecastReport
/mnt/jenkins/workspace/duetto_app_basic2/frontend/src/main/java/com/frontend/app/controller/group/forecast/NewGroupForecastReport.java:357: error: cannot find symbol
#DynamicRequestComponent
^
symbol: class DynamicRequestComponent
location: class NewGroupForecastReport
2 errors
FAILED
Edit: It is not the #Configuration annotation causing it. I removed that part of the code and still see the error
Appears to be resolved by pulling out the inner class into a separate class file. Believe the error had something to do with the way Spring scans for annotations

Package not found when running javac

I know that this question was already asked thousand times, but I still can't fully understand the point of the problem, especially in my case. So, I have simple project with dependency of TestNG and Selenium Java libraries, and I have these libraries installed globally, so my project just import them from "global" scope.
So to solve the problem I should add that global folder to my classpath ? Or this in not right from the beginning and I should not use libraries globally in projects ?
C:\Users\Yaroslav\IdeaProjects\GoogleSearchTest\src\main\java>javac GoogleSearchTest.java
GoogleSearchTest.java:1: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
^
GoogleSearchTest.java:2: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
^
GoogleSearchTest.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
^
GoogleSearchTest.java:4: error: package org.openqa.selenium.chrome does not exist
import org.openqa.selenium.chrome.ChromeDriver;
^
GoogleSearchTest.java:5: error: package org.testng.annotations does not exist
import org.testng.annotations.BeforeClass;
^
GoogleSearchTest.java:6: error: package org.testng.annotations does not exist
import org.testng.annotations.Parameters;
^
GoogleSearchTest.java:7: error: package org.testng.annotations does not exist
import org.testng.annotations.Test;
^
GoogleSearchTest.java:12: error: cannot find symbol
private static WebDriver driver;
^
symbol: class WebDriver
location: class GoogleSearchTest
GoogleSearchTest.java:14: error: cannot find symbol
#BeforeClass
^
symbol: class BeforeClass
location: class GoogleSearchTest
GoogleSearchTest.java:23: error: cannot find symbol
#Test
^
symbol: class Test
location: class GoogleSearchTest
GoogleSearchTest.java:24: error: cannot find symbol
#Parameters("queryText")
^
symbol: class Parameters
location: class GoogleSearchTest
GoogleSearchTest.java:17: error: cannot find symbol
driver = new ChromeDriver();
^
symbol: class ChromeDriver
location: class GoogleSearchTest
GoogleSearchTest.java:26: error: cannot find symbol
WebElement searchField = driver.findElement(By.cssSelector("#lst-ib"));
^
symbol: class WebElement
location: class GoogleSearchTest
GoogleSearchTest.java:26: error: cannot find symbol
WebElement searchField = driver.findElement(By.cssSelector("#lst-ib"));
^
symbol: variable By
location: class GoogleSearchTest
GoogleSearchTest.java:28: error: cannot find symbol
WebElement searchButton = driver.findElement(By.name("btnK"));
^
symbol: class WebElement
location: class GoogleSearchTest
GoogleSearchTest.java:28: error: cannot find symbol
WebElement searchButton = driver.findElement(By.name("btnK"));
^
symbol: variable By
location: class GoogleSearchTest
16 errors
GoogleSearchTest.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
public class GoogleSearchTest {
private static WebDriver driver;
#BeforeClass
public void setup () {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
}
#Test
#Parameters("queryText")
public void doSearch(String queryText) {
WebElement searchField = driver.findElement(By.cssSelector("#lst-ib"));
searchField.sendKeys(queryText);
WebElement searchButton = driver.findElement(By.name("btnK"));
searchButton.click();
}
}
I finally understand how it should be done.
So, to compile class and then run TestNG test I done this:
javac -cp C:\Users\Yaroslav\IdeaProjects\GoogleSearchTest\lib\* GoogleSearchTest.java
java -cp C:\Users\Yaroslav\IdeaProjects\GoogleSearchTest\src\main\java\;C:\Users\Yaroslav\IdeaProjects\GoogleSearchTest\lib\* org.testng.TestNG testng.xml
More detailed, in first line to compile class there should be a following command template:
javac -cp "full path to libs folder, where project libraries located" "name of class to compile"
And for second line, which run TestNG test, template is:
java -cp "full path to folder where testng.xml file located";"full path to libs folder, where project libraries located" "testNG filename with extension"
And this is very tiresome, as you can see. I should learn proper way to run similar tests without headache ...
P.S. After all, I just learn Maven and there is no need for these commands now )

app:compileDebugJavaWithJavac , react-native app failed to compile

I created my first react-native proejct and then ejected by npm run eject but app is failing to compile when I run npm run android and giving me below output and it is showing something wrong in andriod dir and but I don't have any clue what is this symbol import error and how to fix this. I have done lots of search and read but can't find solution to my problem.
I am not a java expert and don't know how to fix this . Please help me to fix this , many thanks
:app:mergeDebugResources UP-TO-DATE
:app:bundleDebugJsAndAssets SKIPPED
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:5: error: cannot find symbol
import com.facebook.react.ReactApplication;
^
symbol: class ReactApplication
location: package com.facebook.react
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:6: error: cannot find symbol
import com.facebook.react.ReactNativeHost;
^
symbol: class ReactNativeHost
location: package com.facebook.react
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:14: error: cannot find symbol
public class MainApplication extends Application implements ReactApplication {
^
symbol: class ReactApplication
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
^
symbol: class ReactNativeHost
location: class MainApplication
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:36: error: cannot find symbol
public ReactNativeHost getReactNativeHost() {
^
symbol: class ReactNativeHost
location: class MainApplication
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity
public class MainActivity extends ReactActivity {
^
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:16: error: cannot find symbol
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
^
symbol: class ReactNativeHost
location: class MainApplication
C:\Users\iClick Digital\Documents\ZerotoMastery\react-app\my-first-project\android\app\src\main\java\com\mynewproject\MainApplication.java:35: error: method does not override or implement a method from a supertype
#Override
^
8 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED

Compiling Errors in Netbeans with JFreeChart

When I run my project in Netbeans 8.1 nothing goes wrong. However, when I build it to a .jar file, there are 34 errors of missing packages and symbols all referring to JFreeChart. Couple of these errors:
C:NetBeansProjects\Program\src\org\jfree\chart\servlet\ChartDeleter.java:51: error: package javax.servlet.http does not exist
import javax.servlet.http.HttpSessionBindingEvent;
C:NetBeansProjects\Program\src\org\jfree\chart\servlet\ChartDeleter.java:52: error: package javax.servlet.http does not exist
import javax.servlet.http.HttpSessionBindingListener;
C:\NetBeansProjects\Program\src\org\jfree\chart\servlet\ChartDeleter.java:58: error: cannot find symbol
public class ChartDeleter implements HttpSessionBindingListener, Serializable {
symbol: class HttpSessionBindingListener
C:\NetBeansProjects\Program\src\org\jfree\chart\servlet\ChartDeleter.java:98: error: cannot find symbol
public void valueBound(HttpSessionBindingEvent event) {
symbol: class HttpSessionBindingEvent
location: class ChartDeleter
etc.....
My code is too long to post here (6000+ lines) and contains Java swing and some charts. Everything worked fine, but the charts made these errors appear. What's the reason for this?
"javax.servlet.http does not exist", add servletapi.jar to your classpath

Categories