Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Music transcription program  RSS feed

 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Javaranch programmers,
I have made an initial stab at my Guitar program,
Starting with the tablature to music score transcription.
My first step would be for inputter to determine how many notes they
will want transcribed, and then to produce a GUI of that number of
notes x 6 - being the number of strings.
Inputter would then input numbers to textboxes in grid thus produced,
the Gui may run into several pages, but that bridge will have to be
crossed when this one has been. The obstruction being that compiler
returns 'cannot be dereferenced' to my attempt to reference the
length of the 'Notes' variable, as placed in the String array in the
creation of the JPanels. The syntax has worked before, but not now. I
wanted to know where I am going wrong.
Thank you for reading.
I look forward to hearing from any of you re this.
Yours
Mary Dawson.(Trainee Programmer)

gets:


 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There I was, going helpfully to do a search for the last time anybody asked about music programs. And I found just what I had seen, posted by Mary Dawson.

Sorry I can't help more.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,

I think what's happening is that your trying to do this:

1.length(); (where 1 is a primitive int)

int's aren't objects, so you can't call length() on them.

Hope that helps!
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,
I am experiencing a problem with my music program code.
It keeps returning a null pointer exception.
The idea was to create a set of panels representing input to a question as to how many strings the instrument has, and then labels to go into those panes to a question as to how many notes the tune has. I recognise that the Strings need not be requested, and be fixed at 6, and the only input to establish the gui would be the notes input.
But apart from that (it could after all then be used for a lute/ mandolin, or od etc's music ) I am getting a null pointer exception return.
The JOption panes appear, and take input, it is when the second JOption pane is okayed, that the console returns a null pointer exception.
Program 'MusicOne' is based on program 'Music' which runs okay, and which I enclose below, to give you an idea of what I am aiming for.
Why is this? how can I get around this? Thank you for listening, and thank you for helping (if you can)
I enclose the code and console response to that code below.
Yours
Mary Dawson (programming student)


returns:-









[/CODE]
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I probably shall be fast asleep before you answer, but please supply a copy of the stack trace. It makes it a lot easier to track down an Exception when you know where it occurred. We need to know the details.
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mr Campbell Ritchie, and Ranchers,
I did put in the console response to the program MusicOne, I just put in the code to program Music, below, which does run okay, to show what direction I want to take the program in. I enclose the console response to program Music below, but that isn't the problem program - MusicOne is, which I have given the console response to, as said.
I hope you can give me some idea as to how I might get it to compile, and where I am going wrong with my coding thus far.
Thank you for your help.
Yours Mary Dawson (programming student)

gives, to JOptionpane inputs of 5 and 6 respectively :-
 
Campbell Ritchie
Sheriff
Posts: 55329
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error messages are you getting?
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Campbell Ritchie, & other Ranchers,
I am not getting an error return from console, just a null pointer exception. I've realised I haven't put in all the requisites to generate a GUI.
Here is a revised version of program 'MusicOne'.
However though it compiles and takes input to the JOptiopane requests, it still
returns the null pointer exception, the original problem.
I hope you can point me in the right direction. It occurred to me to ask - is there a 'Build your own customised / DIY guide to GUI design' out there you could recommend ?
Thank you for reading, and for your help.
Yours
Mary Dawson. (Programming student)


after inpuitting say numbers 5 & 6 to JOption pane requests, gives:-
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

What's the code at line 34? The code example you posted doesn't quite match up with the numbers I suspect.
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Martin,
You're right - I must've forgot to recompile. (Hey - perhaps it'll run- but hang about, isn't it Friday the 13th ?)
Will get back to you.
Cheers,
Mary (programming student)
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Martin/Ranchers,
I did compile it, upon reconsideration.
I can verify the line compiler is pointing to suspiciously/inauspiciously is:-


This means to my understanding, that JLabel object as incremented by outerloop of j from 0 to value of 'Notes' (as initialised by inputter)
creates new JLabels.
Next line says that JPanel object p[defined by innerloop of i from 0 to value of 'Strings' (as initialised by inputter) method calls add to put those JLabels in those generated JPanels, thus hopefully creating a gui of JPanels, equivalent to input defined integer 'Strings' holding JLabels, equivalent to input defined integer 'Notes'.
The syntax used has worked before, so why not now (I was wondering).
Anyway, if that is the only problem, I would be pleased if you could help me solve it.
Thank you for your help, and I look forward to hearing from you.
Yours
Mary Dawson, (Programming Student)
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I'm going to be deliberately slightly unhelpful here, as this is a great chance to learn!

* What I suggest you do is print out the values of i and j as it goes through you loop.
* Also print out the contents of p and label as you go.

So something like:

Logger.debug("i is [" + i "]");
Logger.debug("j is [" + j "]");
Logger.debug("p contains:");
for (int 0; x < p.length; x++)
{
Logger.debug("p item [" + x + "] is [" + p[x] + "]");
}
// add for loop for label array printing out
..
...
..

Best of luck!!
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Martijn & other Ranchers,
I have recoded the MusicTest program, having followed your
instructions, re: putting System.out.println( ) to see what its
doing. I have got it to run, but the Gui appears for only a split
second - how can I get it to stay fixed on the screen for more than
a millisecond?
Hope you can give me some advice on this.
Thank you for reading, and for your help & advice thus far.
Yours
Mary Dawson, (Programming Student)


gives, to the console (along with cameo gui):-
 
Rob Spoor
Sheriff
Posts: 21047
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Skip the System.exit(0) call. Unlike modal dialogs, calling setVisible(true) on a frame will not block. Therefore, right after that call, System.exit(0) is called and the application quits.
If you want to exit your application if the frame is clicked away, that call to setDefaultCloseOperation will suffice.
 
Mary Dawson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Rob Prime, Martijn & other programmers,
I have lost the System.exit(0); line as you advised, and the gui endures so that I can see that it unfortunately does not contain the JPanels nor JLabels that I had hoped it would.
I was wondering if this was due to fundamental errors - say in the looping instancing of the JLabels & JPanels or would it be in the presentation part of the code ie:setVisible(true), setSize(500,500) etc methods?
I had thought that as the code output to console is that generated by the loops that the JLabels and JPanels would've been instanced - so why arent' they in evidence?
I haven't quoted the program MusicTest again, as it is the same as before, minus the System.exit(0); line.
I hope you might be able to point me in the right direction.
Thank you for your help so far, and I hope to hear from you in regard of this.
Yours
Mary Dawson (Programming Student)
 
Rob Spoor
Sheriff
Posts: 21047
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll have more success in the Swing forum. Moving.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!