作者: luckiejacky 時間: 2009-4-1 17:53 標題: Simple Java program
If even simple console can't be created, where would be the problem? Only when I am in eclipse
- import java.io.Console;
- import java.sql.SQLException;
-
- public class MainDocument {
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- Console console = System.console();
- if (console == null) {
- System.err.println("sales: unable to obtain console");
- return;
- }
- console.printf("%s ", "string");
- }
- }
result: sales: unable to obtain console
I have set the path X:\Sun\sdk\jdk\bin to no avail.
Any suggestions?
[ 本帖最後由 luckiejacky 於 2009-4-1 17:56 編輯 ]
作者: thinkpanda 時間: 2009-4-1 18:08
原帖由 luckiejacky 於 2009-4-1 17:53 發表
If even simple console can't be created, where would be the problem? Only when I am in eclipse
import java.io.Console;
import java.sql.SQLException;
public class MainDocument {
public static vo ...
唔明你句英文寫乜野....
作者: luckiejacky 時間: 2009-4-1 18:12
Sorry.... I meant when I am running the application, the result "Sales: unable to get console" is shown.
I guess there is some configuration problem, and I forgot which...
When i run the application under command prompt, it is okay
- java myApp
but fail when I run under eclipse...
- Run >> run as java application
I have reboot the system, the same results came up
Another symptom is I can run the application as applet, but not application...
Another complement, when I run it using javaw.exe on the command prompt, nothing is displayed
Does anyone know why this happens?
- Console console = System.console();
After the call, console is null
Thanks
[ 本帖最後由 luckiejacky 於 2009-4-1 21:02 編輯 ]
作者: luckiejacky 時間: 2009-4-1 21:09
I had these errors when I compiled another set of application
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
- at CardLayoutFun3.getCardPanelInfo(CardLayoutFun3.java:58)
- at CardLayoutFun3.<init>(CardLayoutFun3.java:40)
- at CardLayoutFun3.createAndShowUI(CardLayoutFun3.java:218)
- at CardLayoutFun3.access$2(CardLayoutFun3.java:214)
- at CardLayoutFun3$2.run(CardLayoutFun3.java:232)
- at java.awt.event.InvocationEvent.dispatch(Unknown Source)
- at java.awt.EventQueue.dispatchEvent(Unknown Source)
- at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
- at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
- at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
- at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
- at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
- at java.awt.EventDispatchThread.run(Unknown Source)
So does anyone know what's going on?
Thanks
作者: hdvd-rom 時間: 2009-4-1 22:00
please read java se api the Console section(java.io.Console), then you will know why.
作者: luckiejacky 時間: 2009-4-7 21:12
Hello, what would be the general causes of these messages
- Exception in thread "main" java.lang.NoClassDefFoundError: test
- Caused by: java.lang.ClassNotFoundException: test
- at java.net.URLClassLoader$1.run(Unknown Source)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.net.URLClassLoader.findClass(Unknown Source)
- at java.lang.ClassLoader.loadClass(Unknown Source)
- at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
- at java.lang.ClassLoader.loadClass(Unknown Source)
- at java.lang.ClassLoader.loadClassInternal(Unknown Source)
- Could not find the main class: test. Program will exit.
Under dos command , and I have constructor
and how do i fix it? I've google, couldn't find the appropriate source
Thanks
[ 本帖最後由 luckiejacky 於 2009-4-7 21:20 編輯 ]
作者: thinkpanda 時間: 2009-4-7 23:37
原帖由 luckiejacky 於 2009-4-7 21:12 發表
Hello, what would be the general causes of these messages
Exception in thread "main" java.lang.NoClassDefFoundError: test
Caused by: java.lang.ClassNotFoundException: test
at java.net.URLClas ...
你邊度有個"test" 既class.
作者: luckiejacky 時間: 2009-4-8 11:28
Hello Panda Ching,
Sorry I did not mention, that is another program... I have the test class.....
Thanks a lot
作者: etkin 時間: 2009-4-8 16:32
原帖由 luckiejacky 於 2009-4-8 11:28 發表
Hello Panda Ching,
Sorry I did not mention, that is another program... I have the test class.....
Thanks a lot
class MUST start with capital letter....
JAVA is case sensitive....
frankly, I think you'd better read your books/notes carefully before asking these simple questions...
[ 本帖最後由 etkin 於 2009-4-8 16:33 編輯 ]
作者: 李且麒 時間: 2009-4-8 23:52 標題: 回覆 4# 的帖子
呢個係好常見嘅新手error - 你自己o向#3度都講左個Console object係null, 咁用一個null嘅object去invoke一個method, 當然會出NullPointerException啦
你要修改program嘅logic, Console object係null時, 就唔call printf()
至於#6, 你應該係無set PATH同CLASSPATH, 亦有可能係你用java test.java (而唔係java test)黎run個program
作者: patrickit 時間: 2009-4-9 08:19
呢句 :
if (console == null) { ... }
PHP 寫法... 我估你一定係寫開php啦....
作者: 十三 時間: 2009-4-9 10:20
提示: 作者被禁止或刪除 內容自動屏蔽
作者: luckiejacky 時間: 2009-4-9 16:27
Thanks all ching
I've checked everything
In summary,
Under Eclipse, it shows on the console window "Sales: unable to get console"
But under dos prompt, the app shows "string"...
So where should be the problem?
I am looking for some articles/documents for newbie in eclipse
Anyone knows? And when I delete the variable CLASSPATH, the app runs fine under dos prompt.
If I have CLASSPATH, stack traces occur...
Thanks
作者: t61 時間: 2009-4-9 16:39
老友, 你用 Eclipse 去 run 呢個program, Eclipse 係調用 JDK 下面既 javaw.exe
javaw.exe 是沒有 console 這個東西的, javaw.exe 使用來跑 Swing, AWT呢D野既.
你係 dos prompt 下面係用正常的 java.exe, 當然正常啦.
初初學 Java 都係唔好用IDE...
你俾呢個無謂既問題困擾佐甘耐...學從難處學, 用從易中用.
原帖由 luckiejacky 於 2009-4-1 17:53 發表
If even simple console can't be created, where would be the problem? Only when I am in eclipse
import java.io.Console;
import java.sql.SQLException;
public class MainDocument {
public static vo ...
[ 本帖最後由 t61 於 2009-4-9 16:43 編輯 ]
作者: luckiejacky 時間: 2009-4-9 16:58
原帖由 t61 於 2009-4-9 16:39 發表
老友, 你用 Eclipse 去 run 呢個program, Eclipse 係調用 JDK 下面既 javaw.exe
javaw.exe 是沒有 console 這個東西的, javaw.exe 使用來跑 Swing, AWT呢D野既.
你係 dos prompt 下面係用正常的 java.exe, 當然正 ...
Ok... Thanks, I understand now.... Thanks all ching

