Posts by Victor Stafusa • 63,338 points
1,321 posts
-
3
votes1
answer7738
viewsA: How to validate multiple fields in a form?
First, let’s simplify your code: function null_or_empty(str) { var v = document.getElementById(str).value; return v == null || v == ""; } function valida_form() { if (null_or_empty("numeroPedido")…
-
7
votes1
answer525
viewsQ: How to determine if a point of a swing component is visible on the screen?
How do I determine if a certain point X within a swing component is visible on the user screen? For example, let’s assume that the JComponent To was added to a window B (normally, but not…
-
1
votes3
answers1511
viewsA: How to send an object via SOAP web service
I don’t know if this is the correct answer, because I have no way of testing what you are doing. But I will try to answer anyway: java.lang.Runtimeexception: Cannot serialize: Person{name=given,…
-
5
votes2
answers2937
viewsA: Best Way to Use and Instantiate Entitymanagerfactory
Here are the golden rules: You must have a EntityManager by interaction with the database1. You must have a EntityManagerFactory by database in the application (persistence Unit) and for…
-
15
votes1
answer10040
viewsA: How to Stop a Thread?
Thread stop.() There is the method Thread.stop() which has this purpose. However it is obsolete (deprecated). It still works if used, but there are strong reasons for not using it. When a thread is…
javaanswered Victor Stafusa 63,338 -
6
votes2
answers1215
viewsA: Why create an interface for each DAO?
The main advantage is the evolution and modularization of the system. We have two possible approaches: Create 20 interfaces DAO with 5 or 6 methods each, you have interfaces UsuarioDAO, PedidoDAO,…
-
3
votes1
answer120
viewsA: How to resume all students with a common name
Your first problem is here: if (name == student.name) This will then check if the two pointers are pointing to the same memory address, which will never happen. What you wanted is to compare if the…
-
1
votes2
answers108
viewsA: When starting an application, perform Windows task
Let’s assume you want to run the y.exe whenever the x.exe is executed. What you can do is: Rename the x.exe for z.exe. Create a new program x.exe to execute both, the z.exe and the y.exe, passing on…
windowsanswered Victor Stafusa 63,338 -
1
votes1
answer161
viewsA: Track #hash and create description from it [LOGICA]
Assuming the question is actually on-topic and not based on opinions (I’m not entirely sure, but I’m giving you the benefit of the doubt), it seems to me that what you want is to implement in PHP…
-
2
votes4
answers1177
viewsA: How not to repeat terms on printf
You can change your loops to check if it is not a repeated number: // Percorre o vetor a. for (i=0; i<5; i++) { // Percorre o vetor b. for (j=0; j<7; j++) { // Se o número está em ambos os…
canswered Victor Stafusa 63,338 -
1
votes4
answers274
viewsA: Problem checking prime numbers
Let’s see your code, in the part where you test yourself n[i] is cousin: for (j=2; j<n[i]; j++) { if (n[i]%j==0) {} else printf("O numero %d e primo\n",n[i]); break; } Let’s see what happens when…
canswered Victor Stafusa 63,338 -
1
votes2
answers431
viewsA: Help to determine vector/matrix size - C language
To know the file size, you can go to the end of the file and then get the position: fseek(fp, 0L, SEEK_END); sz = ftell(fp); And then, you can go back to the beginning of the file: fseek(fp, 0L,…
-
0
votes2
answers431
viewsA: Help to determine vector/matrix size - C language
If the entries have a defined and unique size, all you have to do is take the file size and divide by the size of the input. The result is the number of entries. If the size of the entries varies,…
-
10
votes2
answers1484
viewsA: Compareto: Comparison method violates its general Contract!
First, the method of getEndSLA should return a Date, or at least have some other method that does so, to improve object orientation. It should not be the responsibility of the comparison method to…
-
4
votes2
answers86
viewsA: Application closes at the touch of the button
Your mistake seems to be coming from these lines: rcpNum = Integer.parseInt(rcpTxt.getText().toString()); fckNum = Integer.parseInt(fckTxt.getText().toString()); abtmNum =…
-
3
votes1
answer591
viewsA: how to compile java application and generate your Bytecodes
Let’s assume you have your project in a folder teste and its archives *.java are in the folder src (with several subfolders corresponding to the packages), and you want to put your files *.class in…
-
2
votes1
answer195
viewsA: Get url of next page with javascript
The methods history.go, history.back and history.forward have no return value. The purpose of these methods is to navigate the page history, and not know what such history is. If it were possible to…
javascriptanswered Victor Stafusa 63,338 -
1
votes1
answer1026
viewsA: Map objects through Hibernate with "decentralized" data
For the table name, you can use the annotation @Table. You can also use @SecondaryTable or @SecondaryTables if the entity is divided into several separate tables. You can use @Inheritance,…
-
4
votes4
answers3497
viewsA: How to prevent the user to enter numbers for a given data?
Assuming you’re using console, you can do something like this: public static String lerNome(String mensagem, Scanner scanner) { while (true) { System.out.println(mensagem); String lido =…
-
3
votes1
answer96
viewsA: Build error using Audioplayer class
Your problem is with Rts: import sun.audio.*; import com.sun.java.util.*; The packages sun.*, sunw.* and com.sun.* are proprietary and internal JDK packages that should not be used by applications,…
javaanswered Victor Stafusa 63,338 -
2
votes1
answer332
viewsA: Problem when doing String Code and Discovery
Your method long2str is wrong: String s = Arrays.toString(chArray); This then does not do what you want. For example: System.out.println(Arrays.toString(str2long("Hello World"))); Show that: [83,…
-
1
votes1
answer1005
viewsA: Trouble with hangman play
Let me reformat your javascript: var palavra = new Array(); var controlando = 0; var cont = 0; var tracos = []; var conpt = 0; // controle var jogadas = 5; function preencher(valor) { var elemento =…
-
4
votes1
answer278
viewsA: Program does not read file data properly
I think your problem is here: arquivo1 = fopen("medico.dat", "r"); ... arquivo3 = fopen("consulta.dat", "w"); I think you should wear rb and wb instead of r and w. Or else some other way like ab,…
canswered Victor Stafusa 63,338 -
1
votes1
answer921
viewsA: Error while printing chained list
First of all: void imprime(celula *inicio){ celula *pont; for (pont = inicio -> prox; pont != NULL; pont = pont->prox) printf (" %d\n", pont->nodo); } The right thing would be pont =…
-
1
votes1
answer159
viewsA: Jtextfield validation
Your problem is a very silly mistake. He’s here: (txtServicoValor.getText().replaceAll("\.", "").replace(",",".")).equals(campoTexto) This here is a String:…
-
6
votes2
answers178
viewsA: Does PHP work within Javascript?
No, what you’re trying to do doesn’t work. The reason is that PHP is processed on the server before the page is generated. After PHP has finished processing, it is sent to the client’s browser, and…
-
1
votes1
answer156
viewsA: Insert the Password to continue
It seems to me that your mistake comes from here: day = T_FechaSalida.getText().substring(0, 2); That is, the countryside T_FechaSalida has not been filled in correctly. You are not testing anywhere…
-
10
votes1
answer9847
viewsA: How to create string vectors in java?
First, note this part: for (j=0; j<m; j++) { d[i] = ent.nextLine(); } You iterate the variable j, but accesses the array using i. This is wrong. To avoid errors like this, it is recommended to…
-
1
votes1
answer952
viewsA: Structure maze in C
Suppose you use a character to represent a position on the grid, where a blank is a free path and X is a wall and other objects are other characters: const char caminho = ' '; const char parede =…
-
6
votes2
answers6555
viewsA: How do I check if two strings are anagrams of each other?
I think of three ways to do that. The first way is to count the frequency of each character for each String and then compare frequencies. The second way is to sort the letters of both Strings and…
-
5
votes2
answers360
viewsA: Put method return before a "Finally" block
The output will be: Parte 1 Parte 2 And then false will be returned. The block finally executes whenever the block try ends, even if he has released an exception, returned, aborted a loop or…
-
4
votes2
answers6174
viewsA: How to count the frequency of each letter in a string?
Note that your if that’s inside the for external, runs once for each letter of String, no matter if this letter has been told before or not. You will need to check whether the letter has been used…
-
3
votes1
answer642
viewsA: Label is not displayed
Your problem is you seem to have forgotten this: getContentPane().add(txt_status); To be put right after that: txt_status = new JLabel(this.status); txt_status.setForeground(Color.RED);…
-
3
votes1
answer299
viewsA: How to record multiple information in multiple classes using only one save class?
Your code has a long series of problems. Let’s try to fix everything. First step: We have to avoid this code copied and pasted everywhere: final JCheckBox Teclado = new JCheckBox ("Teclado");…
-
0
votes2
answers984
viewsA: Error compiling project in QT Creator
Your mistake basically is this: /usr/bin/ld: cannot find -lGL At this link, I found the following tip: sudo apt-get install libglu1-mesa-dev -y Another tip I found on this other link. Take a look at…
-
0
votes2
answers634
viewsA: Problems inserting values in vector pointer
I think your code should be this: #include <stdio.h> #include <conio.h> int main() { char v[20]; for(int i = 0; i < 20; i++) { char c; scanf("%c", &c); v[i] = c; } for(int i = 0;…
-
3
votes1
answer116
viewsA: Stop the loop when you find a result
Let’s see your code: public Objeto busca(String nome){ for(Objeto id : MinhaLista){ if(id.getNome().equals(nome)){ return null; } else { return id; } } } When it starts iterating the first element,…
-
1
votes1
answer239
viewsA: Interleaved matrix
First of all, you’re reading n twice, but you should read n, m and p independently. Then the most problematic section is this: for(int i=0; i<n; i++){ for(int j=0; j<(n+n); ){ q[i][j] =…
-
2
votes1
answer1930
viewsA: Calculation of hours with Java 8
It seems to me that the three forms are correct and are equivalent. However, it seems to me that all three will fail if there are daylight saving or time zone changes.
-
1
votes1
answer153
viewsA: Doubts in the creation of my App
I need to create a way, to show on the customers screen, the "vendors" that are around at the time when he accesses the application, as the "vendors" are not fixed locations, are like the taxis of…
-
1
votes1
answer88
viewsA: Events and changes in a JSP?
A simple way would be to use an AJAX Poster. Something like this: function alguemDigitandoAlgo(dados) { // ... Aqui é com você. } (function pollServerForNewMessage() {…
-
0
votes4
answers1206
viewsA: Java Class Scanner Loop Error
Here’s a Gambi to solve your problem. Change this: nomes[i][0]=entrada.nextLine(); That’s why: String lido = null; do { lido = entrada.nextLine(); } while (lido == null || lido.trim().isEmpty());…
-
1
votes1
answer205
viewsA: Transform javax.persistence.Query to Arraylist
I think return one javax.persistence.Query doesn’t seem like a good idea, if I understood your case correctly. Nothing would stop the caller from invoking methods like setParameter, getResultList,…
-
6
votes3
answers1337
viewsA: In what order is a Set stored? Random?
The Set is just an interface. The order depends on the implementation. The HashSet has no guarantee of any order. In practice it is random. The LinkedHashSet maintains the order in which the…
-
1
votes3
answers851
viewsA: Regular expression to find word exception
I managed with a somewhat complicated javascript function: function localizaRecursoes(codigo) { var regex = new…
regexanswered Victor Stafusa 63,338 -
5
votes3
answers937
viewsA: Operators, order, relevance, how it is read and priority
The operator != is not the same thing as <. The operator != means inequality, while the < means smaller-than. According to this here, this is the precedence of operators: Precedence 1…
-
1
votes1
answer518
viewsA: Sending characters through the serial port including zero-value bytes
Your problem is in the instruction you are using: WriteFile(hComm,Buffer,strlen(Buffer),&bytesEscritos,NULL); Note that the strlen will return the size to the first byte with zero value and…
-
0
votes2
answers299
viewsA: Sudoku does not print answers on screen
It seems to me that your code is "almost there". Use fprintf to write to a file. It works the same way as the printf, but it has one more parameter than the file. Remember to use fclose to close…
canswered Victor Stafusa 63,338 -
3
votes1
answer2424
viewsA: Read file in binary
You are saving a bit pattern that represents numbers. However, in PPM format, you must save the numbers as text. That is, use fprintf instead of fwrite. For reading, you can try using a fscanf or a…
-
2
votes1
answer57
viewsA: Generating objects with a certain value within a defined distribution
If your difficulty is creating the objects, try this: import java.util.ArrayList; public class Porcentagem { private final int valor; public Porcentagem(int valor) { this.valor = valor; } public int…
javaanswered Victor Stafusa 63,338