Tagged Questions
0
votes
1answer
28 views
Is it possible to store all bytes from file to array of bytes?
Just as the title, is it possible to store all bytes from file to array of bytes without getting java heap space error?
0
votes
3answers
41 views
Sorting an Array of Objects throws long[] error
Im following the MKyong sort examples.
I have the class AGRinformesActivos overriding compareTo() method to sort my class by riesgoTotal double.
public class AGRinformesActivos extends EntidadBase ...
0
votes
1answer
9 views
java parentheses around class while storing reference to button
i am in aprocess of learnning java.
i have this code from java reference:-
public class ButtonList extends Applet implements ActionListener {
String msg = "";
Button bList[] = new Button[3];
public ...
1
vote
1answer
16 views
java cipher.dofinal return 0 size array
I have a problem with decrypt string.
cipher.doFinal must return byte array. Method is returning any bytes byt suze array is 0.
byte[] byteDecod;
byte[] inBytes;
try {
BASE64Decoder decoder = new ...
0
votes
4answers
41 views
Read a text file to an array Java
I know there are many questions about reading text files here but I have gone through all of them and I think I'm having some difficulty with syntax or SOMETHING because nothing that I've been trying ...
0
votes
0answers
33 views
Recursive return array of bytes in Java function
I wanted to compare two binary files using Longest Common Subsequence, but Java heap space error made me comparing the file every 2048 bytes.
The problem occured when i wanted to return the value of ...
0
votes
1answer
19 views
Android Call Filter working on my device, but not client's device
I have created a simple call filter using a for loop that goes through a database and searches for a saved number. This filter works great on my device, but when I send it to my client, it ...
0
votes
1answer
23 views
Free hand Drawring on JFrame, Color + Point[] Storage and rendering failing
I can't figure out what I've done wrong.
The program is supposed to allow free hand drawing on the one frame
and the other as a button to open the color selector.
The code for the main class can be ...
2
votes
3answers
47 views
Int array iteration?
My main goal is to iterate from a defined start location in an array to the end of the array to find the index of the minimum value then swap it with the index zero, iterating through will keep ...
0
votes
1answer
29 views
My Code Generator Won't Work Properly
So I'm trying to make a code generator that will generate setter and getter methods if you input variable names like: "int nums" or "String words" etc.
My problem is that it can only take one input
...
0
votes
2answers
35 views
Trouble with a recursive path finding algorithm java
I wrote this path finding algorithm that should be working, but I'm getting tons of java.lang.ArrayIndexOutOfBoundsException. The goal of the program is to find the shortest path from one point to ...
-1
votes
0answers
11 views
Trouble analyzing array points compared to other array points
So, for my class project I have to create a battleship game, and one of the requirements is that when you fire a missile, you can get one of four responses. You either get a miss, a hit, a "close", ...
1
vote
2answers
31 views
Recursion: Solving an imported maze?
I'm working on a maze and am stuck. Using JFileChooser, I can import and read into the maze in a .txt file, where a series of spaces and hashtags determine paths and walls. String path = " "; and ...
0
votes
2answers
23 views
Adding objects to an object array and then printing out the objects from the array
This is basically a program that adds or tries to add patients details to an object array. The patients are created in the hospital constructor.
import java.util.*;
public class Hospital {
public ...
0
votes
3answers
43 views
Array index out of bound exception for palindrome java program
Why am i getting the array bound of exception? im beginner in programming. Please help me understand. I have tried to convert the string to char array and reverse the characters and convert the end ...
-1
votes
1answer
43 views
Junit Testing error [on hold]
I have an assignment on arrays I'm working on and one of the questions is to write a code for a histogram.
The method histogram takes a positive number n indicating the number of divisions in which ...
0
votes
4answers
30 views
Not reading the first line from a text file
I have crated this method to read data from a text file. I am storing all the data which i recive from the BufferedReader inside a String array. Now when you want to read a specific data you have to ...
1
vote
5answers
45 views
Finding uniques integers in an array
i have an array of integers like this one :
A={1,1,4,4,4,1,1}
i want to count the each number once , for this example the awnser is 2 becuase i want to count 1 once and 4 once
i dont want to use ...
1
vote
2answers
25 views
Genrate jLabel code in Java
Can anyone explain me why my code doesn't seem to work? Result of this code is an empty screen.
Altough my labels array contains all and right labels. I probably miss something but can't find out ...
-3
votes
1answer
78 views
ArrayUtils has a bug? it does actually delete but
In case You want to test it your self:
[link]https://gist.github.com/anonymous/091750563384024e0ffa
[link]https://gist.github.com/anonymous/1f05cdd1d1685d103326
Everything worked fine in deleteItem ...
0
votes
2answers
52 views
Partitioning array index out of bounds
I am trying to implement a randomized selection algorithm where an array is filled with random numbers and the user selects a location and the program returns the value coinciding with the location in ...
2
votes
1answer
53 views
Shopping Cart in Java
I'm doing an assignment in which I have to have a Stamp store with a GUI, where users need to be able to add and remove items from a shopping card, then print an order receipt to a file when the ...
0
votes
3answers
39 views
Reducing the number of comparisons performed when matching between two String arrays
I am comparing three arrays of Strings using the two classes below. Without using any hash maps or changing the structure of my code too much (I can't change the signature of findMatchingElements()), ...
0
votes
2answers
14 views
Importing .txt file and saving it in to class
I'm trying to import the values stored in .txt file and store it in a class using array.
But I can't do that I'm getting ArrayIndexoutofboundException1 error.
Could you please help me with it.
My ...
-2
votes
1answer
58 views
How to read a .txt into an array
I want to read a .txt file via a Java program.
Say this is the text file input.txt
abc, test, 1,2,3
abc
abcd
test, 1, 2, 3
Each line represents a row, each comma-separated value represents a ...
0
votes
1answer
29 views
How do you incorperate an AVERAGE and LETTERGRADE in a java program which has 2D Array
I have written a program with minimal errors but do not know where I should place the Average or Letter grade function:
package org.education.tutorial;
import java.util.Scanner;
public class ...
-1
votes
1answer
26 views
Adjacency Matrix for ACM Finals JAVA
I was going through the questions they issued for 1996 ACM Regionals and I try to solve all of them. I found this interesting one about Adjacency Matrices and Connectivity matrices. Here's the ...
-2
votes
2answers
21 views
Changing a value from an array
I'm trying to change the sexe value of a person when their name is mentioned. My function changerSexe() is the function created for this process. But i keep getting this error.unexpected type line 83 ...
0
votes
1answer
41 views
Randomized Selection Algorithm
I am trying to implement a randomized selection algorithm where an array is filled with random numbers and the user selects a location and the program returns the value coinciding with the location in ...
2
votes
2answers
49 views
Formatting String Array efficiently in Java
I was working on some string formatting, and I was curious if I was doing it the most efficient way.
Assume I have a String Array:
String ArrayOne[] = {"/test/" , "/this/is/test" , "/that/is/" ...
0
votes
1answer
49 views
Java, accessing element of ArrayList of ArrayList
I did look at Accessing ArrayList<ArrayList<SomeObject>> elements but was thinking there's a more simple answer in my case. Also looked at Why does Java ArrayList use per-element casting ...
0
votes
3answers
19 views
Comparing elements of two arrays in a for loop (java)?
It seems to be a very common question relating with arrays and comparing in java, however I couldn't find the right answer in all of these for my case.
In this application I am trying to make a ...
-1
votes
1answer
23 views
QuickSort Random Pivot Not Sorting
As the title implies, I am currently working on a Java implementation of quicksort. I read in my algorithms textbook (Sedgewick text), that choosing a random pivot reduces the chance that I will get ...
-2
votes
0answers
54 views
Java: My original array values are being changed even though I'm changing them in a copy of the array
When I run this and the solution method not only changes the values in the solutionBoard array but also in the original board array. I can't figure out where I'm going wrong with this.
import ...
0
votes
3answers
70 views
repeated element in Array
I have an array of N elements and contain 1 to (N-1) integers-a sequence of integers starting from 1 to the max number N-1-, meaning that there is only one number is repeated, and I want to write an ...
0
votes
0answers
20 views
Create new variable names in each actionevent? javafx
I'm working on making a user interface using javafx that takes group names from the user. Then you can set some options for what you want to do with each group. The UI will then write a text file to ...
0
votes
0answers
39 views
parsed array only returns last object
I am parsing an array into multiple smaller arrays but the returned result to my main is the last object in the original array. I understand why it is happening but I don't know how to fix it.
Here ...
1
vote
1answer
38 views
Comparing Two Arrays within separate 2D arrays
I have two separate 2D arrays. Each contains smaller arrays that are pairs of int values. The first 2D array is the input information, the other 2D array contains values that are to be matched or ...
-2
votes
1answer
52 views
Implementing Depth First Search in Java
I have a homework where I need to implement a DFS in java.
this pseudocode was given for task 1.
DFS(V,E,s)
foreach u ∈ V
vis(u) <-- 0
p[u] <-- NULL
DFS-Visit(u)
vis(u) <-- 1
...
-5
votes
0answers
35 views
Simulating a ATM machine using a Person class, Account class and a main class [on hold]
I'm having some problems with my code, I can't get it to work properly. I have attached all three classes. Can someone please tell me what I'm doing wrong. I think my logic is wrong. The problem I am ...
0
votes
3answers
26 views
when clicked print coordinates from Points in array
I want to print out the X and Y coordinates from 3 Points in a array.
When clicked on the JFrame, the coordinates of that click need to go to the first Point p1, the second click to the second Point ...
-2
votes
2answers
36 views
The method <method> is undefined for the type string
Ok, so I have a super class with a getter method below:
public String getBorrowerID(){
return borrowerID;
}
And then I have a subclass with a new array declared as an instance variable to store ...
1
vote
5answers
67 views
How to use ArrayUtils for array of objects, it doesnt deleted the content of an array
How to delete the content of an array of objects. If there is other ways to delete a content of an array of objects , please do share.
import java.util.Arrays;
import java.util.Scanner;
import ...
-2
votes
0answers
41 views
How to obtain 4x4 blocks from a 2D array in java? [on hold]
I have a 2D array which I want to split into 4x4 blocks. And then compare 2 coefficients from each block. (eg: select coeff(2,2) and coeff(3,3) from each block and compare whether ...
-3
votes
2answers
72 views
What is wrong in this Java Code [on hold]
I have been practicing writing Java by creating the game Tic Tac Toe.
According to Eclipse, everything is fine but when i run the program and when i play, it allows one turn and returns "Player X ...
0
votes
2answers
52 views
Longest Common Subsequences of 2 Arrays of Bytes
I wanted to compare the LCS of two files from their binary, therefore i used the usual LCS source code, and using the GenStr command to change the bytes of the file to String first.
The problem is, I ...
0
votes
3answers
43 views
How to use enumMap in java
How do you use enumMap in java? I want to use an enumMap to get constant named values that go from 0 to n where n is size. But I don't understand the description on the oracle site > EnumMap.
I tried ...
1
vote
2answers
49 views
Array of float to array of double
So I need to use the class org.apache.commons.math3.stat.StatUtils, to compute the mean of an array of float, but the input array should be an array of double. How can I convert float[] to double[]??
...
0
votes
1answer
61 views
How to delete the last element from an array JAVA?
Now I'm working with the recursive backtracking,my assignment is to find the longest path in the maze,the mass is presented as the field covered with the coordinates,and the coordinates of the walls ...
0
votes
2answers
37 views
I want to loop over an int comparing it with an int array java
I want to compare an int x value with an int array data[i][j] using a do loop. data got the values 1236, 1238, 1240 and 1250. and x = 1237
my loop looks like this:
boolean go = true;
do {
if (x ...