Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

intValue() error  RSS feed

 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am copying code into existing code (working program).
Everything was going great until I got to this line of code with the intValue()

I'm getting a red error with this message:

cannot find symbol
symbol: method intValue()
location: class Object






I am cursing because of this.  I have copied  dozens of lines with no complaints from Java and now this.
I haven't a clue what to do.

Any guidance would be appreciated. I could copy all of the good code if you think that may help?

TIA
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What data type does getNextTicketNCF() return?
 
Junilu Lacar
Sheriff
Posts: 10883
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to tell because of the poor alignment of your code and the ellipses. On line 3, I can't tell whether the reference to s as the argument to the Transaction constructor is valid. The closing braces and parenthesis on line seem to be matched correctly with their respective opening symbols but it's hard to tell because of the missing code and the poor alignment. Then, the opening brace on line 1 would be matched by a closing brace after line 9 but you don't show that much code so we just have to assume it's there.
 
Junilu Lacar
Sheriff
Posts: 10883
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:What data type does getNextTicketNCF() return?

Of course, this is the real question that should be answered to address the question OP posed. I got so caught up pointing out the other things that were muddying up the code snippet that I lost sight of the main problem.  
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:What data type does getNextTicketNCF() return?



I think the best way to get to the heart of the matter would be for me to show you the code that I am trying to insert.
I can't answer the above question because my programming skills are not at that level.

Here is the page where I am taking the code:

How to Create New Sequence

And here is the code:

Make changes to the TicketInfo.java file (com/openbravo/pos/ticket/TicketInfo.java)




Editing DataLogicSales.java file (com/openbravo/pos/forms/DataLogicSales.java). This file contains all the logic needed to interact with the database. It is kind of tricky to see the changes on this ones, but I suggest looking at the SQL queries.




There is more code. I stopped at the spot I was getting the error.
Basically I am supposed to replace the code between the ...  ...
and leave everything else alone.

Thanks again for your help!



 
Junilu Lacar
Sheriff
Posts: 10883
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the page that you cited, it looks like getNextTicketNCF() returns an Integer which does have an intValue() method though.  You can try changing that to just getNextTicketNCF() since autoboxing/unboxing will take care of conversion to/from int/Integer.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:From the page that you cited, it looks like getNextTicketNCF() returns an Integer which does have an intValue() method though.  You can try changing that to just getNextTicketNCF() since autoboxing/unboxing will take care of conversion to/from int/Integer.


Thanks Junilu for helping!

So I just went back to the code now.
I need to fill you in on what happened just before I get this error.

When I first input this code:



I receive this error with the whole line underlined in red:
cannot find symbol
symbol: method getNextTicketNCF()

I then create a method as suggested (by double-clicking on the code) which satisfies java to an extent.
It removes the red line except for the .intValue part.

That part remains underlined with this error:
cannot find symbol
symbol: method intValue()
location: class Object

If I try to remove .intValue as you suggest,
it underlines getNextTicketNCF() and says:

incompatible types: Object cannot be converted to int


All the other code I have entered so far before and after this seems to be OK, no errors.
And there was quite a lot of code.
I hope I can get this fixed.
 
Junilu Lacar
Sheriff
Posts: 10883
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the code on that page immediately below where the code that you copy/pasted here stopped, you'll see the definition of the getNextTicketNCF() method that you need. The one you created returns Object instead of Integer, which is what the original version returns.
 
Junilu Lacar
Sheriff
Posts: 10883
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the code snippet right before the Step 3 heading, the one with a comment that says // line 528
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:It's the code snippet right before the Step 3 heading, the one with a comment that says // line 528


Thanks again for helping out Junilu!

I have attempted to insert a method just before the place I was getting the red error.

I am inserting:



just before the following now:






The yellow error I now get for
the public final Integer getNextTicketNCF()
is "missing @ return tag, surround with ..."

The yellow error I now get for
ticket.setTicketNCF(getNextTicketNCF().intValue());
is "Unnecessary unboxing, surround with...
introduce..."

I hope this will help.
 
David Henstridge
Ranch Hand
Posts: 79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got some good news and some bad news to report.

First the good news.

I experimented with the errors and was able to eliminate them.

For the first error I let it fix itself.
For the second error it suggested I remove the .intValue(), which I did.


Now the bad news.
After I compiled the code I ran the java program.
There is a key, main sales screen that is supposed to come up when the program starts.
It is not coming up now. 

