本文整理汇总了Java中java.lang.NumberFormatException类的典型用法代码示例。如果您正苦于以下问题:Java NumberFormatException类的具体用法?Java NumberFormatException怎么用?Java NumberFormatException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NumberFormatException类属于java.lang包,在下文中一共展示了NumberFormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readNumber
import java.lang.NumberFormatException; //导入依赖的package包/类
static private Object readNumber(PushbackReader r, char initch) {
StringBuilder sb = new StringBuilder();
sb.append(initch);
for(; ;)
{
int ch = read1(r);
if(ch == -1 || isWhitespace(ch) || isMacro(ch))
{
unread(r, ch);
break;
}
sb.append((char) ch);
}
String s = sb.toString();
Object n = matchNumber(s);
if(n == null)
throw new NumberFormatException("Invalid number: " + s);
return n;
}
示例2: parseAirTemperature
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseAirTemperature(String s) {
String a = trimAndNullEmpty(s);
if (a == null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_TEMP_UNAVAIL)
return null;
double degC = (((double)val)/10.0D);
int i = (new Temperature(degC, Temperature.Units.CELSIUS)).round(CELSIUS);
return Integer.valueOf(i);
}
示例3: parseAvgWindSpeed
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseAvgWindSpeed(String s) {
String a = trimAndNullEmpty(s);
if (a == null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_SPEED_UNAVAIL)
return null;
double mps = ((double)val) / 10.0D;
double kph = mps*((double)SEC_PER_HOUR/1000.0D);
int i = (new Speed(kph, Speed.Units.KPH)).round(KPH);
return Integer.valueOf(i);
}
示例4: parseAvgWindDir
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseAvgWindDir(String s) {
String a = trimAndNullEmpty(s);
if (a == null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_DIR_UNAVAIL)
return null;
if (val == 360)
val = 0;
return Integer.valueOf(val);
}
示例5: parseGustSpeed
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseGustSpeed(String s) {
String a = trimAndNullEmpty(s);
if (a == null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_SPEED_UNAVAIL)
return null;
double mps = ((double)val) / 10.0D;
double kph = mps*((double)SEC_PER_HOUR/1000.0D);
int i = (new Speed(kph, Speed.Units.KPH)).round(KPH);
return Integer.valueOf(i);
}
示例6: parseGustDir
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseGustDir(String s) {
String a = trimAndNullEmpty(s);
if (a == null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_DIR_UNAVAIL)
return null;
if (val == 360)
val = 0;
return Integer.valueOf(val);
}
示例7: parsePrecipRate
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parsePrecipRate(String s) {
String a = trimAndNullEmpty(s);
if (a==null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_PRECIPRATE_UNAVAIL)
return null;
float gramsPerSqMPerSecond = (((float)(val)) / 10.0F);
float mmPerHr = (
( gramsPerSqMPerSecond / (float)G_PER_L_H2O)
/ (float)L_PER_MM_RAINFALL) * (float)SEC_PER_HOUR ;
return Integer.valueOf(Math.round(mmPerHr));
}
示例8: parseVisibility
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseVisibility(String s) {
String a = trimAndNullEmpty(s);
if (a==null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_VIS_UNAVAIL)
return null;
double meters = (((double)val)/10.0D);
int i = (new Distance(meters, Distance.Units.METERS)).round(Distance.Units.METERS);
return Integer.valueOf(i);
}
示例9: parseSurfaceTemperature
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseSurfaceTemperature(String s) {
String a = trimAndNullEmpty(s);
if (a==null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_TEMP_UNAVAIL)
return null;
double degC = (((double)val)/10.0D);
int i = (new Temperature(degC, Temperature.Units.CELSIUS)).round(CELSIUS);
return Integer.valueOf(i);
}
示例10: parseSubSurfaceTemperature
import java.lang.NumberFormatException; //导入依赖的package包/类
protected static Integer parseSubSurfaceTemperature(String s) {
String a = trimAndNullEmpty(s);
if (a==null)
return null;
int val;
try {
val = Integer.parseInt(a);
}
catch (NumberFormatException e) {
return null;
}
if (val == ESS_TEMP_UNAVAIL)
return null;
double degC = (((double)val)/10.0D);
int i = (new Temperature(degC, Temperature.Units.CELSIUS)).round(CELSIUS);
return Integer.valueOf(i);
}
示例11: toInt
import java.lang.NumberFormatException; //导入依赖的package包/类
public static int toInt(String value, StringBuilder err) {
if (value != null && !"".equals(value)) {
int neg = 1;
if (value.length() > 0 && value.charAt(0) == '-') {
value = value.substring(1).trim();
neg = -1;
}
try {
int parsed;
if (value.length() > 1 && value.substring(0,2).equals("0x")) {
parsed = toIntWarnParse(value.substring(2), 16, err);
} else {
parsed = toIntWarnParse(value, err);
}
return parsed == sm_PARSE_FAILED ? parsed : neg * parsed;
} catch (NumberFormatException e) {}
}
return sm_PARSE_FAILED;
}
示例12: createValueList
import java.lang.NumberFormatException; //导入依赖的package包/类
/**
* reset dataTable to default (demo data), and refesh chart
*/
protected List createValueList(String in){
// System.out.println("in="+in);
String vs = in;
// String[] values = in.split("( *)+,+( *)");
// int count = java.lang.reflect.Array.getLength(values);
StringTokenizer st = new StringTokenizer(in,DELIMITERS);
int count = st.countTokens();
String[] values = new String[count];
for (int i=0; i<count; i++)
values[i]=st.nextToken();
List<Double> result = new java.util.ArrayList<Double>();
try{
for (int i = 0; i < count; i++) {
double v = Double.parseDouble(values[i]);
result.add(new Double(v));
}}catch(NumberFormatException e)
{
showMessageDialog("Data format error!");
return null;}
return result;
}
示例13: createValueList
import java.lang.NumberFormatException; //导入依赖的package包/类
/**
*
* @param in
* @return
*/
protected List createValueList(String in){
vs = in;
// String[] values = in.split("( *)+,+( *)");
// int count = java.lang.reflect.Array.getLength(values);
StringTokenizer st = new StringTokenizer(in,DELIMITERS);
int count = st.countTokens();
String[] values = new String[count];
for (int i=0; i<count; i++)
values[i]=st.nextToken();
List<Double> result = new java.util.ArrayList<Double>();
try{
double v;
for (int i = 0; i < count; i++) {
if (values[i]!=null && values[i].length()!=0){
v = Double.parseDouble(values[i]);
result.add(new Double(v));
}
}}catch(NumberFormatException e)
{
showMessageDialog("Data format error!");
return null;}
return result;
}
示例14: test
import java.lang.NumberFormatException; //导入依赖的package包/类
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
NumberFormatException object1 = new NumberFormatException();
harness.check(object1 != null);
harness.check(object1.toString(), "java.lang.NumberFormatException");
NumberFormatException object2 = new NumberFormatException("nothing happens");
harness.check(object2 != null);
harness.check(object2.toString(), "java.lang.NumberFormatException: nothing happens");
NumberFormatException object3 = new NumberFormatException(null);
harness.check(object3 != null);
harness.check(object3.toString(), "java.lang.NumberFormatException");
}
示例15: getUsersByEmail
import java.lang.NumberFormatException; //导入依赖的package包/类
public LinkedList<Integer> getUsersByEmail(int email)
{
WebResource webResource = client.resource(ActiveSearchConstants.REST_URL_PREFIX + "getUsersByMessage/" + email);
String[] messages = webResource.accept("text/plain").get(String.class).split("[\\r\\n]+");
LinkedList<Integer> retList = new LinkedList<Integer>();
for (int i = 0; i < messages.length; i++) {
try {
int id = Integer.parseInt(messages[i]);
retList.add(id);
}
catch (NumberFormatException e) {
// this is ok
}
}
return retList;
}