1) productType that have name and price of the productType and an empty consturcor.
2) superMarket that have name of supermarket and arraylist of productTypes (
private ArrayList<ProductType> products;
) and an empty constructor.
In each class I have function that get input from console and should store it into each class variables.
In productType i have function:
public void getFromUser() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter product name:");
name = br.readLine();
System.out.println("Enter price:");
price = Integer.parseInt(br.readLine());
[Code] ....
The main is something like:
public static void main(String[] args) throws IOException{
SuperMarket s1 = new SuperMarket();
SuperMarket s2 = new SuperMarket();
s1.getFromUser();
}
The problem is when i get to line "products.add(i,p)" I get java.lang.NullPointerException
In the debug mode I can see that when I get to this line the "products" is null.
why do you think this happening, when I do "new SuperMarker()" in the main it should run the empty constructor and create new arraylist...
I'm trying to use in the constructor inserts from keyboard and then check whether any of the constructors fields remained empty. Let say my constructor is:
public SomeClass(String a, String b, String c)throws SomeClassException{ if (a == null || b == null || c == null) {throw new SomeClassException("Some message"); // here is the empty test } //...
Thus I prepared method: insertConstruct() as follows:
public static String insertConstruct(){ String lettering = null; Scanner sc = new Scanner(System.in); lettering= sc.nextLine(); return lettering; }
And during creating the new object in some main method I call:
// ... ClassName obj1; obj1 = new ClassName(insertConstruct(),insertConstruct(),insertConstruct()); //...
The problem is not with inserting data but with leaving the field empty. When I pass any field just with keyboards Enter, the empty test doesnt return me any message about it. While it works if I build object with the constructor like:
How do you test a default constructor in one class and then test it in a different class? This is the code for the Person class which has the default constructor. I'm not sure in the PersonTester class how to access this default constructor and how to test it - what I have so far for the second class is also below.
class Person { // Data Members private String name; // The name of this person private int age; // The age of this person private char gender; // The gender of this person
1 - I don't understand why I'm getting an empty stack error when calling the removecard method in my Table class line 13?
2 - I am trying to use a constructor to populate my deck of cards instead of a method when creating my theDeck object in my Table class line 11 but I get the following error:
java.lang.StackOverflowError at java.util.Vector.<init>(Unknown Source) at java.util.Vector.<init>(Unknown Source) at java.util.Stack.<init>(Unknown Source) at Deck.<init>(Deck.java:7) at Deck.<init>(Deck.java:34)
I have a HashMap with multiple values at runtime. In that map one key has empty value , how to avoid this value to add in a list. some code sample is below:
public HashMap getLoop2Map(Map map, String xslFile , int sheetNo){ HashMap hashMap = new HashMap(); try{ ArrayList list = new ArrayList(); System.out.println("-------Map : " +map); list.add(map.values()); //System.out.println("------- boolean : " +val); System.out.println("------List : " +list); }
I do not want to add the empty value in a list ...
result in map
-------Map : {Free Text Entry={}, Mouth / Throat={Free Text Entry={Free Text Entry=<FORMFILENAME>EditChartPhysicalExamText.form </FORMFILENAME><TAG>"<MUSCULOSKELETAL.PE>"</TAG>}, Salivary Glands Condition={Salivary Glands Condition=MouthAttribute}, Examination Overview- Mouth / Throat={Examination Overview- Mouth / Throat=MouthAttribute}, Tonsils={Tonsils=MouthAttribute},
@ManagedBean @SessionScoped public class HelloBean { public void downloadFile() { File file = new File("C:datacontacts.doc"); HttpServletResponse response = (HttpServletResponse)
I've been beavering away with Java for a few months. But as with all languages the String implementation looks designed to trip up even experienced programmers.
My current development gets data from various sources outside my control. When I get a string I want to test if it is empty/null/or whatever. Simple enough one thinks.
But if you search the internet you see everone seems to have a slightly different approach. So what is the best way of determining that a string is not useful to you?
I've had success with this
if(string == null || string.length() == 0)
But I've seen people using methods - not necessarily of String (e.g equals, empty) and regular expressions.
What is the best approach to this considering coding efficiency and/or processing efficiency (accepting you'd have to be processing a lot of strings for the latter to be an issue).
im trying to make a gui im trying to add a new jbutton for every empty cell in the array, and for some reason its giving me array index out of bounds error, this is what i have, im trying to to do it in an 80 by 80 array.
public JButton[][] buttons = new JButton[80][80];
public void addButtons(){ for(int i=0;i<buttons.length;i++){ for(int j=0;i<buttons[i].length;j++){ buttons[i][j]= new JButton(); } }
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner; import java.util.ArrayList; import java.util.Scanner; import java.lang.Double; public class GraduationPlanner { public static void main(String[] args) {
I am learning Java on my own, and I am creating little programs to do so.The program below asks the user to input text and hit enter. When user does that, it asks if that is correct. If the user enters "y," the program ends. That's good.If the users enters "n," the strGrategul is set to empty which triggers the while statement to start over again. That's good. However, when the program asks the user to "Tell me one thing you are grateful for..." it doesn't wait for user input. Instead it skips to "You said ''? Enter 'y' or 'n'" It thinks the user enter an empty line.
I am having issues with the program below everything works but I can't figure out a way to add code that if a user just hits enter without inputting anything it says "entering in nothing is not a valid choice" I am stuck on how to compare a int to a string ...
//import statements import java.util.*; //for scanner class // class beginning public class Guess { public static void main(String[] args ) { //Declare variables area
I am trying to create an array filled with the object Card. It keep throwing the exception that the "deck is empty". I am not sure why that's happening because the code for filling the array seems fine.
public class Deck { private Card[] deck; private CardPile cardPile; private int numCards; public Deck() throws InvalidDataException{ this.deck = new Card[52];
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12; int i = 1; int k = 0; int[] factors = {} while (i<x) { if (x%i==0) { factors[k] = i; k++; i++;
table.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode()==KeyEvent.VK_ENTER) { model.addRow(new Object[]{"", "","",""}); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } } );
I've added JTable to JPanel and used DefaultTableModel. I have to add a new empty Row to table after i press enter key. But somehow I've not been successful so far.
It works in the first time. But, after sometime the data is not retrieved and display empty screen. Once, i stop and start the server again, the data is getting retrieved again. But, later when we refresh the empty page is getting displayed again.
I've been trying to get my program to not accept empty strings when the user inputs, but I'm having some difficulties. I've tried for loops, as well as while loops.
import java.util.Scanner; public class GasMileage { /** * displayIntro * This method displays the introduction to the user */ public static void displayIntro()
When i run my program i see a JTable with data in it. The first 3 columns are filled with data, the next one is empty. Other columns that come afther the empty one are also filled.
So my 4th column is empty. But it only apears empty, cause when i move the 4th column to the left. The same column that was at 4th place is now at 3th place and filled up with data.
So the 4th column apears empty but it contains data when i move it to the left or the right.
Why does it show an empty column at the 4th place?
Some printscreens to get it clear:
In attachment:
attachment1 = 4th Column is empty attachement2 = 4th column is moved to 3th place and is filled with data.
I am working on a project with client/server relationship and I want the client to be able to transfer their personal music files over the socket. Every time I attempt to do it the file is created but it is empty.
Server code:
Java Code:
public class Server extends JFrame { //=============================== // FIELDS //=============================== // connection essentials private ServerSocket server; private Socket connection;
I am designing a advanced search option in a java project with sqlite in NetBeans. there are 5 different JTextfields and 5 columns, I want to populate JTable with corresponding matching criteria. If a JTextfield is empty then it should select all items of that column.
query i was using is: String val1=txt_billing2.getText(); //five input fields String val2=txt_station2.getText(); String val3=txt_invoice2.getText(); String val4=txt_amonth2.getText(); String val5=txt_umonth2.getText();
[code]....
but when i leave a JTextfield empty it shows no data in JTable. only method i know is to use if else conditions but that generates 5!= 120 conditions!!!
I have a txtfile which I read and go through. My question is what are the ways I could do to read a txtfile of words and assign an empty score to each of the word in it. So each word will have a 0 value. Later on I will manipulate the score but for now I want each word to have a 0 score.What I have at the moment is reading a text file full of words eg:
private void readtextfile() { try { Scanner rd = new Scanner( new File("filename")); List<String> lines = new ArrayList<String>(); while (sc.hasNextLine()) { lines.add(sc.nextLine());
[code]...
how to make each of the words to have a score of zero 0?