我有一个像下面这样的字符串.
ABC {一位知名的魔术师}将在{0}的{1}小时内进行表演.
第一对花括号没有占位符.当我将此字符串传递给MessageFormat.format(String,Object [])方法时,如果对象数组包含两个字符串来替换占位符{0}和{1},则会出现以下错误.
java.lang.IllegalArgumentException:所有参数标识符必须是非负数或模式后面的字符串([:ID_Start:] [:ID_Continue:]*).
看来第一对括号正在为第一个占位符进行解析,因为它不是有效占位符,所以会发生错误.
如何告诉MessageFormat.format忽略第一对花括号并与其他两个花括号一起使用?
java replace placeholder messageformat illegalargumentexception
我正在尝试编写一个只能同时运行X(让我们说3个)线程的类.我有8个线程需要执行,但我只想让3一次运行,然后等待.一旦当前运行的线程之一停止,它将启动另一个.我不太清楚如何做到这一点.我的代码看起来像这样:
public class Main {
public void start() {
for(int i=0; i<=ALLTHREADS; i++) {
MyThreadClass thread = new MyThreadClass(someParam, someParam);
thread.run();
// Continue until we have 3 running threads, wait until a new spot opens up. This is what I'm having problems with
}
}
}
public class MyThreadClass implements Runnable {
public MyThreadClass(int param1, int param2) {
// Some logic unimportant to this post
}
public void run() {
// Generic code here, the point of this is to …Run Code Online (Sandbox Code Playgroud) 
Eclipse IDE for Java Developers
Version: Luna Service Release 2 (4.4.2)
Build id: 20150219-0600
Run Code Online (Sandbox Code Playgroud)
我在第一张图片中加入了一些断点:

之后,我点击了错误符号来启动调试模式:

但应用程序启动就像它处于正常运行模式一样.正如您在2.图片中看到的那样,这些按钮无法点击(下一步,步入).
我使用kepler,它是相同的,所以我下载了luna但它仍然是相同的.我可以在5-6个月前使用调试模式.从那时起我没有使用eclipse而且没有改变任何东西.
当我传入一个空字符串""时,为什么以下代码返回1?
private int GetItemsInCommaSeparatedList(){
// Locals
String param = ""; // "1,2,3" returns 3 without issue
List<String> items = Arrays.asList(param.split("\\s*,\\s*"));
// Empty?
if ( items.isEmpty() )
return 0;
// Return
return new items.size();
}
Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习SQL,并且正在尝试创建一个表,并在CSV-file 上填充一些数据.
以下是尝试执行此操作的应用程序:
public sqlThingy() throws Exception {
File spritesheetsCreate = new File("sql/spritesheetsCreate.sql");
File spritesheetsData = new File("sql/spritesheetsData.sql");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection conn = DriverManager
.getConnection("jdbc:derby:TESTNAME;create=true");
//CREATE TABLE
try (PreparedStatement statement = conn
.prepareStatement(readFile(spritesheetsCreate))) {
statement.execute();
}
//FILL TABLE WITH DATA
try (PreparedStatement ps = conn.prepareStatement(readFile(spritesheetsData))) {
try (CSVReader rdr = new CSVReader(new FileReader(new File(
"res/spritesheets.csv")), ',', '"', 1)) {
for (String[] row : rdr.readAll()) {
ps.setString(1, row[0]);
ps.setString(2, row[1]);
ps.setInt(3, Integer.valueOf(row[2]));
ps.execute();
}
}
}
}
private …Run Code Online (Sandbox Code Playgroud) 这是我在下面的代码来自java教程 - 但是当我尝试接收从计算机发送的正常消息时,我的问题就出现了,而不是通过GMail发送.如果我通过GMail接收电子邮件它运行正常并返回邮件,但是尝试从传统桌面邮件客户端检索邮件返回
错误:
java.lang.ClassCastException: java.lang.String cannot be cast to javax.mail.Multipart
at gridnotifierproject_pcbuild.HandleMailInput.retrieveOneMail(HandleMailInput.java:37)
at gridnotifierproject_pcbuild.GridNotifierProject_PCBuild.main(GridNotifierProject_PCBuild.java:22)
Run Code Online (Sandbox Code Playgroud)
码:
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("imap.gmail.com", "***********@gmail.com", "******");
System.out.println("Established Connection to Server!");
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message msg = inbox.getMessage(inbox.getMessageCount());
System.out.println("Found specified Folder, retrieving the latest message...");
Address[] in = msg.getFrom();
for (Address address : in) {
System.out.println("FROM:" + address.toString());
}
Multipart mp = (Multipart) msg.getContent();
BodyPart bp = mp.getBodyPart(0); …Run Code Online (Sandbox Code Playgroud) 我想解析一个约会.当我使用以下日期格式时:
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMM d");
Run Code Online (Sandbox Code Playgroud)
随着字符串"星期一,5月19日",做
cal.setTime(sdf.parse(dateString));
Run Code Online (Sandbox Code Playgroud)
以短格式取出星期几,我得到了"星期二"!Cal的一周似乎设置为3.任何想法为什么?它将在5月份推出,每月推出19次,但它希望周二表示星期几,而5月19日肯定是我所在地区的星期一.
我想把int写入文本文件.我写了这段代码
public static void WriteInt(int i,String fileName){
File directory = new File("C:\\this\\");
if (!directory.exists()) {
directory.mkdirs();
}
File file = new File("C\\"+fileName);
FileOutputStream fOut = null;
try {
//Create the stream pointing at the file location
fOut = new FileOutputStream(new File(directory, fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
OutputStreamWriter osw = new OutputStreamWriter(fOut);
try {
osw.write(i);
osw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
但是在输出文件中我没有int,只有一个符号.有什么想法吗?