Error In Adding In ArrayList

Apr 19, 2014

package eg.edu.guc.iphone.tiles;
import java.util.ArrayList;
import eg.edu.guc.iphone.Location;
public class Square extends Piece {
private ArrayList<Location>possibleMoves;

[Code] ......

View Replies


ADVERTISEMENT

Adding Objects To ArrayList

Oct 17, 2014

I've two classes: Student and ArrayListExamples (which has my main method in it).

The student class acts pretty simply at the moment with a constructor that takes a name, surname and ID number. I've tested it and it seems to be working. My issue is with adding an object to an array list, here is my effort:

public class ArrayListExamples {
private static int MAX_SIZE = 50;
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList();
 
[code]....

I know the last loop to add the student objects is wrong.I'm calling the student ArrayList add method with a student object whose constructor requires two strings and an integer. Why isn't this allowed?

View Replies View Related

Adding Element From Arraylist To Array

Sep 11, 2014

So I'm trying to write a method which returns the number of vowel characters in arraylist. My idea is to convert the arraylist element by element to array each time iterating through the array counting the vowels of that element. When I started I immediately got an error(surprise, surprise). Excuse me if the problem is too simple, but I am very new to programming.

At line 9 I get the following error "Type mismatch: cannot convert from String to int". I want to get the element at this position, not to convert to int..

ublic class One {
public static void main(String[] args) {
ArrayList<String> bla = new ArrayList<String>();
bla.add("aaa");
bla.add("brr");
bla.add("unn");
}
public static ArrayList<String> averageVowels (ArrayList<String> list){
String[] arrListWord = list.toArray(new String[list.get(0)]);
return list;
}
}

View Replies View Related

Adding Element To ArrayList Not Working

Jan 24, 2015

Ive set up a list to when a user creates an element it will be added to the entire list, but when i return to the main menu the Element isnt added.

Here is the code

public void setElement(int atomicNum, Element e){
if (ElementHasData(atomicNum) == false) {
if(atomicNum < MAX){
list[atomicNum] = e;
atomicNum++;

[Code] ...

Here is what the code intiates

~MAIN MENU~
Please select an option you wish to activate
1) Print All Elements
2) Print One Specific Element
3) Add an Element
4) Edit an Element

3
What is the atomic number of the Element you would like to add
Numbers only valid 1-113
1
Enter element name
Hydrogen
Enter element Symbol
H
What is the Elements weight
1.01
NEW ELEMENT ADDED!

[Code] ....

~MAIN MENU~

Please select an option you wish to activate
1) Print All Elements
2) Print One Specific Element
3) Add an Element
4) Edit an Element

But then after i try to print the specific element

~MAIN MENU~
Please select an option you wish to activate
1) Print All Elements
2) Print One Specific Element
3) Add an Element
4) Edit an Element
2
What is the atomic number of the Element
1
that element does not exist would u like to create this element Enter yes or no

View Replies View Related

Creating ArrayList And Adding Item To Array

Nov 27, 2014

Creating an Arraylist and adding item to that array, refer below code

ArrayList<String> sjarr = new ArrayList<String>();

Statement1:
String arritem1 = new String("First array item");
sjarr.add(arritem1);

Statement2:
String num = "text will decide";
sjarr.add(num);

Both adds the String item to array list but puzzling what makes the difference....

View Replies View Related

Adding Integer Values Into String Arraylist

May 5, 2014

I'm having an issues with adding integer values to a string list. The question is asking me "the method should iterate over runners, and for each runner generate a random number between 90 and 180 (inclusive) which should be used to set the time (in minutes) for that runner."

I have been able to get the random number and iterating over the runner arraylist but I haven't been able to figure out how to add the values generated into the runners list. I am also using BlueJ.

Here's the whole code I have at the moment:

