Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7676407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:11:33+00:00 2026-05-31T17:11:33+00:00

I have a JTable called Cart where user can add products before buying them.

  • 0

I have a JTable called “Cart” where user can add products before buying them. The only editable column in that table is the last column called Quantity, which allows users to change the amount of products they wish to buy. By default when adding products this value is one. When I create invoice with these default values, ORDERS DB table is successfully updated. However if I change the amount in quantity cell by typing it, I get an exception I don’t know how to fix. It would appear that integer value I’m trying to get from that column is returned as a String, instead of integer.

Basically I have integer tempStock in which I store quantity of products. I get that value from Model of the table in row “i” and last column “4”.

int tempStock = (int)cartModel.getValueAt(i, 4);

When program adds new row in this table the fourht column is by default 1, and when I call that value, I do get integer. However, if I type in that column some other value, then I no longer get int back, but String.

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

I have found a temporary work around, through checking the type of variable:

/** Check if Quantity field was updated **/
if (cartModel.getValueAt(i, 4).getClass().getName().equals("java.lang.Integer")) {
    tempStock = (int)cartModel.getValueAt(i, 4);
} else {
    tempStock = Integer.parseInt((String)cartModel.getValueAt(i, 4));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:11:34+00:00Added an answer on May 31, 2026 at 5:11 pm
    1. you have to setColumnClass in the TableModel with value Integer for returning int value in the form int tempStock = (int)cartModel.getValueAt(i, 4);

    2. for real sugestions and help you have to edit your question with SSCCE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable where a user can create a custom report. They can
I have a project with a jTable called AchTable , that is like this:
I have a JTable that is using a TableColumnModelListener() to detect when the column
I have a jTable set so that it is read only, and selection is
In a class called HistoryPanel I have a static JTable called resultsTable with a
I have a Jtable on which I called the method table1.setAutoCreateRowSorter(true); . So this
I have a Jtable and intend to add JCheckboxes to it. There is quite
I have a JTable that I want to use to display some data (a
I have a static 2D array called Status.Data[][] and a Column header called Status.Columns[]
I have a JTable that loads data from a database. Because sometimes there's too

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.