導航:首頁 > 編程語言 > javaformatlist

javaformatlist

發布時間:2021-02-23 16:57:02

java java.lang.NumberFormatException: empty String

因為你這個是報的異常
你首先應該看異常信息是什麼 上面說的是
NumberFormatExceptionextends

如果你不認識你首先應該去版查JDK的幫權助文檔,上面是這樣寫的
public class NumberFormatExceptionextends IllegalArgumentException
當應用程序試圖將字元串轉換成一種數值類型,但該字元串不能轉換為適當格式時,拋出該異常。

看到這我想你應該明白是什麼意思了吧。
也就是說你將一個可能包括非數學字元相關的字元串轉成成數值,導致錯誤
比如說 12as34,他是不可以轉成數值的。

你的代碼我沒有細看,我想可能是通過getText時獲得了非數值字元轉

看你的詳見
我看可能是由

JComboBox控制項引起

② 請問Java中DateFormat df=new simpleDateFormat()是什麼意思

DateFormat和SimpleDateFormat都是java.text包下的類,兩者的關系是:
DateFormat是抽象類,SimpleDateFormat是具體類,DateFormat是SimpleDateFormat的父內類。

由於DateFormat是抽象類,因此沒法用new來構建。容而SimpleDateFormat可以。
Java的多態性,決定了SimpleDateFormat的類對象可以向上轉型為DateFormat類型,因此這句是可以的。
(另外,類名首字母都是大寫,你寫的simpleDateFormat的首字母寫錯了)

③ 關於JAVA中JLIST顯示問題

你這個問題是說
用JLIST.setSelctedIndex(index)方法,沒有辦法設置選擇項嗎?
下邊有段簡單的代碼,希望對你有幫助。

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JButton;

public class JListTest extends JFrame implements ActionListener {

private String pattern = "selected {0}";
private int len = 5;
private JButton btnNewButton = null;
private int index = 0;
private JList list = null;

public JListTest() {

setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(400, 300);
setResizable(false);
getContentPane().setLayout(null);

DefaultListModel listModel1 = new DefaultListModel();

list = new JList(listModel1);
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (int i = 1; i <= len; i++) {
calendar.set(Calendar.DATE, i);
listModel1.addElement(sdf.format(calendar.getTime()));
}
list.setSelectedIndex(5);
list.setBounds(23, 10, 127, 240);
getContentPane().add(list);

btnNewButton = new JButton(getBtnName());
btnNewButton.setBounds(162, 7, 148, 21);
btnNewButton.addActionListener(this);
getContentPane().add(btnNewButton);
setVisible(true);
}

private String getBtnName() {
int random = (int) (Math.random() * 1000);
index = random % len;
System.out.println(index);
return MessageFormat.format(pattern, index);
}

public static void main(String[] args) {
new JListTest();
}

public void actionPerformed(ActionEvent e) {
list.setSelectedIndex(index);
btnNewButton.setText(getBtnName());
}
}

④ java dateformat怎麼轉換時間格式

Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm");
System.out.println(sdf.format(d));

