Results 1 to 10 of 10
  1. #1
    Nageshpune is offline Member
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    6
    Rep Power
    0

    Question when i am runing this program i am getting problem with Exception in thread "main"

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Add.main


    import java.lang.*;
    import java.io.*;

    class Add {
    int a=6,b=7;
    int z=0;
    z=a+b;

    public static void main(String args[])
    {
    int a;
    int b;
    a=10;
    b=10;

    Add s1=new Add();
    System.out.println(s1.z);
    System.out.println(s1.a);
    System.out.println(s1.b);
    }}

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    So can you actually compile it with the javac command?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    You cannot separate the declaration and initialization of the "z" variable at the class level. That's why you got a compile error.

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    This line: z=a+b; needs to be inside a method. Change the declaration of z to : int z = a+b;
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    Nageshpune is offline Member
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    6
    Rep Power
    0

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    Yes it is compiling but it's throwing the error java.lang.Error: Unresolved compilation problem: when i am runing this program i am getting problem with    Exception in thread "main"-1.png

  6. #6
    Nageshpune is offline Member
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    6
    Rep Power
    0

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    i have done inside the method. but when i am putting outside the method error is coming.............. why?

  7. #7
    Nageshpune is offline Member
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    6
    Rep Power
    0

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    when i am runing this program i am getting problem with    Exception in thread "main"-2.png i have done inside the method. but when i am putting outside the method error is coming.............. why?

  8. #8
    Nageshpune is offline Member
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    6
    Rep Power
    0

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    yes it's working thank you

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    Quote Originally Posted by Nageshpune View Post
    Yes it is compiling
    Your screenshot proves it is NOT compiling :/

    @PhHein: you win for this one; Netbeans is really NOT helping here.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    Nageshpune is offline Member
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    6
    Rep Power
    0

    Default Re: when i am runing this program i am getting problem with Exception in thread "m

    Yes Finally it's working thank you Mr. PhHein


    class Add {
    int a=6,b=7;
    int z=a+b;
    public static void main(String args[])
    {
    int a;
    int b;
    a=10;
    b=10;
    Add s1=new Add();
    System.out.println(s1.z);
    System.out.println(s1.a);
    System.out.println(s1.b);
    }}

Similar Threads

  1. Replies: 4
    Last Post: 12-22-2012, 06:40 AM
  2. Replies: 1
    Last Post: 11-02-2012, 11:38 PM
  3. Replies: 2
    Last Post: 06-20-2012, 12:18 AM
  4. Replies: 5
    Last Post: 12-21-2011, 06:44 PM
  5. Replies: 5
    Last Post: 06-22-2010, 03:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •