[자바] 이거 왜 애러가 나는거죠???

여리왕자의 이미지

자바를 3년만에 다시 만져서...

처음부터 예재를 하나씩 연습해 가는데...

소스코드가 전혀 문제가 없는데 자꾸 애러가 납니다... ㅠㅠ

class Exam {
	int c;

	public int add( int a, int b ) {
		c = a + b;
		return c;
	}
}

public class ExamTest {
	public static void main(String[] args) {
		int sum; 
		int x, y;
		
		x = Integer.parseInt( args[0] );
		y = Integer.parseInt( args[1] );

		Exam examobject = new Exam();

		sum = examobject.add( x,y );

		System.out.println("입력받은 숫자는" + sum + "입니다");
	}
}

스트링형을 매개변수로 받아서 정수형으로 변환하여 집어넣는부분

x = Integer.parseInt( args[0] );
y = Integer.parseInt( args[1] ); // 요부분이죠....

에서 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ExamTest.main(ExamTest.java:15)

라고 애러가 납니다... 애러의 계열은 주로 배열의 참조범위를 벗어나서 나는 애러라고 나는데....

전혀 문제가 없어 보이네요.... 참고로 jdk1.5.0_04 버젼 쓰고요,
애플리케이션은 Edit_Plus 쓰고 있습니다....

한수 가르쳐 주십시오.... ㅠ.ㅠ;;

익명 사용자의 이미지

It worked fine for me.
(sorry no korean on this computer.. --;;)

I think you are not adding the right argument when running the application.

java ExamTest 5 6

여리왕자의 이미지

but.... 지금부터 한글 쓰겠습니다...

도스 모드에서 인수 주고 입력하니 잘 되더군요...

근데 제가 에디트 플러스에서 실행할때 사용자도구 부분에서 인수를 주고 실행시켰을때는 안되는군요...

제가 실행을 잘못 한건지....

java.lang.NoClassDefFoundError: 7     // 7은 인수로 입력한 숫자임

인수 묻는 창이 뜨길래 인수를 입력하고 실행을 하니깐 저런 애러가 뜨는군요...

제가 에디트 플러스를 어설프게 써서 그런것 같은데...

저렇게 애러가 나는 이유 아시는 분은 답변좀... ㅠ.ㅠ;;;

아... 끝없는 프로그래밍의 세계... 정복하고파...

익명 사용자의 이미지

에디트 플러스에서 실행할때 잘못하시는거 같네요.
명령이 java 7 이렇게 들어가는 것으로 보입니다.
잘 수정해보시길...

tinywolf의 이미지

java [classname] 7 이렇게 들어가야 되는데..
java 7 이라고 들어가는 것같다고 하시는 군요.
인수로 정확히 무엇이 들어오는지 찍어보는 것도 좋을 것같구요.

System.out.println("인수0 : \"" + args[0] + "\"");
System.out.println("인수1 : \"" + args[1] + "\"");

요렇게..
제가 게으른 프로그래머라 그런지 디버깅할 때는 다른 도구들은 진짜 모를때 어쩔 수 없이 쓰게되구
보통은 저렇게 의심나는 부분을 출력해 보곤 하지요.

ㅡ_ㅡ;

binul의 이미지

EditPlus의 User Tools Configuration을 확인해 보세요.

저 같은 경우, 컴파일을 위해서는

Command: javac.exe
Argument: $(FileName)
Initial Directory: $(FileDir)

Capture output: checked

컴파일에 옵션을 주기 위해서는, 위의 옵션에

Prompt for arguments: checked

실행을 위해서는

Command: java.exe
Argument: $(FileNameNoExt)
Initial Directory: $(FileDir)

실행 인자를 주기 위해서는 위의 실행 옵션에

Prompt for arguments: checked

애플릿 실행을 위해서는

Command: appletviewer.exe
Argument: $(FileNameNoExt).html
Initial Directory: $(FileDir)

등으로 설정하여 쓰고 있군요.

--------------------------------
그래날아보자꾸나

익명 사용자의 이미지

오늘 들어와본 후 답변을 보고 바로 해결했습니다..

실행할때 원래 명령을 java.exe 로 뒀었는데....

java $(FileNameNoExt) <---- 이렇게 두고

인수를 7로 주니 되는군요...

물론 java.exe 를 명령으로 두고 인수를 [클래스명] 인수 이렇게 둬두 되구요..

아무튼.... 답변들 감사합니다.... ^^;

복 받으실꺼에요~

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.