Latest Questions

Get Answers to Your Coding Questions

27
Votes
Published 09 Sep, 2022
Java - Stream definition

I'm reading on Java I/O streams and I'm confused on the correct definition associated with them. Some say that a stream is a sort of conveyor belt in which data are transmitted... other say that a s...

44
Votes
Published 10 Sep, 2022
Java - NoSuchMethodError: org/apache/log4j/Logger.setLevel(Lorg/apache/log4j/Level;)

I am using these log4j, slf4j and ch.qos.logback dependencies in my pom.xml of my java project: <dependency> <groupId>org.slf4j</groupId> <artifac...

112
Votes
Published 26 Aug, 2022
Java - How to know whether I am in a call on Android?

I want to know whether I am in a call. If I am in a call then start the service (service part is clear). How do I do this? While attending the call I need to call the service... I am unaware of how...

44
Votes
Published 18 Sep, 2022
Java - Set individual timeouts in VertX per request

Is it possible to set individual timeouts per request in VertX? Doing this, val vertx = Vertx.vertx(VertxOptions().setMaxWorkerExecuteTime(15000)) sets the timeout for all requests. Certain things...

64
Votes
Published 19 Sep, 2022
Java - Java access bean methods with LambdaMetafactory

my question is strongly related to Explicit use of LambdaMetafactory in that thread, some very good examples are provided to use the LambdaMetafactory to access a static method of a class; however, I...

48
Votes
Published 31 Aug, 2022
Java - TimerTask class has to run only once in java

I have a class that runs for every 10 secs, but when I execute it more than once, multiple timers are started. If one timer is already running, I want the other timer calls to be ignored. I want only...

125
Votes
Published 12 Sep, 2022
Java - Define default constructor for record

I have a record and want to add default constructor to it. public record Record(int recordId) { public Record { } } But it created constructor with int param. public final class Record ext...

9
Votes
Published 19 Sep, 2022
Java - R.layout.main couldn't be resolved

I am building an application and I added a new activity to generate a view. I compiled it. My application can not find anything that is on the format R.id.xxx or R.layout.xxx, I've tried also cleaning...

21
Votes
Published 22 Aug, 2022
Java - Spring graceful shutdown - REQUEST METHOD POST NOT SUPPORTED

I'm trying to use the Spring endpoints to gracefully shut down my application but I'm getting an error: 2016-08-09 13:46:54.606 WARN 13315 --- [nio-8090-exec-6] .w.s.m.s.DefaultHandlerExceptionResol...

103
Votes
Published 26 Aug, 2022
Java - Override log4j.properties

My java application references a 3rd-party jar file which uses log4j logging. The problem is that this jar contains its own log4j.properties file which causes access denied exceptions on my machine, b...

68
Votes
Published 19 Sep, 2022
Java - Meaning of android.content.UriMatcher

What is Uri Matcher in android.content.UriMatcher How to use it? Can someone please explain meaning of following three line of code? uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); uriMatcher....

89
Votes
Published 20 Aug, 2022
Java - If parenthesis has a higher precedence then why is increment operator solved first?

I have a single line code, int a = 10; a = ++a * ( ++a + 5); My expected output was 12 * (11 + 5) = 192 ,but I got 187. As much as I knew the increment operator inside () is to be solved first, the...

22
Votes
Published 09 Sep, 2022
Java - How to copy superclass object values to subclass object values?

I want to copy superclass object getters to subclass object setters. But how can I do this easily. I'm looking for something like clone. Could you please me help me to find it? A simple code: Super...

105
Votes
Published 18 Sep, 2022
Java - CXF Client Security

I am creating a client to a Java soap web service, but am having trouble figuring out how to properly pass the password. Here is my "hardcoded" password example: @Test public void exploratorySecurit...

143
Votes
Published 25 Aug, 2022
Java - How to update maven repository in Eclipse?

Assuming you're already using the m2eclipse plugin, what can you do when it doesn't update the dependencies to the latest in your repo? For example, on the command line, you can just add the -U flag...

79
Votes
Published 13 Sep, 2022
Java - Do java threads get deleted when they finish

