Results 1 to 6 of 6
-
Keep running into NullPointers :/ help..
Okay, I've revised my question. Please help if you can.
This is the code:
Java Code:public void openItemAddOnsEditor(int selectedTLindex, Products.Product.ProductModifiers pm) { [COLOR="red"][B]lastModGroup[/B][/COLOR] = pm.returnProduct().getModifiers().indexOf(pm); System.out.println("Last mod group: " + lastModGroup); askItemAddOnsModifierItems.removeAll(); for (int i=0; i<pm.getSetMembers().size(); i++) { final Products.Product.ProductModifiers.ProductModifier mod = pm.getSetMembers().get(i); javax.swing.JToggleButton jt = new javax.swing.JToggleButton(mod.getDescription()); askItemAddOnsModifierItems.add(jt); jt.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { javax.swing.AbstractButton ab = (javax.swing.AbstractButton) evt.getSource(); boolean buttonState = ab.isSelected(); openItemAddOnsMemberEditorAction(mod, buttonState, evt); } }); } askItemAddOnsCardsLayout.show(askItemAddOnsCards, "itemAddOnsCard2"); } public void openItemAddOnsMemberEditorAction( Products.Product.ProductModifiers.ProductModifier mod, boolean buttonState, java.awt.event.ActionEvent evt) { openItemAddOnsMemberEditor(mod, buttonState); } public void openItemAddOnsMemberEditor(Products.Product.ProductModifiers.ProductModifier mod, boolean buttonSelected) { [B][U][COLOR="Red"]lastModItem[/COLOR][/U][/B] = mod.returnGroup().getSetMembers().indexOf(mod); System.out.println("Group: " + [COLOR="red"]mod.returnGroup().getSetDescription()[/COLOR] + "; Last mod item: " + lastModItem); Products.Product p = mod.returnGroup().returnProduct(); System.out.println(p.getDescription()); if (buttonSelected) { if (mod.getPrices().size() > 1) { setAskModUpgradeBox(mod); askModUpgrade.setVisible(true); } boolean priceByWeight = mod.getPrices().get(askModUpgradeRequest).isPricePerKg(); if (priceByWeight) { double itemWeight = 0; setAskItemWeightBox(mod); askItemWeight.setVisible(true); itemWeight = askItemWeightRequest; TransactionLineModifier tempTLM = new TransactionLineModifier(p,lastModGroup,lastModItem,askModUpgradeRequest,itemWeight); askNewOrder.get(currentOrder).addTransactionLine(tempTLM); } else { TransactionLineModifier tempTLM = new TransactionLineModifier(p,lastModGroup,lastModItem,askModUpgradeRequest); askNewOrder.get(currentOrder).addTransactionLine(tempTLM); } } }
This code gives me a null pointer exception in TransactionLineModifier.java because the variable lastModItem is -1.
It is -1, I understand, because the .indexOf method didn't find anything. This is strange to me because lastModGroup is written in a similar way, however it Does find the correct object and return its (int) index.
The other thing is that, mod.returnGroup().getSetDescription() doesn't return the correct description name... Why is that?
When the JButtons and JToggleButtons are created and display, they display the correct Descriptions, but the problem is the Actions attached to them maybe passing the wrong objects.
Once again, any help would be greatly appreciated.
thanks again.Last edited by ozzyman; 04-22-2011 at 12:18 PM.
-
Updated the question/info
-
I can't speak for others, but I have a hard time figuring out your problem without being able to compile/test/run/alter your code. As I've said probably too many times, an SSCCE would be best if you could create one, if not, then still the smallest possible compilable/runnable unit would be helpful.
Much luck!
-
Thanks Fu, I was too afraid to post the whole code because its really, really long; that and I thought maybe there was a conceptual problem that someone would identify.
This is a simplified Products.java file:
Java Code:// code removed
Last edited by ozzyman; 04-22-2011 at 04:00 PM.
- 04-22-2011, 03:09 PM #5
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
Which is the point of an SSCCE, it lets you break the problem down only the necessary components (often times this is enough to discover the problem yourself) and allows one to boil a problem down to just that - it is in my opinion an essential skill in debugging (and the above is not an SSCCE).I was too afraid to post the whole code because its really, really long
That being said, read the API for List, it returns -1 if an Object passed to indexOf is not found in the List. This is what I presume to be the problem, but its difficult to say give the length of code (as well as the excessive use of nested inner classes - making it hard to quickly follow)
-
thanks doWhile, and you're spot on - I discovered the reason why this is happening while I was making the SSCCE;
Java Code:/** Escape modifier */ public ProductModifiers returnGroup() { return productModifiers.get(productModifiers.size()-1); }
This worked for me before (because when the modifiers are created, they are created in a sequence), but now it doesn't work because I need to add product modifiers to products from the GUI.
How can I get the (ProductModifiers group object in the Product.productModifiers List) from the ProductModifier item object?
I've done it for the ProductModifiers group like this: returning the Product its from:
Java Code:/** Escape Modifiers */ public Product returnProduct() { return getProduct(productID); }
EDIT:
this is what I have:
(isn't correct)Java Code:return getProduct(productID).getModifiers().get(productModifiers.indexOf(modifierList.indexOf(this)));
EDIT again:
kay, i finally got around this by adding modifier IDs and a search method.Last edited by ozzyman; 04-22-2011 at 03:59 PM.
Similar Threads
-
running
By aizen92 in forum New To JavaReplies: 3Last Post: 02-11-2011, 07:50 PM -
Running on a Server
By providence in forum New To JavaReplies: 4Last Post: 01-31-2011, 11:11 PM -
Process running or not
By smartsubroto in forum New To JavaReplies: 4Last Post: 11-16-2009, 03:09 AM -
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08-26-2009, 01:03 PM -
Running
By AWPtic in forum EclipseReplies: 1Last Post: 03-24-2009, 06:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks