row insertion error when adding data to table(DefaultTable) [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
Improve this question
when i add data to the table from textfield i get a replacement error, no new row.
enter image description here
enter image description here
i already tried deleting the table and re-creating it but still the error.How can I solve this?
My code
private void xuLyThemVaoGioHang() throws Exception {
DefaultTableModel dtmGioHang = (DefaultTableModel) tblGioHang.getModel();
dtmGioHang.setRowCount(0);
String ma = txtMaSPBanHang.getText();
String ten = txtTenSPBanHang.getText();
String donGia = txtDonGiaBanHang.getText();
int soLuong = Integer.parseInt(txtSoLuongBanHang.getText());
donGia = donGia.replace(",", "");
int donGiaSP = Integer.parseInt(donGia);
spBUS.docListSanPham();
loadDataTableSanPhamBan();
dtmGioHang.addRow(new Object[]{
ma,ten,soLuong,donGiaSP, dcf.format(soLuong * donGiaSP)
});
new MyDialog("Thêm thành công!!", MyDialog.SUCCESS_DIALOG);
}

Related

Printing a list in Java Servlet using response.getWriter() [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
This post was edited and submitted for review 4 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have an excel file from which I have to find the first few even numbers. I am facing trouble trying to print my list. Here is the snippet of my code :
List<String> contents = UtilFile.readFile(getServletContext(), filename);
List<Integer> copy = new ArrayList<Integer>();
List<Integer> store = new ArrayList<Integer>();
for (String s : contents) {
copy.add(Integer.parseInt(s));
}
Collections.sort(copy);
int i = 0;
for (i = 0; i < copy.size(); i++) {
if (copy.get(i) % 2 == 0) {
store.add(i);
}
}
response.getWriter().print("First 10 unique even numbers are: " + contents.toString());
When I run the code, all I see is an empty list. Here is the output :
First 10 unique even numbers are: []

Unable to print values of an array in Tabular format in Java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Trying to print out values of an arrays in tabular format (in the pic) but it doesn't seem to be working. I know it has something to do with the for loop and but I'm not sure how to code it properly so it shows.
The array is user inputed so it could vary on how many "gifts" there are.
If I forgot to include anything, sorry this is my first post
public static void printGiftsReport(String[] giftArray, double[] priceArray,
String[] whomArray, double overUnderAverage)
{
//
{
System.out.printf("%-15s%10s%15s%15s%25s" ," #.", "For", "Gift",
"Price", "Over/ Under Average\n");
System.out.printf("%-15s%10s%15s%15s%25s", "---", "---", "----",
"-----", "-------------------\n");
for(int i = 0; i > whomArray.length ; i++)
{
if (priceArray[i] > overUnderAverage)
{
System.out.printf("%-10s%10s%25s%10.2f%25s", (i+1),
whomArray[i], giftArray[i], priceArray[i], "over\n");
}
else
{
System.out.printf("%-10s%10s%25s%10.2f%25s", (i+1),
whomArray[i], giftArray[i], priceArray[i], "under\n");
}
you're doing i>whomArray.Length which will never run since i is initialized to 0. what you want instead is i<whomArray.Length.

Telling string to equal an int in android studio [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Basically, I'm creating an app where users choose pass, merit or distinction for 18 different units (school basically). My problem is that I can't figure out how to tell the spinner that if the string in it is "Pass", that string equals the integer 70 (Merit = 80 and distinction = 90). I am using a string array and adapters for the spinners. I am currently trying to do this with an If statement:
if (spinner1.toString().equals("Pass")){}
I just have no idea what I should do to tell the string to equal an int.
To reiterate, I want Pass to = 70, Merit = 80, Distinction = 90.
Any guidance and help on this is much appreciated. :)
hope this helps, it's a little vague...
you mean, you have a few string<->int conversion to do?
public YourConstructor() {
/*Map<String, Integer>*/ theMap = new HashMap<String, Integer>();
theMap.put("Pass", 10);
theMap.put("Merit", 70);
theMap.put("distinction ", 90);
...
}
public int getNumber(String text) {
return theMap.get(text);
// I hope this will be, one day, forgotten. This is BAD.
//for (String s : theMap.keySet())
// if (text.equals(s))
// return theMap.get(s);
// return 0; // default for "item not found", or throw
}
thus final String yourString = ""+getNumber(spinner.getSelectedItem().toString());
Conversion::String to integer is done by:
int integer = Integer.parseInt(text);
integer to String
String theString = ""+integer;
Create a Map like below:
Map<String,int> gradeScoreMap=new HashMap<String,int>();
gradeScoreMap.put("PASS",70);
gradeScoreMap.put("MERIT",70);
gradeScoreMap.put("DISTINCTION",70);
The above map will contains the mapping for your grade with score
create a getter for Map:
public String getgradeScoreMap(String grade) {
return gradeScoreMap.get(grade);
}
the above method will be used to fetch the score based on input grade.
Now use:
int score=-1;
if (spinner1.toString().equals("Pass")){
score =getgradeScoreMap(spinner1.toString());
}
The score will be your equivalent value for "PASS" i.e 70

No error yet no output. Help.(Sudoku solver getter) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to add text fields a01, a02, ... to the array a.
I want to display the value of val so that I would know if the text is being taken from text fields. This code does not show any errors, but, well, it doesn't give me output as well.
int i, j;
JTextField[][] a = new JTextField[9][9];
int[][] val = new int[9][9];
for (i = 0; i < 9; i++)
{
for (j = 0; j < 9; j++)
{
val[i][j] = Integer.parseInt(a[i][j].getText());
System.out.println(val[i][j]);
}
}
It is from my old question here.
You did not give them value
int i,j; // counter
JTextField[][] a = new JTextField[9][9];
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
JTextField tf = new JTextField();
tf.setText("a"+i+j);
a[i][j] = tf;
}
}
In your version the call to a[i][j].getText() should throw a NullPointerException. This should either kill your application, end up on the console or you have somewhere something like
try {
// more code here
} catch (Exception ex){}
which will silently swallow the exception and is veeeeery bad practice.
The code you have shown us does generate an error - it throws a NullPointerException when you try to access the text of the text fields via a[i][j].getText().
You didn't initialize the JTextFields in your array a.
ideone example

Initializing an Big integer array [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My code:
BigInteger R;
int Height;
BigInteger[][] results = new BigInteger[String.valueOf(Height)][R];
Getting an error for this please help me out.
Why are you doing
String.valueOf(Height)
???
Height is an int.
This code works :
BigInteger R = new BigInteger("5");
int Height = 5;
BigInteger[][] results = new BigInteger[Height][R.intValue()];
R is a BigInteger and the [] needs an Integer so we call the inValue method to turn it into an int.
Array sizes in java are ints. So assuming R is initialized:
BigInteger[][] results = new BigInteger[Height][R.intValue()];

Categories