I was tasked with creating my own linked list class, using a book class i made. One of the questions was to Determine the book that appears first alphabetically. i was able to sort the Linked list alphabetically using bubble sort(i know its not efficient but im still new) here is the code. my problem is i onl…
Tag: java
Getting the Activity inside Adapter in Android
I am trying to access the activity on which my Imageview is, so I can use the URL of an Image of type SVG and display it to the user using the GlideToVectorYou library. But when I try to get access to the activity using R.layout.activityname, a syntax error appears. this is the code that I’m using Thank…
LocalDate.parse can’t parse the character on the last index wehere there is no character (nor empty space)
I have in my notepad file text: I checked is there any empty spaces, there is none. When I write: I receive an error: But there is no index 10! Why it thinks there is index[10]? Answer Trim possible whitespaces before parsing the date using String::trim:
ClassCastException being encountered even with correctly imported or assigned classes
I am receiving a ClassCastException randomly/intermittently. I already tried clearing and invalidating my local caches, doing an mvn clean install and depedency reimports. Still the issue persist. It also exist on the deployment of my microservice to aws. My directory structure is as follows. This BopAccountT…
Sort list of strings as BigDecimal in reverse order in Java
I need to sort list of strings comparing them as BigDecimal. Here is what I tried: Can I somehow do this without explicitly specifying the types? Answer You can do it like this. prints You could also do it like this but need to declare the type parameter as a String. But here is the way I would recommend doin…
Storing Objects of multiple classes in an Array List, then accessing their attributes
I have class of (sub)Objects And a class of Objects The Objects hold the values height and width and an ArrayList of SubObjects. This works as intended, I do however want to store multiple types of SubObjects from different classes in these ArrayLists. After a bit of googling I changed the Objects class to Th…
Java Test with coverage fails on methods that use Scanner, but the same test passess successfully if only the particlar test method is executed
I am new to Java and I have been struggling with this issue where the test with coverage fails on a method that takes input (via Scanner). The strange thing about it is that, the exact same test passes if I only run the particular test method from intellij. I have been able to replicate it to some extent in
Unable to generate interface with openapi-generator-gradle-plugin
I’m trying to generate models and controller interfaces with openapi-generator-gradle-plugin. The problem I’m having is that the plugin in generating classes instead of interfaces. A generated class looks like this: While I’m trying to generate an interface, so that I can implement it in my …
GSON flat down map to other fields
So I have an Android app which uses Retrofit for API. I have a class like which looks like: When GSON creates a JSON it looks like: Would it be possible to change JSON serialization to: Thanks. Answer Here is how Gson could be used to implement the flattening: I’ve put some comments explaining “wh…
Parsing multiple JSON objects that exist in one line in Java
I’m currently using the OMDB API, which can either return get-queries as JSON objects or XML. Working with JSON is something I’d like to learn, and it generally seems like best solution for what I’m trying to do. The implementation I’m hoping for, is to allow the user to search for a m…