Javac compilation error - java

I am trying to compile a Java class but I get this error:
TestRunner.java
TestRunner.java:3: error: package org.junit.runner does not exist
import org.junit.runner.JUnitCore;
^
TestRunner.java:4: error: package org.junit.runner does not exist
import org.junit.runner.Result;
^
TestRunner.java:5: error: package org.junit.runner.notification does not exist
import org.junit.runner.notification.Failure;
^
TestRunner.java:9: error: cannot find symbol
Result result = JUnitCore.runClasses(ApplicationIT.class);
^
symbol: class Result
location: class TestRunner
TestRunner.java:9: error: cannot find symbol
Result result = JUnitCore.runClasses(ApplicationIT.class);
It is unable to resolve any of the import packages and classes.
I'm not sure what is wrong?
Thanks

Got the same error, but
Closing android studio,cleaning the build and again rebuilding it solved my error.

Related

Flutter/Dart - FlutterFirebaseMessagingPlugin.java - Build fails with Exception "error: cannot find symbol"

After upgrading to Null Safety sdk: ">=2.12.0 <3.0.0" I'm getting errors when I try to build my Flutter app in Android Studio.
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:20: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceId;
^
symbol: class FirebaseInstanceId
location: package com.google.firebase.iid
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:21: error: cannot find symbol
import com.google.firebase.iid.Metadata;
^
symbol: class Metadata
location: package com.google.firebase.iid
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:152: error: cannot find symbol
: Metadata.getDefaultSenderId(FirebaseApp.getInstance());
^
symbol: variable Metadata
location: class FlutterFirebaseMessagingPlugin
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:153: error: cannot find symbol
FirebaseInstanceId.getInstance().deleteToken(senderId, "*");
^
symbol: variable FirebaseInstanceId
location: class FlutterFirebaseMessagingPlugin
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:165: error: cannot find symbol
: Metadata.getDefaultSenderId(FirebaseApp.getInstance());
^
symbol: variable Metadata
location: class FlutterFirebaseMessagingPlugin
C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:166: error: cannot find symbol
String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");
^
symbol: variable FirebaseInstanceId
location: class FlutterFirebaseMessagingPlugin
Android Studio tells me FlutterFirebaseMessagingPlugin.java "cannot find symbol". So what does this mean and how do I fix it
Update your firebase_messaging in pusbpec.yaml to version that supports null-safety (for example: firebase_messaging: ^10.0.0, and call flutter pub get from terminal
First, get the latest versions of your firebase dependencies from pub.dev
Run the commands:
flutter pub upgrade
flutter pub get
flutter clean
Invalidate caches and restart
and then try running the app
For me, the problem was that I updated androidx core version from 1.0.1 to 1.5.0 in my app/gradle file but I didn't update it in project level gradle file in resolutionStrategy
They both should be the same.

Error when I Migrate my project to androidx?

My project
Main class
I successfully migrated my project to androidx .
after I build my project it occurs an error in build folder.
error at build folder
Error :
`D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\MainActivity_ViewBinding.java:4: error: package android.support.annotation does not exist
import android.support.annotation.CallSuper;
^
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\MainActivity_ViewBinding.java:5: error: package android.support.annotation does not exist
import android.support.annotation.UiThread;
^
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\PopupMenuDialog_ViewBinding.java:4: error: package android.support.annotation does not exist
import android.support.annotation.CallSuper;
^
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\PopupMenuDialog_ViewBinding.java:5: error: package android.support.annotation does not exist
import android.support.annotation.UiThread;
^
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\MainActivity_ViewBinding.j
ava:22: error: cannot find symbol
#UiThread
^
symbol: class UiThread
location: class MainActivity_ViewBinding
where T is a type-variable:
T extends MainActivity declared in class MainActivity_ViewBinding
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\MainActivity_ViewBinding.j
`
ava:42: error: cannot find symbol
#CallSuper
^
symbol: class CallSuper
location: class MainActivity_ViewBinding
where T is a type-variable:
T extends MainActivity declared in class MainActivity_ViewBinding
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\PopupMenuDialog_ViewBin
ding.java:25: error: cannot find symbol
#UiThread
^
symbol: class UiThread
location: class PopupMenuDialog_ViewBinding
where T is a type-variable:
T extends PopupMenuDialog declared in class PopupMenuDialog_ViewBinding
D:\jp\ft\FileTransfer\app\build\generated\ap_generated_sources\debug\out\me\pengtao\filetransfer\PopupMen
uDialog_ViewBinding.java:64: error: cannot find symbol
#CallSuper
^
symbol: class CallSuper
location: class PopupMenuDialog_ViewBinding<T>
where T is a type-variable:
T extends PopupMenuDialog declared in class PopupMenuDialog_ViewBinding
8 errors
> Task :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. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3m 33s
17 actionable tasks: 9 executed, 8 up-to-date
How can I solve this ?
AndroidX and Butterknife only works with 9.0.0-SNAPSHOT or later
you can update your define in build.gradle as below
butterknife : "com.jakewharton:butterknife:10.2.1",
butterknifeCompiler: "com.jakewharton:butterknife-compiler:10.2.1",

Jersey client javax.ws.rs.client.Client not found

I have a jersey client. I have the following imports in the client class
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
When I compile the application I get
./src/com/uciext/ws/class2/client/StudentClient.java:3: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Client;
^
How can I fix the issue
EDITED:
This is the error trace
./src/com/uciext/ws/hw2/client/InventoryClient.java:4: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Client;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:5: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.ClientBuilder;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:6: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Entity;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:7: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Invocation;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:8: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.WebTarget;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:9: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.MediaType;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:10: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.Response;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:15: error: cannot find symbol
Client client = ClientBuilder.newClient();
^
symbol: class Client
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:15: error: cannot find symbol
Client client = ClientBuilder.newClient();
^
symbol: variable ClientBuilder
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:16: error: cannot find symbol
WebTarget myResource = client.target("http://127.0.0.1:8080/inventory/rest/catalog");
^
symbol: class WebTarget
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:17: error: package Invocation does not exist
Invocation.Builder builder = myResource.request(MediaType.TEXT_PLAIN);
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:17: error: cannot find symbol
Invocation.Builder builder = myResource.request(MediaType.TEXT_PLAIN);
^
symbol: variable MediaType
location: class InventoryClient
12 errors
This is the c.sh. I use jersey 2.2.7. I downloaded jersey 2.2.7 and copied it in my lib folder. Can I have the wrong version of jar.
JAXB_PATH=./lib/jaxb-ri-2.2.7/lib
JAXB_LIB=$JAXB_PATH/jaxb-api.jar:$JAXB_PATH/jaxb-core.jar:$JAXB_PATH/jaxb-impl.jar:$JAXB_PATH/jaxb-jxc.jar:$JAXB_PATH/jaxb-xjc.jar
JAXRS_PATH=./lib/jaxrs-ri/lib
JAXRS_API=./lib/jaxrs-ri/api
JAXRS_LIB=$JAXRS_PATH/jersey-server.jar:$JAXRS_PATH/jersey-common.jar:$JAXRS_PATH/jersey-container-servlet.jar:$JAXRS_PATH/jersey-container-servlet-core.jar:$JAXRS_API/javax.ws.rs-api-2.0.jar
CLASSPATH=$CLASSPATH:./lib/jaxrs-ri/api
CLASSPATH=$CLASSPATH:./lib/jaxb-ri-2.2.7/lib
CLASSPATH=$CLASSPATH:./lib/jaxrs-ri/lib
javac -classpath $JAXB_LIB:$JAXRS_LIB:. -d classes ./src/com/uciext/ws/hw2/util/*.java ./src/com/uciext/ws/hw2/backend/model/*.java ./src/com/uciext/ws/hw2/backend/*.java ./src/com/uciext/ws/hw2/backend/impl/*.java ./src/com/uciext/ws/hw2/service/model/catalog/*.java ./src/com/uciext/ws/hw2/service/model/order/*.java ./src/com/uciext/ws/hw2/service/model/orderconfirm/*.java ./src/com/uciext/ws/hw2/service/*.java ./src/com/uciext/ws/hw2/service/impl/*.java
javac -classpath $JAXB_LIB:$JAXRS_LIB:. -d classes ./src/com/uciext/ws/hw2/client/model/catalog/*.java ./src/com/uciext/ws/hw2/client/model/order/*.java ./src/com/uciext/ws/hw2/client/model/orderconfirm/*.java ./src/com/uciext/ws/hw2/client/*.java
Have you included the dependencies to get the implementation of this package?
If you are using maven this post give the details.
For library version, download libraries from here and follow the following tutorial for adding the required jars. Although the Client class is available in jaxrs-ri\api jar.
You want to grab this zip file and make sure the jaxrs-ri/api/jakarta.ws.rs-api-2.1.6.jar is in your classpath.

can not resolve symbol package name while creating library

I want to create a library and .jar file to use this into another project, for creating library and .jar file i'm following this tutorial, but when i'm copying my classes in to library module i got error, can not resolve symbol Color for import android.graphics.Color and for all other package i got same error,
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.util.Log;
import android.content.Context;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Typeface;
and while build
/local_dir/newFolder/../../src/main/java/com/../Utils.java
Error:(3, 23) error: package android.content does not exist
Error:(4, 27) error: package android.content.res does not exist
Error:(5, 24) error: package android.graphics does not exist
Error:(6, 24) error: package android.graphics does not exist
Error:(7, 24) error: package android.graphics does not exist
Error:(8, 33) error: package android.graphics.drawable does not exist
Error:(9, 20) error: package android.util does not exist
Error:(10, 20) error: package android.util does not exist
Error:(11, 20) error: package android.view does not exist
Error:(21, 20) error: cannot find symbol class DisplayMetrics
Error:(33, 29) error: cannot find symbol class Context
Error:(91, 37) error: cannot find symbol class Paint
Error:(95, 20) error: cannot find symbol class Rect
Error:(97, 38) error: cannot find symbol class Paint
Error:(132, 25) error: package Paint does not exist
Error:(134, 39) error: cannot find symbol class Paint
Error:(138, 39) error: cannot find symbol class Paint
Error:(138, 57) error: package Paint does not exist
Error:(143, 40) error: cannot find symbol class Paint
Error:(147, 40) error: cannot find symbol class Paint
Error:(147, 58) error: package Paint does not exist
Error:(152, 38) error: cannot find symbol class Paint
Error:(159, 20) error: cannot find symbol class Rect
Error:(168, 37) error: cannot find symbol class Paint
Error:(196, 20) error: cannot find symbol class Rect
Error:(198, 34) error: cannot find symbol class Canvas
Error:(199, 34) error: cannot find symbol class Drawable
I want to create a library .jar file to use it into another project, so how to solve this error ? or any other way to create library .jar file?
its seems dependent jars are not at class path
while creating jar from your library all dependent classes jars should in class path.

Unable to compile a JUnit test on Windows

I'm trying to compile this very simple JUnit test on my Windows 10 box:
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TestHelloWorld
{
#Test
public void BasicTest ()
{
assertTrue(true);
}
}
However, this seemingly innocuous task has proven impervious to three to four hours of research and trial and error.
From a Cygwin terminal I see this:
javac -cp lib/hamcrest-core-1.3.jar:/lib/junit-4.12.jar:. TestHe
TestHelloWorld.java:1: error: package org.junit does not exist
import static org.junit.Assert.assertTrue;
^
TestHelloWorld.java:1: error: static import only from classes and interfaces
import static org.junit.Assert.assertTrue;
^
TestHelloWorld.java:2: error: package org.junit does not exist
import org.junit.Test;
^
TestHelloWorld.java:6: error: cannot find symbol
#Test
^
symbol: class Test
location: class TestHelloWorld
TestHelloWorld.java:9: error: cannot find symbol
assertTrue(true);
^
symbol: method assertTrue(boolean)
location: class TestHelloWorld
5 errors
and from a CMD prompt I see this:
javac -cp C:\Users\canon\Documents\GitHub\cse1341\AssignmentTester\lib\junit.jar TestHelloWorld.java
error: error reading C:\Users\canon\Documents\GitHub\cse1341\AssignmentTester\lib\junit.jar; error in opening zip file
1 error
I honestly have no idea what I'm doing incorrectly here. I've always been on a *nix machine before, where I don't recall having any problems compiling JUnit tests when I pass in the junit and hamcrest jars to the class path using the -cp flag. Any ideas or guidance here would be much appreciated!
There are two thing:
Java in windows using ';' to separate the jar files in classpath argument so it should be
"javac -cp lib/hamcrest-core-1.3.jar;/lib/junit-4.12.jar;. TestHeTestHelloWorld.java" in cygwin
check if C:\Users\canon\Documents\GitHub\cse1341\AssignmentTester\lib\junit.jar is a valid jar. (you can use zip tool to check).
The slash before lib/junit-4.12.jar seems to be wrong.

Categories