Tagged Questions
0
votes
3answers
17 views
Java HashMap associative multi dimensional array can not create or add elements
Okay so I have spent several hours trying to wrap my head around this concept of a HashMap in Java but am just not able to figure it out. I have looked at many tutorials but none seem to address my ...
0
votes
1answer
25 views
printing array out of bounds java
i have an array of objects looking like this:
1: [volvo, 200] , [jaguar, 900]
2: [bmw, 300]
3: [skoda, 100] ,
[(no input)] , [(no input)]
this is my method to print only the areas ...
0
votes
4answers
55 views
Comparing 2 sets of integer values in 2 separate arrays
I am quite new to java and have this problem that I am struggling to work with. I have 2 sets of numbers, stored in two separate arrays, representing lottery numbers. The first set is the user numbers ...
0
votes
1answer
44 views
why this method returns only zeroes and what would make it work?
I'm struggling with the AskInfo method of the following assignment:
//Your task is to complete the program below by writing three methods (askInfo, copyInfo
//and setArray). Program should ask for ...
0
votes
1answer
53 views
The type of expression must be an array type but it is resolved to a string?
I'm trying to integrate a "Next" button in my jokes app. I'm getting the error on textView.setText(message[currentSelectedJoke]); I KNOW this error means that "message" is a string but it ...
-4
votes
8answers
74 views
Java NullPointerException error with making an array of user-defined class and initializing it
In the following code can anyone tell the error?
public class Person {
int age;
String name;
}
public class Enter {
public static void main(String[] args) {
Enter ob = new ...
0
votes
3answers
76 views
Is it possible to check if two arrays are not equal in java
I'm aware of the fact that i could just do a
while(arrays.equals(array1, array2))
And then just write the code needed in the else statement.
But is there no other way to check if they are unequal.
...
0
votes
1answer
23 views
Java XML Parsing, read's values into array correctly then overwrites entire array with last values?
I'm making a simple game, and loading an XML file with weapon stats into an array of weapons to be used in game. The stats and weapon objects are all correctly read and populated until the 'try' ...
0
votes
3answers
48 views
How to get a certain array element's key?
I'm pretty new to java, and I'm trying to create a simple method that sorts inputted numbers, either ascending or descending. However, there's a problem that I can't put in repeated values. Is there a ...
-5
votes
0answers
76 views
java help : need explanation for the code [on hold]
i have just started learning Java and this snippet is from my assignment. just need explanation for line 1 & 2 marked in the below code .. thankx in advance
@Test
public void testProblem1Usage() ...
0
votes
0answers
34 views
How to achive dynamic binding with ArrayList<T> in Java?
It looks like ArrayList in Java do not support dynamic binding. When I tried to do following code it gave compile time error.
Code:
class Value
{
<some variables>
<some methods>
...
-1
votes
0answers
30 views
Use a spinner in android to change the value of string.
I am wanting to use a class of static strings to update a string within an activity.
I have been looking through other questions and examples but I am finding it confusing as to which way is the ...
0
votes
4answers
58 views
Split into separate arrarys
All the split command I have seen split (for example) a CSV file into the 1 array.
eg
cat,feline,house
dog,canine,house
monkey,primate,zoo
Into
array[0] = cat
array[1] = feline
array[2] = ...
1
vote
3answers
58 views
Best array for this case
I have one problem of choosing which array use for this case. There are many arrays like list, colection, and others. I want to keep two numbers like this in array(numbers here is random):
(many rows ...
0
votes
5answers
72 views
Getting null pointer exception while inserting into two dimensional array of Strings
I have file named input1.txt with contents as below:
a b c d
b d
c d
d e
I want to read it and put them in 2-dimensional array of Strings. I have written code for it. But it is showing NULL ...
1
vote
4answers
66 views
Remove multiple substrings from a string - Java
I need to remove multiple substrings from a given String. Example -
String[] exclude = {"one","two","three"};
String input = "if we add one and two we get three"
I want my program to remove all ...
-2
votes
0answers
41 views
Java - Generate an array of random integers using java.util.Random [duplicate]
This is the code that I've written so far. I'm trying to generate an array of 6 random numbers between 0 and 49. For now, I'm just trying to get it to print each element of the array so I can see if ...
0
votes
3answers
60 views
Print only elements of array
i'm new in Java/Android. I create an array like this:
String [] resultArray = new String [lengthFromServ];
int i = 0;
while (i<lengthFromServ) {
...
0
votes
2answers
52 views
Generic array in ArrayList implimentation [duplicate]
Could someone please help me to make following code completely generic.
Why I'm not allowed to write private E[]store = new E[length];
import java.util.Arrays;
public class MyArrayList<E> {
...
-5
votes
1answer
38 views
Revere an array till nth number only in java
Reverse an array till the nth number for eg:
int[] num = {1,2,3,4,5,6,7,8,9};
int n = 5;
reverse num array till n and output should be :
int result = {5,4,3,2,1,6,7,8,9};
can any body help ...
2
votes
3answers
51 views
Java - Simple way to re-assign values in an array
I'm having trouble reassigning values in an array.
public static void main(String[] {
int[] ArrayOfIntegers = new int[4];
ArrayOfIntegers[0] = 11;
...
-3
votes
1answer
46 views
Java, displaying change in coins, arrays, functions?
My function ReturnChange is supposed to take in change, coins array (int Coins[] = {100, 50, 20, 10, 5};) p.s they are in cents, and numCoins array (int NumCoins[] = {10, 10, 10, 10, 10};) and ...
-2
votes
2answers
55 views
Split the String into a String array [duplicate]
How can I split the following string to an array of {"George", "Washington"};
String arr = "George\nWashington";
0
votes
3answers
27 views
Java - Calling functions in extended classes through an object array
I've got an array of objects, some of which use an extended version which contains a function not available in the base class. How can I call that function through the array when the array is defined ...
-1
votes
1answer
69 views
Why is keyword 's' giving me an error?
I have the following method which gives me an error when the word is "sk" but not when it is "ks". These keywords are coming from the arrPunjabi.
Exception in thread "main" ...
-1
votes
1answer
26 views
NullPointerException at handler.getQueryResponse(stream);
I'm getting a NullPointerException at the line :
handler.getQueryResponse(stream);
I've looked over the source code quite a few times and I'm not sure exactly why this is occurring.
Any ...
0
votes
1answer
49 views
number´s of parse strings from xml
i have a little question :).My problem is , that i parse a xml and make by every tag there are parsing a new fragment. .But now my problem:
By creating Tabs i must give the FragmentPagerAdapter the ...
0
votes
4answers
58 views
Nested loop leads to OutOfMemory Error: Java heap space
I'm trying to create an array list of string arrays containing all possible combinations of 0s and 1s, in four dimensions. That is, [0,0,0,0] is one combination and [0,0,0,1] is another. There are ...
1
vote
2answers
48 views
Array not printing on morse code program
I am very new to java and have been having trouble with my morse code program. Please bear with me, but when entering text to be translated from morse code to english it just prints null in place of ...
1
vote
5answers
76 views
Creating arraylist of arrays
I'm trying to create an array list of string arrays. When I am done, I want the array list to look like this:
[0,0], [0,1], [1,0], [1,1,]
I have tried to define an array and then add it to the ...