Results 1 to 17 of 17
Thread: I need help with this error
- 10-16-2011, 11:47 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
-
Re: I need help with this error
Your code is missing a period after the array index. i.e., cameras[i].getCameraName(); // note the period to dereference the variable.
The compiler is not very forgiving, and everything has to be just so for it to be happy.
- 10-17-2011, 12:01 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
ok after i put the . in i get 13 errors now
Java Code:C:\Java Test>javac InventoryPart4.java .\Cameras.java:104: error: duplicate class: Supplier class Supplier extends Cameras { ^ .\Cameras.java:56: error: cannot find symbol return CameraName; ^ symbol: variable CameraName location: class Cameras .\Cameras.java:81: error: cannot find symbol this.cameraName = cameraName; ^ symbol: variable cameraName .\Supplier.java:49: error: Illegal static declaration in inner class Supplier.In ventoryPart4 private static DecimalFormat currency = new DecimalFormat("$#,##0.00"); ^ modifier 'static' is only allowed in constant variable declarations .\Supplier.java:70: error: non-static variable this cannot be referenced from a static context new InventoryPart4(); ^ .\Supplier.java:68: error: Illegal static declaration in inner class Supplier.In ventoryPart4 public static void main(String[] args) { ^ modifier 'static' is only allowed in constant variable declarations .\Supplier.java:206: error: array required, but String found String cameras = cameras[i].getCameraName(); ^ .\Supplier.java:207: error: cameras is already defined in sortArray() String cameras = cameras[i + 1].getCameraName(); ^ .\Supplier.java:207: error: array required, but String found String cameras = cameras[i + 1].getCameraName(); ^ .\Supplier.java:210: error: array required, but String found Supplier temp = cameras[i]; ^ .\Supplier.java:211: error: array required, but String found cameras[i] = cameras[i + 1]; ^ .\Supplier.java:211: error: array required, but String found cameras[i] = cameras[i + 1]; ^ .\Supplier.java:212: error: array required, but String found cameras[i + 1] = temp; ^ 13 errors C:\Java Test>
- 10-17-2011, 12:03 AM #4
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
I put in the dot and i get 13 errors now
C:\Java Test>Java Code:ok after i put the . in i get 13 errors now Java Code: C:\Java Test>javac InventoryPart4.java .\Cameras.java:104: error: duplicate class: Supplier class Supplier extends Cameras { ^ .\Cameras.java:56: error: cannot find symbol return CameraName; ^ symbol: variable CameraName location: class Cameras .\Cameras.java:81: error: cannot find symbol this.cameraName = cameraName; ^ symbol: variable cameraName .\Supplier.java:49: error: Illegal static declaration in inner class Supplier.In ventoryPart4 private static DecimalFormat currency = new DecimalFormat("$#,##0.00"); ^ modifier 'static' is only allowed in constant variable declarations .\Supplier.java:70: error: non-static variable this cannot be referenced from a static context new InventoryPart4(); ^ .\Supplier.java:68: error: Illegal static declaration in inner class Supplier.In ventoryPart4 public static void main(String[] args) { ^ modifier 'static' is only allowed in constant variable declarations .\Supplier.java:206: error: array required, but String found String cameras = cameras[i].getCameraName(); ^ .\Supplier.java:207: error: cameras is already defined in sortArray() String cameras = cameras[i + 1].getCameraName(); ^ .\Supplier.java:207: error: array required, but String found String cameras = cameras[i + 1].getCameraName(); ^ .\Supplier.java:210: error: array required, but String found Supplier temp = cameras[i]; ^ .\Supplier.java:211: error: array required, but String found cameras[i] = cameras[i + 1]; ^ .\Supplier.java:211: error: array required, but String found cameras[i] = cameras[i + 1]; ^ .\Supplier.java:212: error: array required, but String found cameras[i + 1] = temp; ^ 13 errors
-
Re: I need help with this error
Best to see your current code, so we can see everything in context.
- 10-17-2011, 12:19 AM #6
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
Java Code:C:\Java Test>javac InventoryPart4.java .\Cameras.java:104: error: duplicate class: Supplier class Supplier extends Cameras { ^ .\Cameras.java:56: error: cannot find symbol return CameraName; ^ symbol: variable CameraName location: class Cameras .\Cameras.java:81: error: cannot find symbol this.cameraName = cameraName; ^ symbol: variable cameraName .\Supplier.java:49: error: Illegal static declaration in inner class Supplier.In ventoryPart4 private static DecimalFormat currency = new DecimalFormat("$#,##0.00"); ^ modifier 'static' is only allowed in constant variable declarations .\Supplier.java:70: error: non-static variable this cannot be referenced from a static context new InventoryPart4(); ^ .\Supplier.java:68: error: Illegal static declaration in inner class Supplier.In ventoryPart4 public static void main(String[] args) { ^ modifier 'static' is only allowed in constant variable declarations .\Supplier.java:206: error: array required, but String found String cameras = cameras[i].getCameraName(); ^ .\Supplier.java:207: error: cameras is already defined in sortArray() String cameras = cameras[i + 1].getCameraName(); ^ .\Supplier.java:207: error: array required, but String found String cameras = cameras[i + 1].getCameraName(); ^ .\Supplier.java:210: error: array required, but String found Supplier temp = cameras[i]; ^ .\Supplier.java:211: error: array required, but String found cameras[i] = cameras[i + 1]; ^ .\Supplier.java:211: error: array required, but String found cameras[i] = cameras[i + 1]; ^ .\Supplier.java:212: error: array required, but String found cameras[i + 1] = temp; ^ 13 errors C:\Java Test>
-
Re: I need help with this error
Again, it would be best if you posted your current code so that we can see what it's doing.
- 10-17-2011, 12:43 AM #8
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
Java Code:import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Supplier extends Cameras { private String supplierName; Supplier(int itemNumber, String productName, int unitsInStock, double price, String supplierName) { super(itemNumber, productName, unitsInStock, price); this.supplierName = supplierName; } public double calculateRestockFee() { return super.calculateInventory() * .05; } public double calculateInventory() { return super.calculateInventory() + calculateRestockFee(); } public String getSupplierName() { return supplierName; } public void setSupplierName(String supplierName) { this.supplierName = supplierName; } @SuppressWarnings("serial") public class InventoryPart4 extends JFrame { private static DecimalFormat currency = new DecimalFormat("$#,##0.00"); private JTextField itemNumberTF; private JTextField cameraNameTF; private JTextField unitsInStockTF; private JTextField priceTF; private JTextField supplierNameTF; private JTextField restockFeeTF; private JTextField valueOfInventoryTF; private JTextField totalValueOfInventoryTF; private JButton priorBT; private JButton nextBT; private Supplier[] cameras; private int current = 0; public static void main(String[] args) { new InventoryPart4(); } public InventoryPart4() { super("Inventory Part 4"); setSize(500, 300); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); cameras = new Supplier[3]; cameras[1] = new Supplier(200, "STYLUS-5010", 20, 650, "Olympus"); cameras[2] = new Supplier(300, "Cyber-Shot", 15, 890, "Sony"); cameras[3] = new Supplier(400, "EASYSHARE SPORT", 80, 1500, "Kodak"); sortArray(); createComponents(); setVisible(true); updateFields(); } private void createComponents() { JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); p.add(createFieldsPanel(), BorderLayout.CENTER); p.add(createButtonsPanel(), BorderLayout.SOUTH); setContentPane(p); } private JPanel createButtonsPanel() { JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.RIGHT)); priorBT = new JButton("Prior"); priorBT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (current > 0) { current--; updateFields(); } } }); p.add(priorBT); nextBT = new JButton("Next"); nextBT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (current < cameras.length - 1) { current++; updateFields(); } } }); p.add(nextBT); return p; } protected void updateFields() { Supplier s = cameras[current]; itemNumberTF.setText(String.valueOf(s.getItemNumber())); cameraNameTF.setText(s.getCameraName()); unitsInStockTF.setText(String.valueOf(s.getUnitsInStock())); priceTF.setText(currency.format(s.getPrice())); supplierNameTF.setText(s.getSupplierName()); restockFeeTF.setText(currency.format(s.calculateRestockFee())); valueOfInventoryTF.setText(currency.format(s.calculateInventory())); totalValueOfInventoryTF.setText(currency.format(calculateInventory())); } private JPanel createFieldsPanel() { JPanel p = new JPanel(); p.setLayout(new GridLayout(0, 2, 5, 5)); p.add(new JLabel("Item Number")); itemNumberTF = new JTextField(); p.add(itemNumberTF); p.add(new JLabel("Cameras Name")); cameraNameTF = new JTextField(); p.add(cameraNameTF); p.add(new JLabel("Units In Stock")); unitsInStockTF = new JTextField(); p.add(unitsInStockTF); p.add(new JLabel("Unit Price")); priceTF = new JTextField(); p.add(priceTF); p.add(new JLabel("Supplier Name")); supplierNameTF = new JTextField(); p.add(supplierNameTF); p.add(new JLabel("Restock Fee")); restockFeeTF = new JTextField(); p.add(restockFeeTF); p.add(new JLabel("Value Of Inventory")); valueOfInventoryTF = new JTextField(); p.add(valueOfInventoryTF); p.add(new JLabel("")); p.add(new JLabel("")); p.add(new JLabel("Value Of The Entire Inventory")); totalValueOfInventoryTF = new JTextField(); p.add(totalValueOfInventoryTF); return p; } public double calculateInventory() { double value = 0; for (int i = 0; i < cameras.length; i++) { value += cameras[i].calculateInventory(); } return value; } public void sortArray() { int n = cameras.length; boolean swapped; do { swapped = false; for (int i = 0; i < n - 1; i++) { String cameras = cameras[i].getCameraName(); String cameras = cameras[i + 1].getCameraName(); if (cameras.compareToIgnoreCase(cameras) > 0) { Supplier temp = cameras[i]; cameras[i] = cameras[i + 1]; cameras[i + 1] = temp; swapped = true; } } n = n - 1; } while (swapped); } } }
-
Re: I need help with this error
Is this code all in one file? If so, what's the name of the file? And, do you have code for the Cameras class?
- 10-17-2011, 01:05 AM #10
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
camera the first class and Supplier is the second class and inventorypart4 is the last one
-
Re: I need help with this error
I'm sorry, maybe my questions above weren't clear. I'm trying to fully understand your error, and for me it will take a little more information, and so I have three questions:
- Is the code that you've posted in post number 8 (labeled #8 in the upper left corner of the post) all in one file, or do you have the two classes in separate java files?
- If they're in the same file, what is the exact name of the file?
- Can you post the code from the Camera or Cameras class as I don't see that this has been done yet (unless I'm missing it)?
If these questions don't make sense, please feel free to ask for clarification.
- 10-17-2011, 01:26 AM #12
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
In Label#8 there is Supplier Class and InventoryPart4 Class and here the Camera Class:
Java Code:class Camera{ public static void main(String[] args){ } private int itemNumber; private String productName; private int unitsInStock; private double price; public Camera() { } public Cameras(int itemNumber, String productName, int unitsInStock, double price) { this.itemNumber = itemNumber; this.productName = productName; this.unitsInStock = unitsInStock; this.price = price; } public double calculateInventory() { return this.unitsInStock * this.price; } public int getItemNumber() { return itemNumber; } public String getCameraName() { return CameraName; } public int getUnitsInStock() { return unitsInStock; } public double getPrice() { return price; } public void setItemNumber(int itemNumber) { this.itemNumber = itemNumber; } public void setName(String cameraName) { this.cameraName = cameraName; } public void setUnitsInStock(int unitsInStock) { this.unitsInStock = unitsInStock; } public void setPrice(double price) { this.price = price; } }
-
Re: I need help with this error
What about my questions #1 and #2 above?
- 10-17-2011, 01:36 AM #14
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
ok yes there is 2 files there and i need to link them to just one so i can get the InventoryPart4 to work i hope that anwsers your question
-
Re: I need help with this error
There should be at least 3 files here, one for each Java class: Supplier.java, InventoryPart4.java and Camera.java (or Cameras.java -- it's not clear).
Then you need to try to just compile the most base class present, which I guess is Camera and show us just the errors from this class. Already I see some contradiction as the class name appears to be Camera but your constructor is Cameras, and these two names must match exactly. Again, the compiler is very strict, and so we must be just as strict about our code if has any hope of succeeding. Only after you have the Camera class compiling correctly can you begin to consider working on the next class, Supplier, and the same for InventoryPart4.
- 10-17-2011, 02:24 AM #16
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help with this error
its Cameras.java
-
Re: I need help with this error
OK, but the code you posted has this:
So the class name and one constructor name is Camera and this will cause errors as the file name, class name, and constructor names must all agree exactly. You will want to change them to Cameras, then recompile your code, look for any errors that come from the Cameras class and try to fix them. If you still get stuck, then post the Cameras class again and the latest error messages.Java Code:class Camera{ public static void main(String[] args){ } private int itemNumber; private String productName; private int unitsInStock; private double price; public Camera() { } //....
Similar Threads
-
java out of memory error-heap space error
By elsanthosh in forum NetBeansReplies: 4Last Post: 06-15-2010, 09:31 AM -
> Operator cannot be applied error and return incompatible types error
By corney_16 in forum New To JavaReplies: 1Last Post: 03-10-2010, 01:53 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks