[질문] java 설치 후 설정, 컴파일, 실행

ggan85의 이미지

/etc/profile 설정 이렇게 하고

 JAVA_HOME=/usr/java/j2sdk1.4.2_05
 PATH=$PATH:$JAVA_HOME/bin
 CLASSPATH="."
 export JAVA_HOME PATH C해결방법LASSPATH

ColorRect.java 소스

      1 import java.awt.*;
      2 import java.util.*;
      3 import java.awt.event.*;
      4
      5 public class ColorRect extends Frame implements Runnable
      6 {
      7     Label l;
      8     int count=0;
      9     int x, y, red, blue, green;
     10     Random ran = new Random();
     11     Color c;
     12
     13     public ColorRect()
     14     {
     15         l = new Label("count");
     16         this.setLayout(new BorderLayout());
     17         add("South",l);
     18         addWindowListener(new WinListener());
     19         addMouseListener(new Mouse());
     20     }
     21
     22     public void run()
     23     {
     24         for(int i=0;i<5;i++)
     25         try{
     26             Thread.sleep(1000);
     27         }catch(Exception e){
     28             System.out.println("Thread error");
     29         }
     30         repaint();
     31     }
     32
     33     public void paint(Graphics g)
     34     {
     35         red = (int)(ran.nextLong() % 255);
     36         green = (int)(ran.nextLong() % 255);
     37         blue = (int)(ran.nextLong() % 255);
     38
     39         if(red < 0)
     40             red = -red;
     41         if(green < 0)
     42             green=-green;
     43         if(blue < 0)
     44             blue = -blue;
     45
     46         c = new Color(red, green, blue);
     47         x = (int)(Math.random() * 100 + 5);
     48         y = (int)(Math.random() * 100 + 5);
     49
     50         if(x < 0)
     51             x = -x;
     52         if(y < 0)
     53             y = -y;
     54
     55             g.setColor(c);
     56             g.drawRect(x, y, 20, 20);
     57     }
     58
     59     public static void main(String args[])
     60     {
     61         ColorRect r = new ColorRect();
     62         Thread t1 = new Thread(r);
     63 //      Thread t2 = new Thread(r);
     64
     65         r.setSize(300, 300);
     66         r.show();
     67         t1.start();
     68 //      t2.start();
     69     }
     70
     71     class WinListener extends WindowAdapter
     72     {
     73         public void windowClosing(WindowEvent we)
     74         {
     75             System.exit(0);
     76         }
     77     }
     78
     79     class Mouse extends MouseAdapter
     80     {
     81         public void mouseClicked(MouseEvent e)
     82         {
     83             int gx = e.getX();
     84             int gy = e.getY();
     85
     86             if( (x<gx)&(gx<(x+20))&(y<gy)&(gy<(y+20)) )
     87             {
     88                 count++;        
     89                 l.setText("count:"+count);
     90             }
     91         }
     92     }
     93 }

입니다.. 컴파일은 되는데 실행하면

[root@localhost java]# java ColorRect
returned
end
Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
   at 0x40268e17: java.lang.Throwable.Throwable(java.lang.String) (/usr/lib/./libgcj.so.3)
   at 0x4025bc8e: java.lang.Error.Error(java.lang.String) (/usr/lib/./libgcj.so.3)
   at 0x40329582: java.awt.AWTError.AWTError(java.lang.String) (/usr/lib/./libgcj.so.3)
   at 0x40340c9d: java.awt.Toolkit.getDefaultToolkit() (/usr/lib/./libgcj.so.3)
   at 0x4034146e: java.awt.Window.getToolkit() (/usr/lib/./libgcj.so.3)
   at 0x40332068: java.awt.Container.addImpl(java.awt.Component, java.lang.Object, int) (/usr/lib/./libgcj.so.3)
   at 0x40331ea6: java.awt.Container.add(java.lang.String, java.awt.Component) (/usr/lib/./libgcj.so.3)
   at 0x403831e7: ffi_call_SYSV (/usr/lib/./libgcj.so.3)
   at 0x403831a7: ffi_raw_call (/usr/lib/./libgcj.so.3)
   at 0x402306e8: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
   at 0x40230ff4: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
   at 0x4022e504: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
   at 0x4038305c: ?? (??:0)
   at 0x403831e7: ffi_call_SYSV (/usr/lib/./libgcj.so.3)
   at 0x403831a7: ffi_raw_call (/usr/lib/./libgcj.so.3)
   at 0x402306e8: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
   at 0x40230ff4: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
   at 0x4022e504: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
   at 0x4038305c: ?? (??:0)
   at 0x40242dd8: gnu.gcj.runtime.FirstThread.call_main() (/usr/lib/./libgcj.so.3)
   at 0x402ad02d: gnu.gcj.runtime.FirstThread.run() (/usr/lib/./libgcj.so.3)
   at 0x4024fc4c: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/./libgcj.so.3)
   at 0x4021c8ac: _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/./libgcj.so.3)
   at 0x08048910: ?? (??:0)
   at 0x42015574: __libc_start_main (/lib/tls/libc.so.6)
   at 0x080486c1: ?? (??:0)

이런 에러가 뜹니다.. 설정도 하고 컴파일도 되는데...
에러가 나는 이유와 해결방법좀 알려주세요~

fender의 이미지

지금 사용하시는 자바는 Sun이 아니라 GCJ/Classpath입니다. java -version해보세요. 참고로 CLASSPATH는 쓰지 마세요...

----------------------------
[서명] 그놈 한국 사용자 모임 - 그놈에 대한 모든 것! - 게시판, IRC, 위키, 갤러리 등등...

ggan85의 이미지

java version "1.3.1"
jdkgcj 0.2.3 (http://www.arklinux.org/projects/jdkgcj)
gcj (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

java -version 하니까 저렇게 나오는데..; gcj로 컴파일하고 실행해야 되는건가요?

fender의 이미지

아뇨... Sun자바가 실행되어야 하는데 PATH나 JAVA_HOME이 잘못 잡혀서 gcj/gij로 실행이 되는 것 같습니다. 한번 확인을 해보시고 정 안되면 java를 전체 경로를 다 써서 실행해보세요.

----------------------------
[서명] 그놈 한국 사용자 모임 - 그놈에 대한 모든 것! - 게시판, IRC, 위키, 갤러리 등등...

ggan85의 이미지

전체 경로로 하니 돌아갑니다..
감사합니다. ^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.