Page 10 of 11 FirstFirst ... 891011 LastLast
Results 181 to 200 of 219
Like Tree22Likes

Thread: How to do this?

  1. #181
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: How to do this?

    The formatting is poor making it hard to see the logic.

    Try debugging it by adding some println statements to show the execution flow.
    Last edited by Norm; 03-13-2014 at 02:09 PM.
    If you don't understand my response, don't ignore it, ask a question.

  2. #182
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to do this?

    Hmm. Shame on my head - I really tried to stay out of this thread ...

    @TAWI:
    I hope you don't want to tell us, that this code is readable at all.
    -> Get good names that people can understand! xyz and xyzisi0/1/2/3 is simply not saying anything (or is it just something in your native language?)
    -> You know the switch/case statement - that would make it much easier to read.
    -> A common practice: If you have code in 2 places: Put it in a function and call the function (This might be needed in your switch statement because some parts might be double.)
    -> A common practice: if a function gets to long or you have to many { in each other: split the function up into multiple functions. (But all with names giving details what the function is really doing! And a name like "xyz is 0" is simply not giving details what the function is doing. The name should not tell when it is called which could change with the time. It should say what it is doing! So if I have a taxi Class I want a Function "DrivingToTargetLocation" and not "PassengerEnteredCar".)

    Maybe you try to understand these points. If you are able to rewrite your code in a way that you can read it yourself, then you might have the answer to your question.

    And one last point:
    I am quite new to this forum. Inside the MSDN Forums there was always the request to open a new thread for a new problem. That way you get a collection of threads that hopefully have meaningful subjects ("How to do this?" is also an example for a bad "naming") that might help others who used a search engine to find a solution to their problem (which might be like your problem.)

    With kind regards,

    Konrad

  3. #183
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: How to do this?

    Quote Originally Posted by kneitzel View Post
    Hmm. Shame on my head - I really tried to stay out of this thread ...
    Join the club!
    kneitzel likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #184
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: How to do this?

    Have you heard the story about the "tar baby"?
    If you don't understand my response, don't ignore it, ask a question.

  5. #185
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: How to do this?

    He he no, but Google knows it :)

    Tar-Baby - Wikipedia, the free encyclopedia
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #186
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: How to do this?

    Guys, I updated the code, please, I still have NPEs, how to fix these NPEs? These NPEs occur in the login and calculation part. Please help to solve this.
    Attached Files Attached Files

  7. #187
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: How to do this?

    I still have NPEs,
    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 response, don't ignore it, ask a question.

  8. #188
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,082
    Rep Power
    4

    Default Re: How to do this?

    Quote Originally Posted by Tawi View Post
    Guys, I updated the code, please, I still have NPEs, how to fix these NPEs? These NPEs occur in the login and calculation part. Please help to solve this.
    In the stacktrace of an NPE is a line number where it was caused. Check that line for any variable that has 1) a null result from a function call or 2) was not properly initialized. We can't keep holding your hand with this form of basic debugging.
    Norm likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #189
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to do this?

    IMO, the solution at this point is to hire an actual programmer to completely rewrite this pile of garbage. I'd bid on it, but I'm already fully employed.
    Get in the habit of using standard Java naming conventions!

  10. #190
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,082
    Rep Power
    4

    Default Re: How to do this?

    I pity the user who has to work with this program. A userinterface like an average Geocities page comes to mind, strangely enough...
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  11. #191
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: How to do this?

    I tried my best but was unable to find the problems. Please find it, will you?

  12. #192
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: How to do this?

    Not sure what to suggest other than what was said in post#189
    If you don't understand my response, don't ignore it, ask a question.

  13. #193
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to do this?

    I agree fully to SurfMan (#190).

    And this Tar Baby story was unknown to me, too. But it was quite interesting to read the story which explained this wording. And yeah - it fits to this problem so maybe SurfMan found the only solution.
    (Or maybe finally Tawi understands that to complex stuff is not a good starting point to learn the basics.)

    With kind regards,

    Konrad

  14. #194
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: How to do this?

    Guys, how to stop this from running again and again? I reduced the NPE to one but this is running again and again without stop so> What shall I do?

    I cannot copy and paste the error messages so please help me.
    Attached Files Attached Files

  15. #195
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: How to do this?

    I cannot copy and paste the error messages
    Why? They have important information about the error.


    how to stop this from running again and again?
    Do you mean the program has an infinite loop and keeps running? There have been many discussions on this thread on how to find them. One technique was to add lots of println statements. The place where the loop is happening will be between the last printed message and the println that did not print.
    If you don't understand my response, don't ignore it, ask a question.

  16. #196
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: How to do this?

    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    NaN
    3


    What is the meaning of those outputs? The problem of putting plenty of prinln is I do not know the process that those println belong to. How to know that?
    Last edited by Tawi; 03-15-2014 at 04:35 PM.

  17. #197
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: How to do this?

    problem of putting plenty of prinln is I do not know the process that those println belong to
    Yes, just printing a number without a unique label with the number makes it hard to tell where it was printed.
    Add a unique id String with each println() so the print out can be tied to the println() that printed it. For example:
    Java Code:
    System.out.println("an ID here "+ theVar +"<");
    Add an ending delimiter: "<" for Strings so you can see empty vs blank Strings.
    If you don't understand my response, don't ignore it, ask a question.

  18. #198
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: How to do this?

    How can println give an invalid result to a JTextField?

  19. #199
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to do this?

    Hi,

    just in case that you do not know what the NaN means: That is short for Not a Number. This is defined by IEEE 754 which describes floating point arithmetic and Java follows this standard.
    IEEE floating point - Wikipedia, the free encyclopedia

    And maybe we forgot to mention the topic "readability" in this thread (or on this side of this thread): Make sure that all you write or output or whatever is readable. So Norm is 100% correct in his point. I just want to extend it a little:
    It is always a good idea to have output exactly what you do. So I like output like:
    System.out.println("X := " + x);
    or
    System.out.println("After loop through all elements: X := " + x);
    or when calling a function:
    System.out.println("Calling SomeFunction(" + param1 + ", " + param2 + ")");

    With such output you can easily read what is going on.

    You could even use some logging framework so instead of printing to a screen you can configure at runtime what should be done with log messages. I would suggest to check log4j.

    With kind regards,

    Konrad

  20. #200
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: How to do this?

    Quote Originally Posted by Tawi View Post
    How can println give an invalid result to a JTextField?
    System.out.println is not giving anything to a JTextField. It just outputs something to the terminal.
    (Or did you try to be smart and placed a lot of things inside a single line / println command? Then yes - maybe you assigned something inside the call but then it is still not the println function that is giving an invalid result.)

    With kind regards,

    Konrad

Page 10 of 11 FirstFirst ... 891011 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
  •