⑤ 用Java編寫數字格式化程序

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class FormateBankAccountId {
List<String> standardBankAccountIdFormat ;
public FormateBankAccountId(String propertiesFileName) throws FileNotFoundException, IOException
{
// 載入資源文件
Properties properties = new Properties();
properties.load(new FileReader(propertiesFileName));
this.standardBankAccountIdFormat = new ArrayList<String>();
int keyNumber = 1;
String value = null;
// 讀取鍵值對,鍵的格式是: formate_1 ,..., formate_10,...,formate_100 等
while( ( value = properties.getProperty("formate_" + keyNumber++) ) != null)
{
value = value.trim();
this.standardBankAccountIdFormat.add(value);
}
}
public List<String> formate(String orginalBankAccountId)
{
List<String> proceededlBankAccountIds = new :

⑥ java.lang.NullPointerException

AddBookAction 應該有一個Double型的參數,但是這個參數從前端傳來的是null值,所以在轉換的時專候出錯了。 產生錯誤的原因是屬:

Double d = Double.parseDouble(null);

⑦ java.lang.NumberFormatException: multiple points

SimpleDateFormat是非線程安全的,每次用的時候new一個

⑧ Java 格式化問題:我要寫一個程序來格式化一串代表銀行帳號的數字。

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class FormateBankAccountId {

List<String> standardBankAccountIdFormat ;

public FormateBankAccountId(String propertiesFileName) throws FileNotFoundException, IOException
{
// 載入資源文件
Properties properties = new Properties();
properties.load(new FileReader(propertiesFileName));

this.standardBankAccountIdFormat = new ArrayList<String>();

int keyNumber = 1;
String value = null;
// 讀取鍵值對,鍵的格式是: formate_1 ,..., formate_10,...,formate_100 等
while( ( value = properties.getProperty("formate_" + keyNumber++) ) != null)
{
value = value.trim();
this.standardBankAccountIdFormat.add(value);
}
}

public List<String> formate(String orginalBankAccountId)
{
List<String> proceededlBankAccountIds = new ArrayList<String>();

orginalBankAccountId = orginalBankAccountId.trim();
for(String formateString : this.standardBankAccountIdFormat)
{
// 格式字元串中的數字個數,
int formateStringDigitNum = formateString.replace("-", "").length();

//原字元串過長,截取後面部分
if(orginalBankAccountId.length() > formateStringDigitNum)
{
orginalBankAccountId = orginalBankAccountId.substring(orginalBankAccountId.length() - formateStringDigitNum);
}

//原字元串過短,前面補零
else if(orginalBankAccountId.length() < formateStringDigitNum)
{
String pre = "";
for(int i = 0 ; i < formateStringDigitNum - orginalBankAccountId.length() ; i ++) pre += "0";
orginalBankAccountId = pre + orginalBankAccountId;
}

// 格式化字元串中分隔符位置
int delimiterPosition = 0;
String temp = orginalBankAccountId;
while(-1 != (delimiterPosition = formateString.indexOf('-',delimiterPosition)))
{
// 添加分割符號
temp = temp.substring(0,delimiterPosition) + '-' + temp.substring(delimiterPosition );
delimiterPosition ++;
}
proceededlBankAccountIds.add(temp);

}
return proceededlBankAccountIds;
}

/**
* @param args
* @throws IOException
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO Auto-generated method stub

String orginalBankAccountId = "000111111222";
FormateBankAccountId formateTool = new FormateBankAccountId("bankAccountId.properties");

for(String proceededBankAccountId: formateTool.formate(orginalBankAccountId))
{
System.out.println(proceededBankAccountId);
}
}

}
/*
bankAccountId.properties:

formate_1 ###-######-###
formate_2 ##-####-###-##
formate_3 ####-#-###-###
formate_4 #-########-###
formate_5 ###-########-#
*/

/*
output :

000-111111-222
00-1111-112-22
0011-1-111-222
0-00111111-222
000-11111122-2

*/

⑨ java.text.messageformat.format會影響效率嗎

這個坑,就出現在下面這個api的使用
java.text.MessageFormat.format(String pattern,java.lang.Object... arguments);

先來個正常的:
上代碼

Code:

package chapter5;
import java.text.MessageFormat;
public class MessageFormatDemo {
public static void main(String[] args) {
String pattern = "select * from staff where salary>{0} and age>{1}";
String result = MessageFormat.format(pattern, 100, 20);
System.out.println(result);
}
}

執行下看看結果是不是:
select * from staff where salary>100 and age>20

Output:

select * from staff where salary>100 and age>20

與預期一致
OK

現在什麼物價啊,salary大於100的太多了(木有少於100的好不好)

改下,要查工資大於50 000的

Code:

String result = MessageFormat.format(pattern, 50000, 20);

執行下看看結果:

select * from staff where salary>50,000 and age>20

看到沒
50000變成50,000

這到資料庫中肯定是不行啊
為什麼出現這種情況呢

扒扒源碼

java.text.MessageFormat.java的
subformat(Object[] arguments,StringBuffer result,FieldPosition fp,List characterIterators)
方法中有對輸入Object數據進行格式化的邏輯

} else if (obj instanceof Number) {
// format number if can
subFormatter = NumberFormat.getInstance(locale);
} else if (obj instanceof Date) {
// format a Date if can
subFormatter = DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT, locale);//fix

} else if (obj instanceof String) {
arg = (String) obj;

把格式化Number的這段代碼摘出來,

Format subFormatter = NumberFormat.getInstance(Locale.getDefault());
System.out.println(subFormatter.format(1000));
subFormatter = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());//fix
System.out.println(subFormatter.format(new Date()));

執行下看看

Output:

1,000

16-4-7 上午12:40

輸出結果與預期一致,果然多了個逗號

細心的tx已經看到了,日期類型也不行,一樣會格式的哦

7
如果還想使用MessageFormat應該怎麼處理呢?
在上面的源碼中,可以看到,在格式化時,String類型是不處理的

只要把arguments的參數改為String就可以了

Code:

String result = MessageFormat.format(pattern, "50000", 20);

⑩ 求教:運行nutch抓取網頁時出錯,無法抓取網頁,貌似是java jdk的問題 ,jdk版本1.6 crawl.log 錯誤信息

不是java問題,應該是配置不對,沒有找到文件/usr/local/apache-nutch-1.2/4

閱讀全文

與javaformatlist相關的資料

熱點內容
共享數據怎麼被凍結了 瀏覽:150
如何登記考勤數據 瀏覽:640
蘋果6s前置照片效果 瀏覽:171
企業微信素材庫文件下載鏈接 瀏覽:582
pdf文件怎麼取消標黃 瀏覽:781
打電話時不能使用網路是什麼原因 瀏覽:919
ps怎麼將文件合並 瀏覽:747
java的日期格式化 瀏覽:981
電腦應用程序怎麼關 瀏覽:986
微信上鏈接在哪個文件夾 瀏覽:691
歐姆龍安裝打開找不到密鑰文件 瀏覽:302
蘋果基本表情 瀏覽:128
我的世界教育版編程在哪裡 瀏覽:842
pong文件夾找不到 瀏覽:759
69版本黑切 瀏覽:997
杭州道富java 瀏覽:635
知道qq號查微博賬號和密碼 瀏覽:294
紅手指自帶哪些app 瀏覽:103
手機用公司網路會被監控哪些 瀏覽:409
什麼叫py編程 瀏覽:370

友情鏈接