I am having a problem with IntelliJ not finding the imports (and subsequently the classes)
At the moment the code is bare bones and doesn't do anything, I am in the process of practicing my skills but I can't get past this error.
The IntelliJ project can be found on GitHub here
The code in question is MovieRecommenderSystemApplicationTests.java
package com.jreid.spring.basics.movierecommendersystem;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
#SpringBootTest
class MovieRecommenderSystemApplicationTests {
#Test
void contextLoads() {
}
}
And the errors are as follows:
java: package org.junit.jupiter.api does not exist
java: package org.springframework.boot.test.context does not exist
java: cannot find symbol
symbol: class SpringBootTest
java: cannot find symbol
symbol: class Test
location: class com.jreid.spring.basics.movierecommendersystem.MovieRecommenderSystemApplicationTests
IntelliJ finds the symbols without any problems.
Any help would be appreciated. Thanks
Enable auto import for maven dependency in settings Import Maven projects automatically. And do mvn clean install. If it won't work, use Invalidate Caches menu to reindex mvn repository.
And be sure you have all dependencies in pom.xml of course
Related
I am trying to run my Selenium code in Ubuntu server and I saw some articles that Java is indenpendent with OS so I thought my Java selenium code would run without any configurations.
However, when I run my Selenium code in Ubuntu server, it comes out heaps of error followings
TestNGSandBox.java:16: error: package org.testng does not exist
import static org.testng.Assert.assertEquals;
^
TestNGSandBox.java:16: error: static import only from classes and interfaces
import static org.testng.Assert.assertEquals;
^
TestNGSandBox.java:17: error: package org.testng does not exist
import static org.testng.Assert.assertFalse;
^
TestNGSandBox.java:17: error: static import only from classes and interfaces
import static org.testng.Assert.assertFalse;
^
TestNGSandBox.java:18: error: package org.testng does not exist
import static org.testng.Assert.assertTrue;
^
TestNGSandBox.java:18: error: static import only from classes and interfaces
import static org.testng.Assert.assertTrue;
^
TestNGSandBox.java:19: error: package org.testng does not exist
import static org.testng.Assert.fail;
^
TestNGSandBox.java:19: error: static import only from classes and interfaces
import static org.testng.Assert.fail;
^
TestNGSandBox.java:47: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
The way I transfered the project from Windows was that copied whole project folder and pasted in Ubuntu home directory. Then I just type command like.
java TestNGSandBox.java
Many solutions I found are talking about Desktop version of Ubuntu.
I am practically new to Java so there must be something I missed while I am porting. So if you give me a tip, that would be super super great.
Thank you in advance.
To run the selenium/testNG project on Ubuntu you have to:
1 Install Java
https://askubuntu.com/questions/48468/how-do-i-install-java
looks like this is already done since you got more detailed java error messages,
which means you have no required packages.. so
2 Make sure, you have all the required libraries .jar files within your project
org.testng
org.openqa.selenium
3 You have to compile the class you want to run.
For the project when you have all the files in one directory:
javac TestNGSandBox.java -cp testng.jar; selenium.jar; ... other dependencies if needed
4 Run the class:
java -cp testng.jar; selenium.jar; TestNGSandBox
But using javac/java for managing projects is time-consuming. Try to look at Maven/Gradle tools, which help to build projects and manage dependencies.
Take a look at some selenium-maven-TestNG project skeletons
https://github.com/khoamle/selenium-java
https://github.com/lalit-k/selenium-java-tests
https://github.com/nusratahmed/maven-selenium-webdriver-testng-example-project
How can I add an Android build dependency to my custom capacitor plugin for app rate based on
https://developer.android.com/guide/playcore/in-app-review/kotlin-java#java
It fails the build with not finding com.google.android.play.core so I wonder how can I add it as a dependency to the component build?
Below is the error
/AppRate.java:9: error: package com.google.android.play.core.review does not exist
import com.google.android.play.core.review.ReviewInfo;
^
/AppRate.java:10: error: package com.google.android.play.core.review does not exist
import com.google.android.play.core.review.ReviewManager;
^
/AppRate.java:11: error: package com.google.android.play.core.review does not exist
import com.google.android.play.core.review.ReviewManagerFactory;
^
/AppRate.java:12: error: package com.google.android.play.core.tasks does not exist
import com.google.android.play.core.tasks.Task;
^
/AppRate.java:17: error: class AppRate clashes with package of same name
public class AppRate extends Plugin {
^
/AppRate/BuildConfig.java:4: error: package me.url.AppRate clashes with class of same name
package me.url.AppRate;
^
/AppRate.java:21: error: cannot find symbol
Activity activity = this.cordova.getActivity();
I am also not sure about the clash error, but that is a separate topic I guess.
Note - I tried integrating the ionic native plugins but had weird build issues. iOS now works with my custom plugin, fixing Android now.
Try these steps to see:
Delete the Buildconfig.java
Refactor -> Rename, error class.
Build -> Rebuild Project!
--
And if not, share what you have in the file: build.gradle in the defaultConfig section and AndroidManifest from the manifest section.
I had to add
implementation "com.google.android.play:core:1.10.2"
to my build.grade file.
Super rusty in Java here
Trying to contribute to an open source project that uses maven and aws
As per what I believe is the right page in the doc, I start with
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
Then I define a variable
EndpointConfiguration end_point;
But I get the error
cannot find symbol
symbol: method EndpointConfiguration(java.lang.String,java.lang.String)
location: class repository.AmazonS3Client
I had a bug with import statement earlier but I fixed that by adding
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.975"
to the Scala SBT file
Am I doing the java import wrong? Do I need to import another package in the SBT? I couldn't find anything else on the Maven repository
I've tried static import as well. Didn't work
I am testing a Spring Boot application using code from a tutorial. The tutorial describes the setup and configuration of a Spring Boot application, and also describes a test that uses JAssert calls in the following manner:
package hello;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
#RunWith(SpringRunner.class)
#SpringBootTest
public class SmokeTest {
#Autowired
private HomeController controller;
#Test
public void contexLoads() throws Exception {
assertThat(controller).isNotNull();
}
}
The test, unfortunately, will not compile in my IDE. The compilation is failing on the assertThat() method.
I am using Eclipse with Maven for my IDE. I have checked the Maven dependencies and see that the JAssert core library is included. Unfortunately, despite this the compiler can not seem to "find" the assertThat() call.
It fails to compile the test for that reason.
How do I get the test to utilize JAssert and find the calls to JAssert functions?
I'm not an eclipse expert, but it seems like you have some configuration issue here.
If you're sure that the dependency appears in pom.xml in scope test then try to eliminate eclipse related issues by running the tests directly via maven:
mvn test
will do the job
If it runs sucessfully, then re-create eclipse configurations from pom.xml / re-import the project.
If not, its a pom.xml related issue and has nothing to do with eclipse, you'll have to fix the pom or maven ecosystem. I suggest the following:
go to the local repository and remove the dependency from the file system (manually, the whole directory, with jar, pom.xml and everything) and then rerun mvn test
Sometimes dependencies are downloaded corrupted and despite being defined correctly in pom.xml they do not really contain classes in a form that java/maven can read
Actually:
It turns out that neither the Boot starter nor the IDE seems to find the necessary import declaration for the JAssert functions. Could it be because they are static?
In looking at some example code, I found in the code the import declaration for the assertThat() method. Usually, Eclipse would have suggested this declaration but it does not.
What is weird is that I put in the declaration by hand, and not only does this allow me to compile, but Eclipse, once the import is included, the code assistant makes proper assertThat() suggestions without problems!
There could be a bug somewhere, but that is beyond the scope of my particular problem. My test now compiles without problems.
I hope someone looking at this can figure out why Elipse's code assist does not work for this particular library properly. I wouldn't be surprised to discover that there are other objects/libraries in Spring Boot that don't get properly handled by the code assistant.
I am trying to get a test class compiling with JUnit, and I can't figure out why it will not compile.
I have the following lines at the top of my class:
import java.util.*;
import org.junit.*;
And the error I am getting is
package org.junit does not exist
JUnit.jar is currently located in Program Files\JUnit\junit.jar, which currently also resides in my class path. I am working on Windows Vista if that helps.
Any ideas on how I can compile this test class with JUnit?
Thanks very much,
What version of JUnit are you using?
I think that until JUnit 3, the package was different:
import junit.framework.*;
Also, if you are using Eclipse, you can pick the JUnit framework to use.