import java.util.*;
import java.io.*;
import ou.*;
import java.util.Random;
/**
* Write a description of class MarathonAdmin here.
*/
public class MarathonAdmin {
// instance variables - replace the example below with your own

[Code] .....

View Replies View Related

ArrayList Only Adding 1 Item When There Are Multiple Items

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");
method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);
if(files.hasReadData) {

[Code] ....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Adding Arraylist To Jtable In Another Class

Jan 23, 2015

I'm trying to fill my jtable with an arraylist. The problem is the jtable is in an extended class and the arraylist in the mainGUI. Now how can I fill the jtable with the arraylist?

That's the arraylist in my MainGUI

BufferedReader in = null;
ArrayList<String> data = new ArrayList<String>();
try {
in = new BufferedReader(new FileReader("1.dat.txt"));
String str;
while ((str = in.readLine()) != null) {
data.add(str);

[Code] ....

View Replies View Related

ArrayList Only Adding 1 Item Even Though There Are Multiple Items (Setting Data To Files)

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");

method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);

[code]....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[code]....

View Replies View Related

Error Adding Two Numbers?

Nov 5, 2014

package calculator;
public class operations {
int a = 5;
int b = 10;
public void add(int a,int b)
{
int c = a+b;
System.out.println(c);
}
}

I am not getting output to this question though it runs.

View Replies View Related

Error When Adding Images?

Jan 16, 2014

I have been trying my hand at making 2d top down view games and have found myself repeatedly using the same code so i created a file with all the functions so when it is down i just import the jar and dont have to keep rewriting functions. I have trouble because the background is loaded on the screen and i dont know why as i didn't tell it to load. In fact I set the panels visiblity to false. Both of my classes are in the same package. Why I still get the Image.

Walking Turtle
Java Code: import javax.swing.*;
import java.awt.event.*;
public class turtleWalker extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame("Walking Turtle");

[code]....

View Replies View Related

Error - ArrayList Has Private Class

Jan 30, 2015

Java Code:

import java.util.Scanner;
import java.util.ArrayList;
public class Problem1
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();

[Code] ....

There is an error and says that my ArrayList has private access. I can't figure out how to fix it.

The code runs but when I enter "Quit", the program just stops. The arraylist isn't printed out?

View Replies View Related

Arraylist Error - Cannot Find Symbol

Feb 4, 2014

I am working on a StringBuffer program and I am getting the following error message: Cannot find symbol - method append(java.lang.String) with this part of the code selected:

return str1.append(str9);
import java.util.*;
import java.lang.StringBuffer;
class stringBuffProject
{
static String append(String str1, String str2, String str3, String str4, String str5, String str6, String str7, String str8, String str9)

[code]...

View Replies View Related

Getting NullPointer Exception Error In Simple ArrayList Program

Mar 21, 2015

I am creating a simple ArrayList program that would enable one to input their username to it using a scanner. However, i am getting this error: "Exception in thread "main" java.lang.NullPointerException

at home.Members.addUser(Members.java:16)
at home.Main.main(Main.java:14)"

Here is the code! :

Main.java class
Java Code: import java.util.Scanner;
public class Main {

[code]....

View Replies View Related

Populating ArrayList Using Scanner Class Logic Error

Sep 12, 2014

My code runs and populates an arraylist. However my break statement, while stopping the loop ends up being added to the arraylist. And I'm not sure how to fix this error.

public static void main(String args[]) throws Exception
{
// declaring variables
String input = "";
// creating array list
ArrayList<String> nameList = new ArrayList<String>();

[Code] ....

View Replies View Related

Quick Sort Method For ArrayList Of Strings - Compiler Error

Sep 14, 2014

So I'm trying to implement a quick sort method for an ArrayList of Strings and right now I'm getting the compiler error message: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space. I don't know what that error means nor how to fix it. I've marked in my code where the error seems to be occurring.

import java.util.ArrayList;
public class quickSort
{
// constructor
public quickSort()

[code]....

View Replies View Related

Create Own ArrayList Using Collection Without Implementing ArrayList Itself

Feb 28, 2014

I'm trying to create my own arraylist using Collection. My program doesn't do anything. Obviously, I haven't a clue.

import java.util.Collection;
import java.util.Iterator;
public class MyArrayList<T> implements java.util.Collection<T> {
private int size = 4;
private T[] mArray;
public MyArrayList(String[] args) {

[Code] ....

View Replies View Related

Populating ArrayList Object With Nested ArrayList Object

Jul 8, 2014

I have stumbled onto a problem with ArrayLists (not sure if nested ArrayList objects would be a more accurate description) ....

As simply put as I can describe it, I have an Inventory class which creates an ArrayList of a Product superclass, which has two subclasses, PerishableProduct and ItemisedProduct.

By default, the program is meant to have a starting inventory, which is why I have added them in the constructor

public class Inventory {
private List<Product> products;
public Inventory() {
addProduct(new Product("Frying pan", 15, 20));
addProduct(new PerishableProduct("Apple", 5.8, 30, 7));
addProduct(new ItemisedProduct("Cereal", 5.8, 0));
// this is where I am having problems. Wanting to add
// objects to the ItemisedProduct's ArrayList for cereal.
}

Within the ItemisedProduct subclass is yet another ArrayList which is meant to hold serial numbers.

public class ItemisedProduct extends Product {
private ArrayList<String> serialNumbers = new ArrayList();
public ItemisedProduct(String name, double price, int qty) {
super(name, price, qty)

[Code] .....

My problem is that I do not know how to populate the serialNumbers ArrayList from the Inventory class' constructor. Because technically, quantity is defined by how many serial numbers are created.

View Replies View Related

JSP :: Eclipse Project Window Shows Error But Code Editor Shows No Error

May 22, 2014

For my jsp file, the code editor shows no error, but the projects window shows an error. I built my project again, cleaned the project, restart eclipse twice and summoned cthulhu. But my project still shows an error. How do I find the cause.

Eclipse project -

JSP file -

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="mine" uri="DiceFunctions"%>

[Code] ....

View Replies View Related

JSP :: Error Page Is Not Displaying Instead Error Status Code Is Displaying

Apr 5, 2014

I have written some error checking code

File name ErrorPage.jsp

<%@ page language="java" isErrorPage="true" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Error</title>
</head>

[code]...

I have put error.jsp and badpage.jsp file in public access folder that is web content in eclipsewhen I am running the code I am status code of 500 and not the errorpage.jsp message .

View Replies View Related

Array Not Adding 1?

Jan 1, 2015

I am working on a text based adventure game. (This is NOT OOP at all) The problem comes in at my second if statement inside my loop, it is not adding 1 to my array locations[] it keep printing location[0] then a 1 at the end. Not really sure what is going on here. I would like it to when I type "Go north" it adds 1 to locations[]

E.G
locations[0]
Go north
locations[1]
go north
locations[2]
package com.PenguinGaming;
import java.util.Scanner;
public class Game{

[code]....

View Replies View Related

Adding JLabels To GUI

Apr 5, 2014

I'm really struggling adding JLabels to my GUI. The code is giving no errors but the JLables aren't showing up as I think I've done something else wrong. Here's my method for adding the JLabels:

public void showGraphics(){
for(int i=0; i<message.length(); i++){
if(message.charAt(i) == '#'){
JLabel localLabel = new JLabel("test label");
getContentPane().add(localLabel);
}
}
}

I think the problem might be to do with how the rest of the GUI is setup and the fact that I haven't specified where to add the JLabel just that I'm adding them.

Here's what my GUI looks like.

I want the JLabels above the JTextArea.

View Replies View Related

Adding Image To GUI

Jul 28, 2014

Code of file:

Java Code: import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

[code]...

The serializable class ImagePanel does not declare a static final serialVersionUID field of type long public class ImagePanel extends JPanel{ ^^^^^^^ ^ ^^2 problems (1 error, 1 warning) mh_sh_highlight_all('java');

im basically just trying to put the image inside the GUI and centre the text underneath it. Which is hard to believe since the text is above the image in the code .

View Replies View Related

Adding Bill / Tax And Tip

Feb 1, 2014

I'm trying to make a simple program that will show the amount of a bill, the tip, tax and total with all 3 added.

Right now i am having issues with line 12. I am getting the error "Variable amount might not have been initialized

I thought i did initialized it.

import javax.swing.JOptionPane;
public class BillAmt {
public static void main(String[] arg) {
String amt;
double tax, taxTotal, tip, total;
tax = 6.75;
double amount;
taxTotal = amount + tax;
tip = taxTotal *.15;
total = tip + taxTotal;
amt = JOptionPane.showInputDialog("Please enter the amount: ");
amount = Double.parseDouble(amt);

View Replies View Related

Adding Values Within Jtextfield?

Mar 25, 2015

I have a supermarket checkout line where i have a list of available products on the left and then a basket on the right with the products in. The products are listed in an array, here is the product class

public class Product {
private String name;
private double weight;
private double price;

[Code] ....

with getters and setters excluded, and the list these are put into

public class productList extends DefaultListModel {
public productList (){
super();
}
public void addProduct (String name, double weight, double price, int code){
super.addElement(new Product(name, weight, price, code));

i have the price for each product to be displayed in a text field with the following code

addBasketItem = new JButton();
getContentPane().add(addBasketItem);
addBasketItem.setText("Add >");

[Code] ....

defaultCheckoutList contains my available items and defaultMainList is the basket, with mainTillPrice being the jtextfield.

This works to get the price however it just replaces each time i make a new entry with the price for the next item, i want a total of the price of all the items i have added, but not sure how.

View Replies View Related

Adding Numbers In Table?

Mar 11, 2014

how can I add the numbers in quantity where it will automatically put in total?

im using netbeans.

just want the codes for how to add the listed quantity?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved