Swing/AWT/SWT :: Number Format Exception - Empty String

Mar 8, 2014

This is the exception message I am getting when I run the program and I select a job from the check box and enter an hour amount.

import javax.swing.*;
import java.awt.*;
public class HourPanel extends JPanel {
private double hours;
String textField;

[Code] .....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Validation Phase - Make Sure Textboxes Are Not Empty And In Correct Format

May 20, 2014

I have a question with this gui project I am building, I have gotten the code to work in very basic forms such as the main part of calculations and etc. But now I am in the phase of validation to make sure the textboxes aren't empty and are in the correct format. I have done alot research already. I would like to use a Joptionpane to warn the user of an invalid entry. But I have tried many different methods and I can't seem to get them to work.

private void calculateActionPerformed(java.awt.event.ActionEvent evt) {
double loanAmt;
int years;
boolean validData;
double rate,total,calcRate,payment,amount,numMonths,totalPayment,paymentRounded,numMonthsRounded;

[Code] .....

When ran I get these errors: (only copied a few of the main lines)

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "p"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
at java.lang.Double.parseDouble(Double.java:540)
at car.loan.NewJFrameCarloan.calculateActionPerformed(NewJFrameCarloan.java:228)
at car.loan.NewJFrameCarloan.access$500(NewJFrameCarloan.java:17)
at car.loan.NewJFrameCarloan$6.actionPerformed(NewJFrameCarloan.java:106)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)

View Replies View Related

Getting Number Format Exception When Trying To Use ParseInt

Feb 17, 2014

The problem occurs at the second to last line of text in this code.

* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package reversing_digits;
import java.util.Scanner;
public class Reversing_digits {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[Code] ....

View Replies View Related

Using Result Of Conversion - Number Format Exception

Jul 27, 2014

I want to use the result of the conversion. Can i do that??

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class App2 extends Applet {
Label x,y,z;
TextField a,b,c;
Button p,q,r;

[Code] ....

View Replies View Related

Number Format Exception While Parsing Date To Long

Feb 1, 2015

I'm getting a NumberFormatException while executing the below statements.

Calendar cal = Calendar.getInstance();

int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day_of_month = 15;

long m_time = Long.parseLong((month + 1) + "/" + day_of_month + "/" + year);

and

long m_time = Long.parseLong(String.valueOf((month + 1) + "/" + day_of_month + "/" + year));

View Replies View Related

Transferring Amount To Other Account - Number Format Exception

Apr 7, 2014

I'm doing this project in JSP.net, with html. and in one of the web pages, what I'm doing is that, a person is transferring an amount to someone else, and if the transfer amount is more than the account balance, then he cannot transfer. else, save details in a table.

Here's the code I've used

<%
String t1=request.getParameter("text1");
String t2=request.getParameter("text2");
java.util.Date date1 = new java.util.Date();
SimpleDateFormat ft = new SimpleDateFormat ("dd/MM/yyyy");
int tamt = Integer.parseInt(t2);
int bamt = 0;

[Code] .....

But when i enter the fields and click the submit button in the form, to save it in the table, i get the error:

"org.apache.jasper.JasperException: java.lang.NumberFormatException: null"

(I've attached a screen shot of the error) : NumberFormatException.bmp (750.98K)

What does this mean? how do i find the line in the code that has the error?

View Replies View Related

Clicking Insert Button - Number Format Exception

Feb 9, 2015

Everything is working great except for my back button at line 172. It works good but if I try to click the "insert" button again. It gives me the java.lang.NumberFormatException error. Other than that it works fine, the "insert" button still works.

package userDatabasePack;

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Database{
//Variables
private String username2, insertUser, insertPassword;
private int insertUserId;

[Code] ....

View Replies View Related

Converting String To Number - Runtime Exception

Feb 6, 2014

I am getting run time Exception while converting String to Number....

public int convertToNumber(String numstr) {
int i = Integer.parseInt(numstr);
return i;
}

Here i am calling above Method convertToNumber().

if (validate.hasNumber(req.getParameter(LRSConstant.MOB_NUM))) {
bean.setMobno(ValidateUtils.getInstance().convertToNumber(
req.getParameter(LRSConstant.MOB_NUM)));
}

This is an Exception which i am getting at Run time

java.lang.NumberFormatException: For input string: "9700636702"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:461)
java.lang.Integer.parseInt(Integer.java:499)

[Code] ....

View Replies View Related

Balanced Brackets Execution - Keep Getting Empty Stack Exception

Oct 21, 2014

Im trying to do this program but I keep getting Empty Stack Exception when I execute balancedBrackets. I know that push and pop methods works, but I'm not so sure if my logic for balancedBrackets is correct.

public void push(T t){
if(this.top+1==this.size){
duplicateCapacity();
}
else{
top++;
arr[top]=t;

[Code] .....

View Replies View Related

Exception In Thread Main - Cannot Format Given Object

Apr 16, 2014

I am working on a program that will allow a user to input grades for a class of four students who have taken two tests. Based on the grades entered, the program will calculate the averages of the two tests for each student and display it along with their respected letter grades.

Now I can get the program to compile successfully, but after inputting the grades in, I get the error message saying that it cannot format given object as a number. I am using 4 arrays to execute this program and maybe that's why I'm having the trouble? I'm not sure because I am still fairly new at this stuff and can't sen to resolve it.

I was having problems for a while and then finally got excited when I got it to compile without any errors and now I'm getting an error inside my program. All I need to do is format the numbers of the grades into something like: 000, and each of the averages as 000.0. I understand how to do it because I have done it in another program I've done in the past. I just don't know how to fix this error that is coming up.

here is my code:

import java.util.Scanner;
import java.text.DecimalFormat;
public class TestAverage
{
/**
* A program that will store and process 2 test scores for a class of 4 students.
* The program will prompt for the test scores as shown above in the sample run.
* After all the data is entered,the program will display the score for test 1, test 2 .
* The average of the 2 tests and the letter grade for the class for each student in a tabular format.
*
*

[code]....

View Replies View Related

String Testing For Null / Empty?

Oct 13, 2014

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).

View Replies View Related

Compile Error - Empty String?

Jul 1, 2014

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) {

[Code] ....

View Replies View Related

How To Compare Int To Empty String To Input Error

Apr 16, 2015

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

[Code] ....

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

Hurricane Java Project - Unknown Format Conversion Exception

Mar 9, 2015

I am having some issues with errors. Here is my code...

import java.io.*;
import java.util.Scanner;
public class StormChaser {
public static void main(String[] args)
{
// Constants
final int MAX_STORMS = 319;
 
[Code] .....

I am having issues with these error messages.... I have tried a couple of different things with each error but haven't been able to figure it out.

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '1'
at java.util.Formatter.checkText(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at Storm.toString(Storm.java:98)
at StormChaser.DisplayStorms(StormChaser.java:141)
at StormChaser.main(StormChaser.java:53)

View Replies View Related

Student Poll Code - Unknown Format Conversion Exception

Dec 8, 2014

It doesn't work and I always get UnknownFormatConversionException...

public class studentPoll {
{
public static void main( String[]args)
{
  int[] responses = { 1, 2 , 5, 4, 3 , 5, 2, 1 , 3, 3, 1, 4, 3, 3, 3,
2, 3, 3, 2, 14 };
 
[Code] .....

View Replies View Related

Continuously Get User Input Until Empty String Entered

Jul 26, 2014

I have the code below that just keeps getting the user's name and displaying it until the user enter's an empty string. Well, to simulate that, I just hit the keyboard instead of entering any name but for some reasons I am not seeing in my code, the programme just keeps looping.
 
System.out.println("Enter your name :
");
Scanner st = new Scanner(System.in);
while(st.hasNext()){
System.out.println("Enter your name :
");
String name = st.nextLine();
System.out.println(name);
if(name==" ") break;
}
System.out.println("you are out of the while loop now!!");

View Replies View Related

Servlets :: JSessionID Cookie Value - It Always Returns Empty String

Feb 6, 2014

I'm trying to get the jsessionid cookie value using the following line in my jsp. It always returns empty string. Is this correct behaviour?

response.encodeURL("")

View Replies View Related

How To Compare Int To A Empty String To Input Error Message To User

Apr 16, 2015

I made a guess a number program but I am having issue figuring out a way that when a user enter's in nothing for the program to spit out a message saying "hey entering nothing doesn't work try again" then ask for input. I have done some research and from what I have found is to read the input in as a String rather than int, and use something like Integer.valueOf() to get the integer value but I am completely lost on how to apply that to my program here is my code

//import statements
import java.util.*; //for scanner class
// class beginning
public class Guess {
public static void main(String[] args ) {
//Declare variables area
int guess, secretNumber = (int) (Math.random() * 10 + 1), lowGuess,highGuess;

[Code] ....

View Replies View Related

TicTacToe Game - Adding Crosses And Naughts To Empty String

Jul 5, 2014

I have an empty string and I want to add to it crosses and naughts. I want to simulate a board of TicTacToe game. My goal is print out 5 strings like this : "xox xxx oxo". There are 3 groups of symbols separated with a space. The crosses and naughts are filled randomly.

Random rand = new Random();
char[] characters = new char[] { 'x', 'o' };
int numOfTimes = 0;
while (numOfTimes < 5)
{
String board = "";
String space = " ";
for (int group = 0; group < 3 ; group++)

[Code] .....

Why my code doesn't output the desired result ?

View Replies View Related

Reading Input With Scanner And Checking If User Entered Empty String?

Apr 7, 2015

The project is a program that allows the user to enter students and enter grades for each student. One of the requirements is that if there is already a grade stored for the student that it will display the previous grade. IF the user then enters a new grade the new grade will be stored. IF the user simply presses enter (enters an empty string) nothing is done. I have everything working except for the requirement of doing nothing if the user enters an empty string. If I just press enter at this point I get a NumberFormatException.

The below code is a method "setTestGrades" from the student class. This method iterates through each student object stored in an array list and then checks if there is a previous grade (Requirement# unset grades have to default to -1) before allowing the user to set a new grade.

public void setTestGrades(int testNumber) { //Sets the grade for the specified test number for each student in the arraylist.
testNumber -= 1;
Scanner input = new Scanner(System.in);
for (int i = 0; i < studentList.size(); i++) {
System.out.println("Please enter the grade for Test #" + (testNumber + 1) + " For Student " + studentList.get(i).getStudentName());

[code]....

View Replies View Related

Swing/AWT/SWT :: JTable Column In The Middle Is Empty?

Jan 23, 2014

I have a problem with my JTable.

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.

View Replies View Related

Swing/AWT/SWT :: How To Populate All Items In JTable When Corresponding JTextfield Is Empty

Aug 3, 2014

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!!!

View Replies View Related

Swing/AWT/SWT :: Add Row Method Inserting Empty Line Vectors

Apr 24, 2014

I am trying to add rows with List of String converted in Object arrays by Array.asList method, and it is inserting Vectors with nothing inside. I tried addColumn and it works perfectly, but in this case Lists represents rows.

(There is values in these Lists).

View Replies View Related

JSP :: How To Format Number As Money In JavaScript

Apr 23, 2014

How to format number as money in javascript? e.g 1000 to 1,000 ... E.g., 100000000 then it will be format into 1,000,000,000 ...

View Replies View Related

JSP :: How To Format Entered Number On Textbox

Apr 24, 2014

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber type="currency" value="12345.6789"/></p>
<input type = "text"/>

This one is working if i set value in fmt but what i want to happen is when i enter a number in textbox it will be fommated on the format that i want, so i think i need to an of og text and set it into value of fmt? <y plan is when I enter a number in textbox it will automatically formatted ....

View Replies View Related







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