Posts by Victor Stafusa • 63,338 points
1,321 posts
-
0
votes2
answers50
viewsA: Random on button with isEmpty();
First, you should just create the Random once and then reuse it: private static final Random random = new Random(); Second, this line should not do what you want:…
-
2
votes1
answer84
viewsA: How do I get my Program to access the net?
Try this: import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class ApitaQuandoCaiInternet { // Método que verifica se a…
-
1
votes1
answer64
viewsA: Problems with cast in Reflection
First that line: private Class classe; Could be: private Class<? extends E> classe; Then we see that your method inserir closes the object db, but it was not he who opened it. As good…
-
3
votes2
answers760
viewsA: Help with mysql Kurdate()-1
I think what you want is this: SELECT category.*, event.* FROM category INNER JOIN event ON event.category_id = category.id WHERE category_id = 7 AND event.date_at = DATE_SUB(CURDATE(), INTERVAL 1…
-
4
votes1
answer577
viewsA: How to install a java application with a Mysql database?
Let’s assume that you have published your Mysql server on the host bd.example.com, on the standard Mysql port (3306) and that the user is fulano, the password is senha123 and the database is called…
-
2
votes1
answer871
viewsA: Return of a binary search
Your code has several problems. First you do checks such as (meio>valor) instead of (v[meio]>valor). This is important, because if you notice well, at no point in your binary search you are…
canswered Victor Stafusa 63,338 -
3
votes5
answers7439
viewsA: Exercise with odd pairs in C
Your mistake is here: printf("Pares -> %d\n", &qpar); printf("Impares -> %d\n", &qimp); Take these off &. You do not want to show the addresses of the variables, but the values.…
canswered Victor Stafusa 63,338 -
2
votes2
answers284
viewsA: Screen to configure Mysql connection
How about using a Factory pattern with getters and setters? public class MySqlConnectionFactory { private String host; private int porta; private String database; private String usuario; private…
-
-1
votes4
answers1255
viewsA: Index returning -1 in Java Arraylist
Your mistake is, as others have said, that you don’t seem to have understood the indexOf. He doesn’t do what you want. To understand how it works, here’s an example: List<String> lista =…
-
1
votes1
answer68
viewsA: Problem after applying a patch to generate random names in ffmpeg
I don’t know if that answers the question, but it’s gotten too big for a comment. Right off the bat, I notice randstring(0) returns an uninitialized pointer, which is dangerous. I think, but am not…
-
1
votes1
answer133
viewsA: Convert assignments from C++ to C
I’m guessing that cacheconfig.numLines, cacheconfig.associativity and cacheconfig.lineSize are of the type unsigned int. If they’re not, maybe you’ll need a cast somewhere, or you can change them to…
-
3
votes1
answer193
viewsA: Show warning message without exception
I don’t think so. In general, nothing that occurs on the SQL server is shown by the user, and all access to the database is performed through software that constitutes the application. This means…
-
3
votes1
answer52
viewsA: Java Array: no value received
You don’t say in the question what the mistake is. What you’re having is a NullPointerException. The assignment formulas you use are not the problem and are correct. The reason for error is because…
-
2
votes1
answer508
viewsA: Break java loop
AWT and Swing have a thread that manages their operation, it is called Event Dispatch Thread - EDT. As she is a unique thread, if you make her fall into a while (true) and/or in a…
-
1
votes1
answer516
viewsA: Creating music player application with Jlayer
The NullPointerException is coming from the class builder Bitstream. That is to say, from here. According to the source code of the class BitStream: public Bitstream (InputStream in) { if (in ==…
-
13
votes1
answer12115
viewsA: What is referential integrity?
Referential integrity is a concept related to foreign keys. This concept says that the value that is a foreign key in a target table must be the primary key of some record in the source table. When…
-
0
votes1
answer246
viewsA: How to declare the final result as variable in a repeat structure in Visualg?
Place after the Fimse: N4 <- N1 Escreval ("Número no final ", N4)
-
5
votes4
answers640
viewsA: Java abstract class exercise doubt
You can override the method toString() class FuncionarioAbstract. Take an example in this other answer of mine. Would look like this: @Override public String toString() { return getNome() + " - R$ "…
-
4
votes1
answer3011
viewsA: Error Code: 1215. Cannot add Foreign key Constraint
Try to do so: CREATE DATABASE escola2; USE escola2; CREATE TABLE IF NOT EXISTS aluno ( matricula INT NOT NULL auto_increment PRIMARY KEY, nome VARCHAR(25), sobrenome VARCHAR(30), cod_curso…
-
5
votes2
answers466
viewsA: Comparing words from a text to an Enum’s list
You don’t need to define the name that way because everyIn has a method name() that does exactly what your getNome() ago. In addition, every Enum has a method valueOf(String) that makes a part of…
javaanswered Victor Stafusa 63,338 -
1
votes3
answers289
viewsA: Error Segmentation fault without indentification
Friend Emoon found the first part of the problem in his answer, that the fgets puts a \n at the end of the string read and need to give free in each of the strings allocated. As for this \n, the…
canswered Victor Stafusa 63,338 -
0
votes1
answer77
viewsA: Processing 3.2.1, Game Control Plus library, java Exception
This is a thread problem. The ControlIO uses its own thread to receive input, as evidenced by: at org.gamecontrolplus.ControlIO.run(Unknown Source) at java.lang.Thread.run(Thread.java:745) However,…
-
2
votes1
answer309
viewsA: Connect to oracle 11 c
First, Oracle XE uses the default port 1521. Port 3128 is normally used by Squid. Unless you have changed the door on purpose, this is probably not the correct number. Do not confuse the port used…
-
1
votes1
answer65
viewsA: pdf export of a web application, error: org/apache/poi/ss/usermodel/Workbook
Notice what we have in your stacktrace: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook That is, Java could not find the class Workbook which is used by your project. This error…
-
0
votes1
answer48
viewsA: Application problem read xlsx file in centos error: libgcc_s.so. 1: Wrong ELF class: ELFCLASS64
The problem Install a 64-bit JVM. Your JVM is 32-bit, but your library and VM are 64-bit, so it’s better to have the JVM also 64-bit because it’s not worth having a headache with these differences.…
-
5
votes2
answers9758
viewsA: Pass matrix as pointer
I understand the code - first alternative Look at that line: matriz_ponteiro(mtr[3][4], lin, col); lin and col are of the type int. mtr is a 3x4 matrix of the type int, and therefore mtr[3] is an…
-
3
votes3
answers1602
viewsA: How to add a database column using PDO
Use the following SQL query: SELECT SUM(valor) AS total FROM minha_tabela See more details on how to use SUM here. Then in the PDO you do this: $soma = $pdo->query("SELECT SUM(valor) AS total…
-
8
votes2
answers99
viewsA: Doubt about List that does not return the result
You must override the method toString() class alunos. For example: @Override public String toString() { return nome + " (" + matricula + ") - " + curso; } The method toString is the method…
-
2
votes1
answer89
viewsA: Click on the screen and change the values of the variables
This question is old, abandoned and poorly formulated, but it is still responsive. The problem is that basically there are two variables called ic. The ic from within the main is what is rendered on…
-
4
votes1
answer843
viewsA: Problem with Eratosthenes sieve - JAVA
Your algorithm is almost right. You just made a silly mistake in findPrimes(): for(int i = 2; i <=primes.length; i++){ for(int j = i; i*j <= primes.length; j++) In those two ties, it was to…
javaanswered Victor Stafusa 63,338 -
4
votes1
answer363
viewsA: Save and load objects inside a list
Do so: public static Map<String, String> cash_player = new HashMap<>(); public static synchronized void save() { File f = new File(plugin().getDataFolder(), "cash.dat"); if…
-
3
votes2
answers716
viewsA: Converts String to int Arduino in C
The first thing I see wrong is in your job Desligado: void Desligado (int x,int y,int z,char st1,char st2,char st3){ if ( st1 == 'l' ) { digitalWrite (x,LOW); } else { digitalWrite (x,HIGH); } if (…
-
2
votes1
answer62
viewsA: Error removing element from a chained list in c
Your mistake is quite clear, you are passing an integer where a pointer is expected. This is the excerpt from your main that presents this problem. Note that the second parameter of retiraLifo is a…
-
6
votes2
answers818
viewsA: Pixel distribution algorithm
Want something like the one below? Click the blue button to run. function agrupar(antes) { var depois = ""; for (var i = 0; i < antes.length; i++) { var a = i === 0 ? "A" : antes.charAt(i - 1);…
-
3
votes1
answer571
viewsA: How to change the Jtable header background without removing the edge?
Try to put this: @Override public Component getTableCellRendererComponent(JTable jTable, Object value, boolean selected, boolean focused, int row, int column) {…
-
1
votes1
answer79
viewsA: Execution time of arrow problem
You can make several improvements. Let’s start with the simplest: Avoid using variavel = variavel + 1. It is simpler and less prone to errors use variavel++. Avoid using global variables as they are…
-
8
votes1
answer234
viewsA: What does this program do in Java?
BE CAREFUL WHEN EXECUTING THIS CODE THAT PROGRAM IS A VIRUS What does he do: Detects the Locale and refuses to do anything if it does not detect that the operating system is configured as being in…
javaanswered Victor Stafusa 63,338 -
19
votes3
answers1336
viewsA: Is it ideal to use primitive types in Java?
The new features that have been added to Java 9 are: Jshell - A Java command interpreter. Javadoc with HTML 5 and search using jQuery. Simplification of cross-compilation (cross-compiling) for older…
-
8
votes4
answers2317
viewsA: What is the use of Exclamation Mark (!) before declaring functions in Javascript?
Note this code: !function (){ return true; }(); This is what he produces: false Already that other code: !function (){ return false; }(); Produces this: true That is, it reverses the function…
javascriptanswered Victor Stafusa 63,338 -
4
votes1
answer365
viewsA: Insertion Sort (Sorting by insertion)
In general, sorting is used in practice when the data set to be sorted is small or almost ordered. Sorting insertion requires an amount of permutations proportional to the square of the number of…
-
3
votes3
answers1208
viewsA: Doubt in the extraction of recursive Fibonacci equation
The Fibonnaci sequence is the one where each term is equal to the sum of the previous two terms. Now, if each term is the sum of the previous two, then: T(n) = T(n-1) + T(n-2) By the way, that’s…
answered Victor Stafusa 63,338 -
6
votes2
answers176
viewsA: Why am I getting Segmentation fault dynamic matrix?
Notice that line: float **matriz = malloc(tamanho * sizeof(float)); whereas tamanho is 5 and sizeof(float) is 4, that would be: float **matriz = malloc(20); And then here, we have this: for(int i=0;…
-
3
votes2
answers2034
viewsA: How do I compare two strings in c
Note this expression: if (nome[0] != binario[contador]) The result of this will be the comparison between the address of two memory pointers. These two addresses will never be the same, and…
canswered Victor Stafusa 63,338 -
1
votes1
answer309
viewsA: Error in field validation
Your mistake is simple. See in your entity: @Pattern(regexp = "[0-9]*", message = "Atenção, digite somente números") private Integer numero; The annotation @Pattern shall not be used in fields of…
-
2
votes1
answer139
viewsA: Error while publishing Java 7 - Java 7 vs Java 8
The important part of your mistake is this: Unsupported major.minor version 52.0 The version major/minor number 52 corresponds to Java 8. Since you are running on a Java 7 JVM, then it will not…
-
4
votes3
answers1866
viewsA: Formatting date in Java web with Primefaces
Place a specific getter in your entity: public String getDataInicioFormatada() { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setLenient(false); return…
-
26
votes2
answers885
viewsA: To what extent should I follow the conventions, where can I apply specific style patterns of my own?
In fact, what is the same rule is what is imposed by the compiler, the rest is convention. There are in practice two conventions in force. In particular, the Eclipse community tends to have a…
-
15
votes2
answers4597
viewsA: What are the differences between HTTP 1.1 vs HTTP 1.0?
Method OPTIONS - The HTTP method OPTIONS was entered in HTTP 1.1, and allows metadata to be obtained about a resource (URL), including which methods are allowed in it. The header Host - This header…
-
4
votes1
answer650
viewsA: Why does this method generate java.lang.Stackoverflowerror?
Observe the code: ArrayList<Eleitor> eleitores(){ return eleitores(); } Let’s see what this method eleitores() ago: First, he calls the method eleitores(), which in turn will call the method…
-
4
votes1
answer554
viewsA: Class or the Enum?
Where it’s good to use Enum? The idea of using an Enum applies in the following cases: It is a fixed set of elements. None can be created or destroyed. The elements are immutable. That is, their…