Most voted "java" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to the Java programming language. Java is a class-based, statically typed, reflective, and execution environment (JRE) language. Java programs are compiled to bytecode and run on a virtual machine (JVM), allowing a "write Once, run Anywhere" philosophy (WORA).
Learn more…14,468 questions
Sort by count of
-
1
votes1
answer125
viewsReturn of the clean catch code
I am reading the book Clean Code of the series of Robert C. Martin. And it was presented a very common situation in my day to day. public static void main(String[] args) { String nome = null; try {…
-
1
votes1
answer297
viewsHow to list users and their "Roles"
Hello! I need to list the level of user access on my User Query page. But I can’t access Role data through User. The User entity has the Role attribute that is mapped with the Manytomany annotation,…
-
1
votes1
answer134
viewsCannot cast from Object to int JSP
I am developing an application using JSP and servelt in which I want to get the total amount of records from my tb_driver table,created a servelt in which I passed the method that makes the query…
-
1
votes1
answer62
viewsI can’t generate that second vector
Write a program that loads a vector with 10 integers and sort it in ascending order using the Bubble Sort method. The program must generate a second vector without repeated numbers. package…
-
1
votes1
answer312
viewsProblem generating random value using Random class
The program is generating a random value, but sometimes it pops the array, or simply displays nothing. Examples of the error: My code: import java.util.Scanner; import java.util.Random; public class…
-
1
votes2
answers461
viewsConvert JSON to Array in java
I have a JSON that represents a test query: {"dctitle":"TestesStatus", "oslc_cmtotalCount":2, "oslc_cmresults": [ {"dctitle":"33643640", "rdfabout":"XXXXXXXXXXX", "dbid":"XXXXXXXXXXX",…
-
1
votes1
answer667
viewsHow to prevent a variable from going negative in Java?
I’m making an application for Android in Android Studio where there is a list of items, where you can choose to increase or decrease the amount of each item, so for this I created two buttons for…
-
1
votes3
answers91
viewsRegistration error "Does not recognize the property"
I’m studying Java EE and I came across a mistake, if anyone knows the answer I appreciate it. I have my form: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"…
-
1
votes2
answers677
viewsjava.lang.Nullpointerexception JSP Servlet
I’m developing a web application using jsp and Servlet and I want to show all my records from my database and the amount of records in a table, I created a DAO in which I performed the queries in…
-
1
votes1
answer65
viewsRemove subArray from a Main Array
I have two main Arrays (listaInformacoesNota,listaInformacoesPedidosPostgreSQL) with N subArrays each, these subArrays have items in common and a different item only, I did the following to compare…
-
1
votes1
answer251
viewsHow to know if the cursor is on a certain component in javafx
I have a component in javafx and would like to know if the cursor is positioned on it. There is a function for this? I tried to create a boolean that stores it using the events setOnMouseEntered and…
-
1
votes3
answers3370
viewsHow to convert Date to whole in Java?
When I use this code: Date data = new Date(); SimpleDateFormat formatador = new SimpleDateFormat("dd/MM/yyyy"); int dataAtual = Integer.parseInt(formatador.format(data));…
-
1
votes1
answer143
viewsError sending files via Java Socket
Java server. package javaapplication48; import java.net.*; import java.io.*; public class Servidor { public static void main(String[] args) throws IOException { ServerSocket servidor = new…
-
1
votes2
answers1378
viewsRead java strings within a while or do-while repetition structure
How do I read java strings within a while or do-while? repeat structure without error and reads Code: package listas; import static java.lang.System.exit; import java.util.ArrayList; import…
-
1
votes1
answer465
viewsPosition Jpanels vertically
I am trying to add 4 panels, so that they are below each other. So, I decided to use the BorderLayout, together with the "positioning" (NORTH, SOUTH etc.), pass a index, however, he ends up skipping…
-
1
votes1
answer1572
viewsSearching another method variable of the same Class
I have a class BancoDeDados and it contains two methods: conexao and addDespesa. The method conexao connects to my local database. The method addDespesa adds values in one of my tables, but cannot…
javaasked 7 years, 9 months ago Goji Berry 77 -
1
votes2
answers155
viewsHow not to lose the decimals when doing "longProperty1.divide(longProperty2)"?
What I want to do is very simple, I just don’t know how to "do it right" in Javafx: I have two Longproperty (num1 and num2) and a Doubleproperty (resultado), where this Doubleproperty resultado must…
-
1
votes0
answers56
viewsSet method does not work for filling object array
I created a class Funcionário, and in class Main create an array of objects of this type. I am now trying to set the attribute "position" of employees in a loop, but gives NullPointerException...…
-
1
votes1
answer496
viewsHow can I change a label that is on a javafx gridpane
Good afternoon community, Lately I’ve been exploring the javafx aspect and creating an application for my master’s degree. Briefly, the application receives an image from the user, and creates a…
-
1
votes1
answer65
viewsHow to define a data structure in Json, with the name of the object at the top of the structure?
I am working on json and I really need to get this structure: { "Identidade": [ { "numero": 1704, "numeroFinal": 1804, "id": 28 }, { "numero": 1806, "numeroFinal": 1905, "id": 28 }, { "numero":…
-
1
votes1
answer288
viewsAccess a textField that is inside a gridPane in javafx
I have been developing a master’s degree in javafx: something that receives an image, puts a grid with textFields on all cells above the image. The user can then put values in the textFields. The…
-
1
votes2
answers1829
viewsHow to find a String inside an Arraylist
I have difficulties in using the Arraylist class, more specifically in the search for a String. The point is, my code even works, but when I register more than two books inside Arraylist, at the…
-
1
votes0
answers14
viewsExtremely slow application after implementing Dozer lib
I have a JSF application. I have just included a layer of Dtos and I need to transfer the values from Entities to Dtos and vice versa. Searching Google, found lib recommendations Dozer in the Soen.…
javaasked 7 years, 9 months ago igventurelli 4,441 -
1
votes2
answers1278
viewsPass product list to another Activity
Hello, I am learning and I wanted the suggestion of you, in a simple way at first, how to make this passage of products to another Activity. The application I’m developing it loads a list of…
-
1
votes1
answer47
viewsHow to get value returned from Get using Volley on android
In case I want to know how to get only the GET value of the link ".../posses_cadastro" to enter If or Else. public class LoginRequest extends StringRequest { private static final String…
-
1
votes0
answers212
viewsInheritance attributes using abstract class
I’m looking to use inheritance with parent class being abstract. The point is that I’m using the toString() superscript so that each print of child classes can print their respective data. But when…
-
1
votes1
answer52
viewsError including name attribute in @Webservice
I am creating the class that implements the WS call and when trying to include the name attribute, this error appears: "@WebService annotation contains an endpointInterface attribute. No name…
-
1
votes1
answer1320
viewsJAVA - Generate a random & scrambled word
I intend to generate a randomized, scrambled word from a vector. It’s already generating a random word, but it’s not scrambled. I created a method called Scramble where the words will be shuffled…
-
1
votes1
answer118
viewsCalling non-static function inside a Handler
I’m developing a code in android studio in which I receive data through a buetooth transmission. The data goes to a function called Handler, which is Static. public static Handler handler = new…
-
1
votes1
answer419
viewsDate to oracle conversion
I’m having a problem, I’m trying to save a date on oracle with formatted dd/MM/yyyy, however, in the bank it presents the date in the format dd/MM/yy. So, I got the question, if the type I used in…
-
1
votes1
answer54
viewsGenerate numbers based on the index in the array
I need to generate random numbers within a range... so far so good, however, I need to do this for each position of the array, for example, at position 1 of my array, random numbers should be…
-
1
votes1
answer771
viewsHelp with simply chained java list
I have a package with the codes below to implement a Simply Chained List. Apparently everything is correct in the classes, but when I run my main I get back what I believe to be the memory reference…
javaasked 7 years, 9 months ago Cléo Sousa 123 -
1
votes1
answer271
viewsDouble chained list with remove method that does not work
I have this algorithm for a double-chained list, but I get an error in the last interaction on both methods of removing. Any idea what might be wrong with my methods? Main class public class…
javaasked 7 years, 9 months ago Cléo Sousa 123 -
1
votes0
answers72
viewsError while consuming REST service. Attribute exists
Does anyone know the reason for the error below, when trying to access consume a webservice? It was working normal, and started to present this error. I already did Refresh in the classes, there was…
-
1
votes3
answers932
viewsCurrent or formal argument lists differs in length
I have the following code snippet: import java.util.Random; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import java.io.*; import…
javaasked 7 years, 9 months ago Diana Madeira 485 -
1
votes2
answers108
viewsWhy don’t you instantiate the list so it doesn’t accumulate?
I have the following class: public class TesteLista { public static void main(String[] args) { List<String> dados; Teste1 t = new Teste1(); dados = t.getList(); System.out.println(dados); } }…
-
1
votes2
answers201
viewsJson created incomplete
Next people had a loop problem in my project when creating Json the application looped. I was able to solve the loop problem with the @Jsonmanagedreference, @Jsonbackreference annotation. However,…
-
1
votes1
answer106
viewsJava code works on Mac, but not on PC
The following code works on my mac and not on the pc. I really need to get to work on the pc, so I appreciate any help you can give me. I’m using Eclipse Java Oxygen on both platforms. Code: import…
-
1
votes1
answer92
viewsProblems with hashmap getordefault in java
I have a hashmap problem, in JAVA. I’m trying to create a program that reads data from a car, save these cars in an Arraylist and organize, by the manufacturer(that would be the key) the cars of…
-
1
votes1
answer63
viewsReturning different messages according to the results of a function
I have the following doubt: I have a function that can give me four different values. I would like to create a message (string) for each function value, so that the message is released with its…
-
1
votes0
answers124
viewsJava - When(). Thenreturn() Mockite Function
@Mock RequestUtils requestUtils; @Before public void init() throws IOException, ClassNotFoundException { MockitoAnnotations.initMocks(this); HtmlPage paginaPesquisa =…
-
1
votes1
answer463
viewsHow to merge <h:column > columns in JSF?
How can I merge columns or rows in JSF 2.0 ? Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html…
-
1
votes1
answer139
viewsHow to use a Jcombobox of one class in another?
I want to create two screens, one registers the values of Jcombobox and the other I use the values. I can get the Combobox back but there’s no value. Class of register public class Combo extends…
-
1
votes0
answers909
viewsHow to run (interact) prompt commands by Java?(Linux and Windows)
Hey, you guys. I need to develop a java program that runs commands as if it were on promt/cmd, and in a way even interact with it. Do you know when we run some kind of command at the prompt and it…
-
1
votes1
answer726
viewsp:inputText is not updating
I have in the following code, a form that works both to change and to add an entity. The logic is this, I have a variable alteracao. if alteracao == true the form will behave to change if alteracao…
-
1
votes0
answers95
viewsInserting Script in Android Code for Searchview Search
I’m developing an Android app that works with the Google Maps API, and in it I have a searchView that needs to search the typed location and display on the map. But I do not know how to insert a…
-
1
votes1
answer3293
viewsIllegal Attempt to map a non Collection as a @Onetomany, @Manytomany or @Collectionofelements
Good night. I have the following mistake in Hibernate: org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements:…
-
1
votes1
answer633
viewsGroup List with java 8
The input data would be a list of Products as below [ { "id": "123", "ean": "7898100848355", "title": "Cruzador espacial Nikana - 3000m - sem garantia", "brand": "nikana", "price": 820900.90,…
-
1
votes1
answer981
viewsPOST request with Okhttp in JAVA
My question is like this, I’m using Postman to simulate these requests, then when I choose there to show the code as it would be in java shows this code below, but full of "strange characters" like…
-
1
votes1
answer406
viewsjava.lang.Indexoutofboundsexception: Invalid index 4, size is 4
I’m not sure what’s going on, when I long click on a list item, it sometimes works normally (open a screen where it shows the user the registered information, allowing them to change it), sometimes…