Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: throws Exception error

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default throws Exception error

    In my neatbens project I have two java class

    First java class have two function.
    public void e()
    public static void f(String[] args) throws Exception


    second java class named rezultati have functions like:
    public void a()
    public void b()
    public void c()
    public void d(String[] args) throws Exception

    if in first java class in function f i use comand:

    rezultati objekt = new rezultati();
    objekt.d(args) or objekt.a(), or objekt.b()

    its ok but if I like use command objekt.d(args) in public void e() I get error. How I can call objekt.d(args) from ublic void e()?

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    94
    My Mood
    Cool
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: throws Exception error

    You should be able to. So you must not be providing sufficient information. Please construct a small example that has complete code that demonstrates the problem.

    Regards,
    Jim

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,425
    Thanks
    52
    Thanked 2,313 Times in 2,269 Posts

    Default Re: throws Exception error

    I get error
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Dec 2017
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: throws Exception error

    I get error message:
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method sestej() cannot be referenced from a static context
    at preprosti.Preprosti.main(Preprosti.java:27)
    C:\Users\Igor\AppData\Local\NetBeans\Cache\8.2\exe cutor-snippets\run.xml:53: Java returned: 1
    BUILD FAILED (total time: 1 second)

    I send link with example
    https://www.dropbox.com/s/dcyehl7dyv...rosti.zip?dl=0

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,425
    Thanks
    52
    Thanked 2,313 Times in 2,269 Posts

    Default Re: throws Exception error

    non-static method sestej() cannot be referenced from a static context
    The method sestej is an instance method that can only be called when an instance of the class exists using a reference to that instance.
    It can not be called from a static method without using a reference to the instance of the class.
    For example:
       rezultati objekt = new rezultati();    // create instance of class
       objekt.d(args);                               // use reference to instance to call method
     
       d(args);                                        // not allowed if this code is in static method

    I send link with example
    Please post all code and examples here in the thread, not via a link
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. ExecuteUpdate throws exception
    By bodylojohn in forum What's Wrong With My Code?
    Replies: 13
    Last Post: February 2nd, 2014, 04:17 AM
  2. [SOLVED] TableRowSorter throws Exception
    By Onur in forum AWT / Java Swing
    Replies: 1
    Last Post: November 7th, 2013, 06:23 AM
  3. Singly Linked List of Integers, get(int i) function throws Null Pointer Exception
    By felixtum2010 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: June 23rd, 2011, 07:55 PM
  4. ZipInputStream Throws Illegalargument exception for diacritics
    By meghaladevi in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 12th, 2010, 03:32 AM
  5. [SOLVED] File.createTempFile() throws exception on Win7
    By jitinsingla in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 10th, 2010, 03:14 PM