Say I spawn a thread every couple seconds using the method below and every thread takes about a second to complete. Do the finished threads get deleted? new Thread (new myRunnableClass()).start();

35
Votes
Published 12 Sep, 2022
Java - Update Specific Fields with Spring Data Rest and MongoDB

I'm using Spring Data MongoDB and Spring Data Rest to create a REST API which allows GET, POST, PUT and DELETE operations on my MongoDB database and it's all working fine except for the update operati...

45
Votes
Published 05 Sep, 2022
Java - @OnClick method from Butterknife crashes app with java.lang.BootstrapMethodError

I am using Butterknife to simplify my code. I have a TextView in the activity_main.xml file. I want to display a toast by clicking on this TextView But when I use @OnClick annotation from Butterknife...

93
Votes
Published 27 Aug, 2022
Java - Exception when creating new instance of OkHttp3.OkHttpClient

I'm trying to use OkHttp to download a file from a webserver in an Android app. After creating a new Project with Android Studio (API level 28) I added a button and am ImageView to my Activity. The id...

45
Votes
Published 26 Aug, 2022
Java - Extend Lollipops "heads-up" notification duration

Been trying to find a way to create a persistent heads up notification, exactly like receiving a phone call or hangouts call. Are these restricted to Google/system apps? I've tried: Updating the no...

73
Votes
Published 01 Sep, 2022
Java - Primary shard is not active or isn't assigned is a known node ?

I am running an elastic search version 4.1 on windows 8. I tried to index a document through java. When running a JUNIT test the error appears as below. org.elasticsearch.action.UnavailableShardsEx...

59
Votes
Published 23 Aug, 2022
Java - FirebaseAuth class now missing "getCurrentUser()" method?

Firebase used to work just fine yesterday, but I opened my project this morning just to find that the FirebaseAuth class now has no reference whatsoever to the FirebaseUser class. I cannot find the ge...

15
Votes
Published 28 Aug, 2022
Java - Using SpringFrameWork @Async for methods that return void

I'm using the Spring Boot framework as my backend. This is one of the calls I want to do asynchronously - it just saves a user into my mongoDB database: @Async public Future<Void> saveUser(Str...

94
Votes
Published 28 Aug, 2022
Java - Trying to upload a file to a JAX-RS (jersey) server

I'm trying to upload a file and other form data using multipart/form-data client with Jersey. I'm uploading to a REST web service also using Jersey. Here is the server code: @POST @Consumes(MediaTy...

7
Votes
Published 07 Sep, 2022
Java - How to escape comma and double quote at same time for CSV file?

I am writing a Java app to export data from Oracle to csv file Unfortunately the content of data may quite tricky. Still comma is the deliminator, but some data on a row could be like this: | ID...

104
Votes
Published 07 Sep, 2022
Java - Find out what variable is throwing a NullPointerException programmatically

I know I can find out if a variable is null in Java using these techniques: if (var==null) -> too much work try { ... } catch (NullPointerException e) { ...} -> it tells me what line is throwing the...

66
Votes
Published 28 Aug, 2022
Java - Switching from H2 to PostgreSQL with spring boot

I have a spring boot application working fine on a H2 DB. If I want to switch to postgresQL I get errors. spring.datasource.url=jdbc:postgresql://localhost:5432/postgres spring.datasource.username=po...

103
Votes
Published 10 Sep, 2022
Java - Instantiate enum class

Consider I am having the following enum class, public enum Sample { READ, WRITE } and in the following class I am trying to test the enum class, public class SampleTest { public static...

17
Votes
Published 08 Sep, 2022
Java - Android aar library doesn't contain dependencies

i saw similar questions, but not found accepted answers. Problem - i have my own android library with some tiny functions. My library uses others - f.e. Hawk (no sql database). My library gradle file:...

26
Votes
Published 13 Sep, 2022
Java - How can I have multiple versions of the Java JDK installed on my machine at the same time?

Background I work mostly in Java and Scala on my job, but a lot of our legacy code has not yet been updated to the most recent JDK. Thus, we have to have JDK versions 5, 6, 7, and 8 installed on our...