CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Sep 2011
    Posts
    197

    [RESOLVED] Confusing compiler error

    I just made a new method and, it's completely enclosed here it is

    Code:
        public String newObj(String paraM) {
     BufferedWriter bw = null;
     Writer w = null;
      try {
         bw = new BufferedWriter(new FileWriter(paraM));
         bw.write(paraM);
         return paraM;
    } catch (IOException ioe) {
    			}
                        }
    Code:
    client.java:10266: missing return value
                                                            return;
                                                            ^
    1 errors
    Finished!
    Press any key to continue . . .

    And, I have not even messed with that area? What is the real problem?

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    Re: Confusing compiler error

    If an exception is thrown in the try block, you won't get to the 'return paraM' line.
    You need another return statement to cover this possibility.

  3. #3
    Join Date
    Sep 2011
    Posts
    197

    Re: Confusing compiler error

    THanks one more question 'FileWriter' in my code what API class is that in? Do you know of any API methods that write values for a method?
    Last edited by kolt007; September 15th, 2011 at 01:20 PM.

  4. #4
    Join Date
    Jan 2009
    Posts
    596

    Re: Confusing compiler error

    Quote Originally Posted by kolt007 View Post
    THanks one more question 'FileWriter' in my code what API class is that in?
    I could tell you this, but why not just google 'FileWriter'? It pops straight up as the first result.

    Do you know of any API methods that write values for a method?
    Sorry, I'm not sure what this means.

  5. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Confusing compiler error

    public String newObj(String paraM) {
    ...
    return;

    missing return value

    The compiler wants you to return a String because that is what you have defined the method to do.


    'FileWriter' in my code what API class is that in

    FileWriter is a java class.

    See: http://download.oracle.com/docs/cd/E...se/6/docs/api/
    Norm

  6. #6
    Join Date
    Sep 2011
    Posts
    197

    Re: Confusing compiler error

    *solved*

    I am trying to return paraM now and, have another method listen for any paraM's... I'm not sure how to have another method listen though so any pointers on that will help.

    Code:
        public String newObj(String paraM) {
     BufferedWriter bw = null;
     Writer w = null;
      try {
         bw = new BufferedWriter(new FileWriter(paraM));
         bw.write(paraM);
         return paraM;
    } catch (IOException ioe) {
    			}
                                  return null;
                        }

    Code:
     public void NewObjects() {
    //global
    
    makeGlobalObject(2536, 4717, 2213, -1, 10);
     this.newObj();
    }
    Doesn't work this is what it say's

    Code:
     client.java:5636: newObj(java.lang.String) in client cannot be applied to ()
    this.newObj();
        ^
    1 error
    Finished!
    Press any key to continue . . .
    this <--- is the only listener I know of. I could really use something like a 'get'.
    Last edited by kolt007; September 15th, 2011 at 01:50 PM.

  7. #7
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Confusing compiler error

    way I could send it to another method

    What is the "it" you are talking about?

    have it be created in the newObj method? by it I mean paraM.

    paraM is a String, not a method. String's don't create things.
    Norm

  8. #8
    Join Date
    Sep 2011
    Posts
    197

    Re: Confusing compiler error

    I want paraM to be printed in NewObjects() method. I was hoping to use some sort of 'this' statement or listener do you know of any? I am seraching for one myself right now with little to no luck.

  9. #9
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Confusing compiler error

    I want paraM to be printed

    System.out.println("paraM=" + paraM);

    will print the String.
    Norm

  10. #10
    Join Date
    Sep 2011
    Posts
    197

    Re: Confusing compiler error

    the only thing is I want paraM to be printed in 'makeGlobalObject(paraM);'

    So idealy I would like
    Code:
     
     public void NewObjects() {
     
      print = new makeGlobalObject(paraM);
      paraM = this.newObj
    Then as soon as a new String of paraM gets passed through it initiates a new field for
    makeGlobalObject(paraM);
    antoher is initiated
    makeGlobalObject(paraM);

    etc....


    I can also set it up so paraM prints out makeGlobalOBject(parameters); if it helps so then you just send it to be saved at newObjects()



    SUM UP

    to sum up I want NewObjects() to listen for new 'paraM's then when new 'paraM's are sent through then print them either inside 'makeGlobalObject(paraM);' or 'paraM;' either way.
    Last edited by kolt007; September 15th, 2011 at 02:15 PM.

  11. #11
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Confusing compiler error

    I want paraM to be printed in 'makeGlobalObject(paraM);'

    Use this to print it:
    System.out.println("paraM=" + paraM);

    Your code makes no sense.
    Norm

  12. #12
    Join Date
    Sep 2011
    Posts
    197

    Re: Confusing compiler error

    Not in a printf I mean like E.G

    Lets say a paraM is invoked

    I want a new one to be printed as so

    makeGlobalObject(parameters);

    and, if another one is then print as so
    makeGlobalObject(parameters);

    and so on..

    keep in mind I can have paraM = just the parameters OR I can have it paraM = makeGlobalObject(parameters) the makeGlobalObject + parameters.



    *current efforts*

    Currently I am trying to 'invoke' the newObj method. But, the compiler keeps telling me
    Code:
    client.java:5596: newObj(java.lang.String) in client cannot be applied to ()
    invoke(newObj());
           ^
    1 error
    Finished!
    Press any key to continue . . .
    Last edited by kolt007; September 15th, 2011 at 02:20 PM.

  13. #13
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Confusing compiler error

    Sorry, I have no idea what you are asking.

    Maybe some other readers of this thread can help you.

    My only suggestion to you is that you take some time to learn the correct vocabulary for discussing programming problems.
    Also you should study basic programming concepts like what are methods and variables and how are they used.
    Norm

  14. #14
    Join Date
    Sep 2011
    Posts
    197

    Re: Confusing compiler error

    I don't mean this to sound 'snappy' (sorry couldn't think of anything better than snappy haha).

    I actually think my understanding of methods varibales constructs etc.. are quite sound it's just I am not good at trying to explain my problem using correct java terms. So I'll try in lamen terms as best I can.

    I want the 'paraM' (string) to be sent to 'NewObjects()' (method), and printed in either String or method form. Meaning printed like this

    Code:
     makeGlobalObject(paraM);
    ORR

    Code:
     paraM;

    I realize it's not likely I can transform a String into a method like makeGlobalObject(); BUT I have a formatting way of adding the makeGlobalObject part into the paraM like so:

    Code:
     newObj(" makeGlobalObject("+absX+", "+ absY+", " + object+", " + 
    
    objectDirection+", "+"10);");
    Although now looking at this I see a possiblity of just returning the value from that area directly... You'll have to forgive me I'm doing the best I can with what I got, no formal java training just the java tutorials and, this forum recently. So I have no idea what REAL programmers do, I tend to make a program, then have ideas on ways it could be better. It occurs to me know maybe I make the program/method (I haven't really created any programs really just a few classes that do simple things) the right way the first time by spending a little more time on the thinking part.

  15. #15
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Confusing compiler error

    Quote Originally Posted by kolt007 View Post
    I actually think my understanding of methods varibales constructs etc.. are quite sound
    I'm sorry to disagree with you, but in all your posts in the last few days you demostrated a lack of understanding of basic programming concepts. Take the good advice from Norm and spend some time learning a bit more about programming and Java.

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured