Comparing data numbers, Iterator.remove() throwing NullPointerException

I am trying to make an Android app that can compare integers. However, when I am trying to compare integers and I need to delete some entries because they are redundant or they do not fit in, I cannot use Iterator.remove() without encountering a NullPointerException. Here is the specific output: E/AndroidRuntime: FATAL EXCEPTION: main Process: … Continue reading “Comparing data numbers, Iterator.remove() throwing NullPointerException”

Find the index of the first space character?

I’ve written functional code that will read and write data values to an arraylist. Though it returns everything, if a value has multiple words how can I exclude the first one? // 3 points static ArrayList<String> Q2(String filename) { // You are given a file (filename) containing a different random phrase on each line. Return … Continue reading “Find the index of the first space character?”

Java – object reference replaaced in object arraylist before called on

I am having a problem where when I’m debugging my code I notice that my object list array is replacing an object before a new object is added to the list array Previous Research I looked researched some similar situations this situation did not apply to my case. Why can't I add objects to my … Continue reading “Java – object reference replaaced in object arraylist before called on”

How to call a specific object from a list in JAVA in calling a constructor?

So I have this public class Client { private String name; private List<Product> purchase = new ArrayList<Product>(); Client (){} Client (String name, List<Product> purchase ){ this.name = name; this.purchase = purchase; } } and in Main I want to create a new client and put it in database. public class Main { public static void … Continue reading “How to call a specific object from a list in JAVA in calling a constructor?”

How to print different parts of a List in Java

I want to know how to print a List in Java where in each position there is a String and an int. List pasajeros = new ArrayList(); I insert the data like this: public void insert(List a) { System.out.print(“Name: “); name= sc.nextLine(); System.out.print(“Number: “); number= sc.nextInt(); ClassName aero = new ClassName(name, number); a.add(aero); } } … Continue reading “How to print different parts of a List in Java”

Displaying a multiple object arraylist?

I am curious as to how would I show a multiple object arraylist in Java. The array list contains both string and int. This is the class of which I am making a arraylist of. public class Movie { public int rating; public String title, directorName, actorOne, actorTwo, actorThree; public Movie(String Title, String Director, String … Continue reading “Displaying a multiple object arraylist?”

List traverse back in java

How can I traverse back in array list in java… Even I have the code to traverse forward direction … but I couldn’t consider that to traverse backward.. ArrayList<String> al = new ArrayList<String>(); al.add(“Raj”); al.add(“Sameer”); al.add(“Nitu”); al.add(“Biren”); al.add(“Vishal”); Iterator<String> it = al.iterator(); System.out.println(“Forward direction:-“); while(it.hasNext()) { System.out.println(it.next()); }

Sort arraylist of objects containing epochs in Java

I’ve an arraylist of objects like arrlist =[obj1, obj2,obj3], where each object contains epochs and an Integer i.e. obj_i = {“1493275005401”, 2} for all i . I want to sort arraylist on the basis of epochs. Being a beginner in java, I don’t know much how to do this. Note: I did some googling, came … Continue reading “Sort arraylist of objects containing epochs in Java”

Java Swing – Draw line between for loop drawn components

I am working on an assignment and I’m almost done, however, there is a bullet that tells me to draw a line between the adjacent components to approximate the distance between them. I searched for the answer everywhere, and none of them worked. Here’s the code, I cut out the unimportant things, thanks in advance! … Continue reading “Java Swing – Draw line between for loop drawn components”