Other screens/menus are also not coming up.

 
Campbell Ritchie
Sheriff
Posts: 54030
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we would need more details before we can help.
I am also suspicious about that website; it uses variable names which don't follow Java® naming conventions, and that makes me suspicious about the whole site I am afraid.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I think we would need more details before we can help.
I am also suspicious about that website; it uses variable names which don't follow Java® naming conventions, and that makes me suspicious about the whole site I am afraid.


I am making very good progress on this.

I am now able to run the java program and have it bring up the main sales screen. All other screens function again as well.

There is one hiccup that I need to overcome now.
When I initiate a new sale, at the payment screen I get the following error:

NOT_00_0000
Notice: Unable to Save Sales Ticket

com.openbravo.basic.BasicException:
java.sql.SQLIntegrityConstraintViolationException: Column 'ID'  cannot accept a NULL value.

java.sql.SQLIntegrityConstraintViolationException:
Column 'ID'  cannot accept a NULL value.

org.apache.derby.impl.jdbc.EmbedSQLException:
Column 'ID'  cannot accept a NULL value.

org.apache.derby.iapi.error.StandardException:
Column 'ID'  cannot accept a NULL value.


If I can figure out which ID column they are talking about, I think I can nail this one.






 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I somehow managed to get it to work! 
 
Campbell Ritchie
Sheriff
Posts: 54030
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somebody has used the NON NULL command when creating that column in the database, so it throws an Exception if you try to insert NULL. You must put a real value in that column, and probably must not try to miss that column out when INSERT‑ing.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Somebody has used the NON NULL command when creating that column in the database, so it throws an Exception if you try to insert NULL. You must put a real value in that column, and probably must not try to miss that column out when INSERT‑ing.


It was I who created the table and the column (ID).
I actually had created the column with a NULL command.

I had difficulty trying to find the right syntax to Alter the column from NULL to Increment by 1,
so finally I just bit the bullet, deleted the table and created a new one using the following syntax:

 
Campbell Ritchie
Sheriff
Posts: 54030
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of database programs have a datatype called SERIAL or similar; that incorporates AUTOINCREMENT and is intended for primary keys, IDs, etc. Have you tried that? Note getting an int may cause difficulties because the SERIAL is probably an unsigned 64‑bit integer. It will probably behave like
(int)123456789101112L
It probably also implies NOT NULL.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:A lot of database programs have a datatype called SERIAL or similar; that incorporates AUTOINCREMENT and is intended for primary keys, IDs, etc. Have you tried that? Note getting an int may cause difficulties because the SERIAL is probably an unsigned 64‑bit integer. It will probably behave like
(int)123456789101112L
It probably also implies NOT NULL.


Thanks for the info Campbell.
One reason I stuck with the resulting table the code created is because
it created the ID column with the same properties as three other closely
related table columns: AUTOINCREMENT start 1 increment 1, INTEGER, Is Nullable (NO) etc.
So everything looked good.

Speaking about looking good.....

I just checked a related Table that has a field for the NCF number.
This table is called Tickets and keeps detailed records of every sale.
I was surprised when I saw that the NCF column had <Null> for all test transactions
that I did yesterday. It should have had the same number that was being printed
on the tickets.

Then I looked at the Column_Def for the NCF. It said <null> !

So if you can tell me the correct syntax to Query this table and change it to
AUTOINCREMENT start 1 increment 1, like the other table, that would be great.

Or even better, please tell me the syntax to allow me change it to AUTOINCREMENT
and the start number to whatever I like?

TIA




 
Campbell Ritchie
Sheriff
Posts: 54030
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have forgotten so much SQL, I think I had better duplicate you in the JDBC forum where we usually discuss such things.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I have forgotten so much SQL, I think I had better duplicate you in the JDBC forum where we usually discuss such things.


OK thanks!
 
Dave Tolls
Ranch Hand
Posts: 2554
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick read of that page you linked to earlier and I would say this is something that POS software is supposed to handle?
It doesn't look to me like you are supposed to create an auto increment field of your own.
Of course, that's only based on a quick read.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:A quick read of that page you linked to earlier and I would say this is something that POS software is supposed to handle?
It doesn't look to me like you are supposed to create an auto increment field of your own.
Of course, that's only based on a quick read.


Thanks for helping out Dave.

This POS is open source software and was designed from the start to evolve by users so-inclined
to improve/add to its functions.

The site that was linked to in my post shows code that was written by someone who did just that.
He was interested in adding a second receipt number, for tax purposes.
His country is the Dominican Republic.

