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 9 of 9

Thread: Methods

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Methods

    Could someone help me with these questions?

    How do I create String array method? Is this correct?
    public static String [] getrandom ()

    How do I pass in String array into method?
    public static boolean getaccess (String[]randomNo,String realNo)

    How do I call that method. This is what I have done and it's giving me errors.
    getaccess(randomNo[],realNo);

    Thanks very much.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Methods

    it's giving me errors.
    Please copy and paste here the full text of the error messages.

    Args when calling a method should just be the names of the arg. Leave off the array notation: []
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Methods

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    at prog.ass.pkg3.ProgAss3.main

    I have one method to create 50 random Strings, second method for user input and third to compare them. I have done it in one method but I'm trying to do it in 3 methods.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Methods

    Did you understand the source change I suggested? Did that fix the problem?

    The error message does not give the source line where the problem is.
    Without the line number and the type of error, it is hard to know what the problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Methods

    Quote Originally Posted by Norm View Post
    Did you understand the source change I suggested? Did that fix the problem?

    The error message does not give the source line where the problem is.
    Without the line number and the type of error, it is hard to know what the problem is.
    Yes, I understood, but it didn't fix the problem.
    getaccess(randomNo,realNo); - cannot find symbol variable randomNo and realNo.

    Should I post the whole code?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Methods

    cannot find symbol variable randomNo and realNo.
    Where are those two variables defined? The compiler can not find their definitions in scope (within the same pair of {}s) at the line where they are being used.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Methods

    Quote Originally Posted by Norm View Post
    Where are those two variables defined? The compiler can not find their definitions in scope (within the same pair of {}s) at the line where they are being used.
    boolean access = getaccess(randomNo,realNo);
    String [] randomNo = getrandomNo();
    String realNo = getrealNo();

    OMG, i'm so ...
    boolean access = getaccess(randomNo,realNo) should be the last one called.
    Thanks a lot.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Methods

    Define and assign BEFORE using.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Methods

    Thanks again. Such a foolish mistake.

Similar Threads

  1. [SOLVED] Help with Methods
    By Blasfemmy in forum What's Wrong With My Code?
    Replies: 24
    Last Post: October 22nd, 2012, 08:18 PM
  2. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  3. Help with methods
    By CSUTD in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2011, 10:39 PM
  4. I need help with METHODS!!!
    By Slone in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 14th, 2010, 08:33 AM
  5. methods help
    By hockey87 in forum AWT / Java Swing
    Replies: 1
    Last Post: March 9th, 2010, 11:57 PM