I’m making my own solitaire program I can run on my computer (for leisure and practice) and I am trying to display my ‘ArrayList<Card>[] playspace’ like it shows in Solitaire. More specifically I’m trying to display the card order downward instead of to the right side like it currently is. Following is my entire program (necessary classes needed to run).
Tag: arraylist
Method that fills the gap between an ArrayList in Java
I’m making a method called fillList. The method will require an arrayList in order to work and the output will be void. What the method is supposed to do is to fill the gaps between the numbers of the List. Example: Input: Output: The code I have so far is this: My idea was to add 1 to the value
How to write a JUnit test case for ArrayStack methods
I am implementing an ArrayStack and we have to create a tester for it with JUnit and I wasn’t sure what to add to check if these two methods are working. The method addAll appends all values from the given list into the other list. Equals checks if two ArrayStacks are equal. I think I would have to create another
App crashes when adding to an ArrayList in a for loop after first succeeful add
Still new to android and java but getting there, here is my problem. The crash occurs at this point fieldsA.add( A.substring(_start, _a[i])); it works the first time but not the second time, I do not get an error in my debug window, just a crash. // number of chars to extract from string value to add to ArrayList. int _a[]
method in class cannot be applied to give types when using generic methods
I have this code that is meant to count all duplicates in any given generic type list If I were to uncomment the header that takes int[] instead of T[], then it works perfectly fine. However, once I try to use a generic type I get the error: Why is this? Shouldn’t int[] be considered as T[]? I suspect the
Saving an ArrayList<ArrayList> to File
I am able to save an ArrayList to a file without any problems, but when I try to write and read an ArrayList<ArrayList<Integer>> to file it nulls out the values. I cannot find an example of this format working, or any subject matter as to why it wouldn’t work. Does anyone have any insight into why this might happen, or
Drawing raffle numbers out of list that can have duplicates in Java
I was trying to learn programming by writing code with friends, we are all new though and are stuck with this raffle program. Players can earn multiple raffle tickets. The raffle tickets are written down in a new row in an ArrayList when they are earned. It looks like this: “PlayerA PlayerB PlayerB PlayerC PlayerD PlayerE PlayerF” Now we want
Adding two linked list ends in Infinite Loop
I’m trying to solve LeetCode problem 2. Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading
Android NullPointer Attempt to invoke virtual method ‘boolean java.util.ArrayList.add(java.lang.Object)’ on a null object reference
I’m getting this error: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.util.ArrayList.add(java.lang.Object)’ on a null object reference and just to make it clear is that I know others with the same issue have asked the same question and I have read the solutions which are usually that you have to instantiate your ArrayList which however I am obviously doing but
How to take input in java where array length is not defined?
My input is in this format: The array length is not known. I coded it this way: But I am getting this error. Thanks in advance. Answer You should use hasNextInt to check for integer input. Once no more integers, then just use next() to read the player. Example input’s supported output