I just so happen to have a business in the same country and want to also add a second receipt
number for the same reason.

 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Henstridge wrote:
... So if you can tell me the correct syntax to Query this table and change it to
AUTOINCREMENT start 1 increment 1, like the other table, that would be great.

Or even better, please tell me the syntax to allow me change it to AUTOINCREMENT
and the start number to whatever I like?



The table I am talking about here is called Tickets.
I added a column called NCF but did not make it autoincrement at the time.

The suggested syntax to alter the table to add the column was:

ALTER TABLE `openbravopos`.`TICKETS` ADD `NCF` int(8)

I used a slightly different code but can't remember exactly what I used at the time.
I didn't mention the value because it is set now as 'Null'.



 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I continue to work with these two tables:
TICKETSNUM_NCF and TICKETS

I get more and more confused/frustrated.

The general instructions to modify the existing code was as follows:



Then we edit the "TICKETS" table to add a "NCF" column with integer type to it.



Neither of the above two worked out of the box, they had to be massaged a little,
but I kept the the names 'TICKETSNUM_NCF' (for the table) and
"NCF" for the column in table TICKETS.

Table 'TICKETSNUM_NCF' is working nicely with the code.
For each new sale, the ID column in the table increments by one.

Now here is the part that confuses me.
The TICKETS table had eleven entries in it when I added the new column called
'NCF'.

Default values of 'Null' were entered into the table for 'NCF'.
When I rang up some test sales, the NCF column in TICKETS continued to add 'Null'
values instead of the expected values which were being added to the
'TICKETSNUM_NCF' table ID column.

So one of my confusions is, why did the programmer name the column in TICKETS
NCF?
How is it linked to the only column in 'TICKETSNUM_NCF', column ID?

'TICKETSNUM_NCF' column ID updates correctly with sales but TICKETS
column NCF does not.

I hope someone gets this. 






 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see the code added the following:



but when I look at the table TICKETS I see the following columns:

ID, TICKETTYPE, TICKETID, PERSON, CUSTOMER, STATUS, NCF

so my hunch is that in the ensuing years since the guy wrote the above add-on to the code
another column was added (STATUS).

Could this be the reason that NCF is not being updated?
Maybe the fact that there are now 7 columns instead of the expected 6?

If this is the case, what would I need to do to correct the problem?
 
Knute Snortum
Sheriff
Posts: 3603
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could this be the reason that NCF is not being updated?
Maybe the fact that there are now 7 columns instead of the expected 6? 

No.  That syntax for the INSERT uses the specific columns named to insert, not all of the columns from the table.
 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:
Could this be the reason that NCF is not being updated?
Maybe the fact that there are now 7 columns instead of the expected 6? 

No.  That syntax for the INSERT uses the specific columns named to insert, not all of the columns from the table.




OK.
I am just trying to understand the setInt(6, ......) now.

That does not mean the sixth table value, but rather the sixth inserted value?
And if that is the case, why would the code written just insert six columns and not all seven?
That's another thing I'm confused about.

Or to put it differently,
I know the TICKETS table had more than one column (STATUS) when this
Insert code was written.

It had all of the columns Except the NCF column.
Why re-insert columns it already had?



 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Henstridge wrote:
... Or to put it differently,
I know the TICKETS table had more than one column (STATUS) when this
Insert code was written.

It had all of the columns Except the NCF column.
Why re-insert columns it already had?



I wanted to edit my post but didn't see a way so I have to quote it now.
I now get that the guy is modifying the source code, so this INSERT is part of the actual
source.
But if it is, how can he neglect to add the STATUS column entirely?

 
David Henstridge
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I will be the first to admit I don't know much about Java coding but I am one heck of a persistent SOAB!

I went back into the tables to study them, went back to the customization code and then went back into the program code itself.
I noticed that I had forgotten to add a couple of key parts:



The NCF in the second line and the  setInt(6, ticket.getTicketNCF());   in the fifth to last line.

I was sure this would fix the problem.
I built the project again and then ran it, adding a couple of sales.
Then I went into the Tickets table and sure enough the two new numbers had been added to the table that
held a bunch of <null> values above them.

Yippee!! 


 
Knute Snortum
Sheriff
Posts: 3603
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congratulations on getting things working!

David Henstridge wrote:But if it is, how can he neglect to add the STATUS column entirely? 

I've stopped asking these kind of questions.  Trying to figure out what another programmer's reasoning is will drive you bonkers.

It could be that status is set somewhere else in the program or that null is a valid status, but you would have to dig through the code to be sure.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!