Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

!!!! Why is the program non-functional ?  RSS feed

 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a Notes Application that Adds the note , displays the note or exits. It add/ displays title and its description.  I am unable to create a GUI of it. Where is the program going wrong.The NoteFrame class has main(). I am only getting a GUI box tht displays just  :
1. Add Note
2. To View Note
3. Exit

And  a click button besides it .And when i run the program in the Eclipse it shows  -> Not a Valid Option !!

Note class


Serialized class




Class NoteFrame






Class InputDetails





 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i run the program in the Eclipse it shows  -> Not a Valid Option !! 

What is the value in the choice variable when that message is displayed?  Print its value so you can see it.
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which bit of your application are you running?
I see two main methods there.
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Norm Radder
Whichever option i input , it shows -"Not a valid option" which is my default option in switch case.However , to add i am not even getting a proper window pane to enter the option. How to do that.


@Dave Tolls.

I have two main's but the InputDetails() main is independent of the NoteFrame main. Note frame option 1. ADD_NOTE only call InputDetails() and not its main. Is it improper to do so? 
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Not a valid option" which is my default option in switch case

Did you print out the value of choice that caused that message to be shown?  What was the value of choice that was printed?
Did that value make sense?

Please add code at line 89 to print out the value of choice for when the message is printed so you can determine why that message was printed.

Note: the default case is executed when there is no match to the other case statements in a switch statement.
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
Did you print out the value of choice that caused that message to be shown?  What was the value of choice that was printed?
Did that value make sense?



I corrected the code to make it work.




Its working little with new issues . I am getting stack Overflow error

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:5)
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:12)
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:12)
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:12)

code :

 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I do not see the value of choice that was supposed to be printed at line 89.
What was the value that was printed?

I corrected the code to make it work.

What did you change?


Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:5)
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:12)

What is the code at line 5 and line 12?
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Sorry, I do not see the value of choice that was supposed to be printed at line 89.
What was the value that was printed?

I corrected the code to make it work.  What did you change?


I changed the choice to text. previously it was int so was taking any default value not 1/2/3.


Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:5)
at com.techlabs.notes.businesslayer.Note.<init>(Note.java:12)

What is the code at line 5 and line 12?



I refactored the code in Note class.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The switch statement now takes String values.  The value from the getText() method could be passed to displayMenu without converting it to int.

I refactored the code in Note class.

Does the code work now?
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Norm
Yes it works.

But it still has loopholes in it. All the previously stored Notes don't appear in the window frame as it used to when i did the program using normal eclipse console. I want all of them. It just shows the last updated Note.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the previously stored Notes don't appear
It just shows the last updated Note.

What GUI component(s) is used to display the Notes?  What is the name of the variable that holds the reference to that component?
What statement(s) are used to add the Notes to the GUI component so that they are shown?

For example with a textarea component:
the setText() method changes the contents to the value passed in the method
the append() method adds the passed contents to the current contents
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:

For example with a textarea component:
the setText() method changes the contents to the value passed in the method
the append() method adds the passed contents to the current contents



Can you please  give some other suggestion. The append() is working the same way. no change.


 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
previously stored Notes don't appear

Please post the code that is loading the GUI component with the Notes so we can see how it is being done.

Also please answer these questions that I asked before.

What is the name of the variable that holds the reference to that component?
What statement(s) are used to add the Notes to the GUI component so that they are shown?


Also add a print statement to the code that prints out the contents of the container that is holding the Notes to see how many Notes there are.
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
Please post the code that is loading the GUI component with the Notes so we can see how it is being done.

Also please answer these questions that I asked before.

The normal console in eclipse  output you get is :

Write to the Console
1. Add Note
2. To View Note
3. Exit
2
The number of notes are:1
Displaying Note

Id = 1
Title :vaibhav
Description : siebel,birlasoft

Write to the Console
1. Add Note
2. To View Note
3. Exit

1
Enter : 1. Id already present or 2. To create a new Note
2
Enter the id
2
Enter the title
Book
Enter the description
Dan Brown, Sidney Sheldon
--------------------
Write to the Console
1. Add Note
2. To View Note
3. Exit
2
The number of notes are:2
Displaying Note

Id = 1
Title :vaibhav
Description : siebel,birlasoft

Id = 2
Title :Book
Description : Dan Brown, Sidney Sheldon

Write to the Console
1. Add Note
2. To View Note
3. Exit
3
Exit

And in the JFrame Console you get the output  -
As only  one note.

Id = 1
Title :vaibhav
Description : siebel,birlasoft

it doesn't show the previous outputs.






What is the name of the variable that holds the reference to that component?
What statement(s) are used to add the Notes to the GUI component so that they are shown?











Also add a print statement to the code that prints out the contents of the container that is holding the Notes to see how many Notes there are.



means hw to do tht using JLabel ?  can you please write syntax
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And in the JFrame Console you get the output  -
As only  one note. 

What is a "JFrame Console"?

can you please write syntax

In the displayNotes method add this to show the contents of the list of Notes:
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Norm.

Jframe Console is Jframe . The frame where i get click, Add note,view note, exit ,...

I put the
System.out.println("retrieveNote="+retrieveNote) in displayNotes -
It shows only the recently updated Note, not all the notes.

Thanks
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It shows only the recently updated Note, not all the notes.

Where is the ArrayList created that is supposed to hold the Notes?  If it is created each time then it will only hold the last one:
 
Jframe Console is Jframe .

What GUI component in the JFrame is used to show the Notes? What is the name of the variable holding the reference to that component?
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i created an ArrayList<Note> notelist1 = new ArrayList<Note>();

ANd it shows all the previous notes.

 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Norm please check line number 3 and 9
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  it shows all the previous notes

Is the code working now?
 
Sucheta Shrivastava
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes . Thank You !
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good.
I see you changed line 10 from:
JOptionPane.showMessageDialog(frame, notelist);   // Shows one Note
to
JOptionPane.showMessageDialog(frame, notelist1);  // Shows contents of List
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code on this thread needs some refactoring.  Are there any volunteers?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!