Help with HashMap!!!

Hi all,
My program reads the data from the external file called: "long.txt" which consists of a million records...
The file is loaded into a list called: "HashMap list" and also store the keys into a separate array. Search is done in HashMap for all the key in the array or also known as an exhaustive search.
I have the files: "long.txt", "HashMapTestnew.java" and "MyData.java" in the same directory called: "tmp"...
Everything looks okay but when I try to compile this, I get the following error...
HashMapTestnew.java:38: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTestnew
MyData md = new MyData( sKey, Integer.parseInt(sVal) );
^
HashMapTestnew.java:38: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTestnew
MyData md = new MyData( sKey, Integer.parseInt(sVal) );
^
HashMapTestnew.java:55: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTestnew
MyData md;
^
HashMapTestnew.java:66: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTestnew
md = (MyData) me.getValue();
^
4 errors
Tool completed with exit code 1
import java.util.*;
import java.io.*;
public class HashMapTestnew
public static HashMap getMapList()
     String MyData;
     Int sKey;
String strLine;
HashMap hm = new HashMap();
try
BufferedReader fBR = new BufferedReader( new FileReader("long.txt") );
while ( fBR.ready() )
strLine = fBR.readLine();
if (strLine != null)
StringTokenizer st = new StringTokenizer(strLine, "\t");
String sKey = st.nextToken();
String sVal = st.nextToken();
MyData md = new MyData( sKey, Integer.parseInt(sVal) );
hm.put(sKey, md);
fBR.close();
catch (IOException ioe)
System.out.println("I/O Trouble ...");
return hm;
public static void showMapList(HashMap hashMap, int n)
String strVal;
String strNdx;
MyData md;
System.out.println("\nHashMap List (first 10 records):");
Map.Entry me;
Set shm = hashMap.entrySet();
Iterator j = shm.iterator();
int i = 0;
while (j.hasNext() && (i++)< n)
me = (Map.Entry) j.next();
strVal = (String) me.getKey();
md = (MyData) me.getValue();
System.out.println(i + ": " + md.getVal() + "\t" + md.getNdx() );
public static String[] getKeys(HashMap hashMap)
String[] key = new String[hashMap.size()];
Map.Entry me;
Set shm = hashMap.entrySet();
Iterator j = shm.iterator();
int i = 0;
while (j.hasNext())
me = (Map.Entry) j.next();
key[i] = (String) me.getKey();
i++;
return key;
public static void searchMapList(HashMap hashMap, String[] key)
int i,n=0;
System.out.println("Search Started:");
long tim1 = System.currentTimeMillis();
for (i=0; i<key.length; i++)
if (hashMap.containsKey(key))
n++;
long tim2 = System.currentTimeMillis();
System.out.println("Search Ended After " + (tim2-tim1) + " miliseconds.");
System.out.println("Searched for " + key.length + " keys.");
System.out.println("Found " + n + " keys.");
public static void main(String[] arg)
HashMap hashMap = getMapList(); // Create the hash map list
showMapList(hashMap, 10); // Display part of the hash map list
String[] searchKey = getKeys(hashMap); // an array of all search keys
searchMapList(hashMap, searchKey); // Search for all existing keys in the list
Can anybody help me with this?
I'm new to Java... What does the error message: "cannot resolve symbol
symbol : class MyData" mean???
P.S. When I compiled the file "MyData.java", it compiles without any error...
Thanks,
Lilian

I moved the 3 files ("MyData.java", "long txt" and "HashMapTest.java") to a directory called "MyData" as well as added the code: "package MyData;"
before the codes:
import java.util.*;
import java.io.*;
just to see if it would make any difference but I still got the following error messages:
C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:38: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTest
MyData md = new MyData( sKey, Integer.parseInt(sVal) );
^
C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:38: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTest
MyData md = new MyData( sKey, Integer.parseInt(sVal) );
^
C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:55: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTest
MyData md;
^
C:\WINDOWS\DESKTOP\MyData\HashMapTest.java:66: cannot resolve symbol
symbol : class MyData
location: class MyData.HashMapTest
md = (MyData) me.getValue();
^
4 errors
Tool completed with exit code 1
By the way, I'm compiling the java program using a Textpad editor and selecting Tools -->> Compile Java...
Let me know if you have any questions...
Thanks,
Lilian
location: class MyData.HashMapTestnewThis says that you have declared your HashMapTestnew
class to be in package MyData.
I have the files: "long.txt", "HashMapTestnew.java"and "MyData.java" in the same directory called:
"tmp"...
If you want HashMapTestnew to be in package MyData,
then it should have been in a directory called MyData.
But having a class with the same name as a package is
very confusing, so I don't think you should do that.
In fact, since you are new to Java I don't think you
u should use packages at all until you can compile
non-packaged classes correctly.
I'm surprised I don't see the line "package MyData" at
the top of the code you posted. But then I'm not
surprised, because since your class isn't in the right
directory for that package, you should have got
different error messages. What exactly did you type
at the command line to compile the class?

Similar Messages

  • Help with HashMap and Collections

    Hey everyone,
    I am currently writing a program that makes use of HashMap, which I am not at all familiar with. I looked it up in some books and some websites, but it seems everyone does something different every time so I need some guidance. My program is to take Inventory Item objects that have an name and an inventory number and store them in a HashMap. Originally I had them stored in an Array but now it's gonna be in a HashMap. This also uses some Java GUI elements so bear with me.
    Ok, first here is my code for my Item object:
    public class Item{
        private String number;
        private String name;
        public Item(String number, String name) {
              this.number = number;
              this.name = name;
          @Override
          public String toString() {
              return "#"+number+"  N:"+name;
    }And this is what I got so far for my Inventory GUI:
    import java.util.HashMap;
    import java.util.Iterator;
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.Label;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JScrollPane;
    public class InventoryGUI {
         //private static Item[] item = new Item[10];
         HashMap hash = new HashMap();
         private static int count = 0;
         public static void main(String[] args) {
              JFrame gui = new JFrame("Project 2 GUI");
              gui.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JPanel inputPanel = new JPanel();
              inputPanel.setLayout(new GridLayout(5,2));
              inputPanel.add(new Label("Inventory Number"));
              final JTextField numberField = new JTextField(15);
              inputPanel.add(numberField);
              inputPanel.add(new Label("Name"));
              final JTextField nameField = new JTextField(15);
              inputPanel.add(nameField);
              gui.add(inputPanel, BorderLayout.NORTH);
              final DefaultListModel dfl = new DefaultListModel();
              JList jl = new JList(dfl);
              JScrollPane jsp = new JScrollPane(jl);
              gui.add(jsp);
              JPanel southPanel = new JPanel();
              southPanel.setLayout(new GridLayout(2,1));
              final JTextField errorMsg = new JTextField();
              errorMsg.setEditable(false);
              southPanel.add(errorMsg);
              JPanel buttonPanel = new JPanel();
              southPanel.add(buttonPanel);
              JButton addButton = new JButton("Add");
              addButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        String number = numberField.getText();
                          numberField.setText("");
                         String name = nameField.getText();
                          nameField.setText("");
                               hash.put(number, name);
                               count++;
              buttonPanel.add(addButton);
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(deleteButton);
              JButton findButton = new JButton("Find");
              findButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                        String temp = hashMap.get(number);
                              dfl.addElement(temp);
              buttonPanel.add(findButton);
              JButton showButton = new JButton("Show");
              showButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                          for (Item p : item) {
                              dfl.addElement(p);
              buttonPanel.add(showButton);
              JButton saveButton = new JButton("Save");
              saveButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(saveButton);
              JButton restoreButton = new JButton("Restore");
              restoreButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(restoreButton);
              JButton exitButton = new JButton("Exit");
              exitButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        System.exit(1);
              buttonPanel.add(exitButton);
              gui.add(southPanel, BorderLayout.SOUTH);
              gui.pack();
              gui.setVisible(true);
    }I know a lot of those buttons are missing functions, but I want to get clear on how to implement a HashMap here. Any help or insight will be greatly appreciated.

    Hey thanks for that, it was some nice insight. However I'm still stumped on how HashMap needs to work in this situation. It worked fine with an object array, but this is stumping me good. To be a little more specific, I need several functions to happen with this HashMap, each correlating with a button for the GUI.
    It needs to be able to add Item objects to the HashMap (the key is the inventory number, and the value is the Item object), it needs to be able to delete an Item object (by using the inventory number), it needs to be able to find Items by inventory number, show all Items currently in the HashMap, save the info in the HashMap to a file on disk by using ObjectStreams, and a restore button just loads the data from that file to the HashMap.
    It's a lot right? :D
    I'm struggling to get anything to work with a HashMap however. If I could get some assistance with any of these functions, I would greatly appreciate it. Here's my updated code:
    import java.util.HashMap;
    import java.util.Iterator;
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.Label;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JScrollPane;
    public class InventoryGUI {
         //private static Item[] item = new Item[10];
         HashMap hash = new HashMap();
         private static int count = 0;
         public static void main(String[] args) {
              JFrame gui = new JFrame("Project 2 GUI");
              gui.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JPanel inputPanel = new JPanel();
              inputPanel.setLayout(new GridLayout(5,2));
              inputPanel.add(new Label("Inventory Number"));
              final JTextField numberField = new JTextField(15);
              inputPanel.add(numberField);
              inputPanel.add(new Label("Name"));
              final JTextField nameField = new JTextField(15);
              inputPanel.add(nameField);
              inputPanel.add(new Label("Manufacturer"));
              final JTextField manField = new JTextField(15);
              inputPanel.add(manField);
              inputPanel.add(new Label("Description"));
              final JTextField descField = new JTextField(15);
              inputPanel.add(descField);
              inputPanel.add(new Label("Price"));
              final JTextField priceField = new JTextField(15);
              inputPanel.add(priceField);
              gui.add(inputPanel, BorderLayout.NORTH);
              final DefaultListModel dfl = new DefaultListModel();
              JList jl = new JList(dfl);
              JScrollPane jsp = new JScrollPane(jl);
              gui.add(jsp);
              JPanel southPanel = new JPanel();
              southPanel.setLayout(new GridLayout(2,1));
              final JTextField errorMsg = new JTextField();
              errorMsg.setEditable(false);
              southPanel.add(errorMsg);
              JPanel buttonPanel = new JPanel();
              southPanel.add(buttonPanel);
              JButton addButton = new JButton("Add");
              addButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        String number = numberField.getText();
                          numberField.setText("");
                         String name = nameField.getText();
                          nameField.setText("");
                         String manufacturer = manField.getText();
                          manField.setText("");
                         String description = descField.getText();
                          descField.setText("");
                         float price = Integer.parseInt(priceField.getText());
                          priceField.setText("");
                             Item myItem=new Item(number, name, manufacturer, description, price);
                               hash.put(number, myItem);
                               count++;
              buttonPanel.add(addButton);
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                   dfl.clear();
                   String number = numberField.getText();
                    numberField.setText("");
                   hashMap.remove(number);
              buttonPanel.add(deleteButton);
              JButton findButton = new JButton("Find");
              findButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                        String number = numberField.getText();
                           numberField.setText("");
                        Item temp = new Item(hashMap.get(number));
                              dfl.addElement(temp);
              buttonPanel.add(findButton);
              JButton showButton = new JButton("Show");
              showButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
                        dfl.clear();
                          for (Item p : item) {
                              dfl.addElement(p);
              buttonPanel.add(showButton);
              JButton saveButton = new JButton("Save");
              saveButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(saveButton);
              JButton restoreButton = new JButton("Restore");
              restoreButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent ae) {
              buttonPanel.add(restoreButton);
              JButton exitButton = new JButton("Exit");
              exitButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
                        System.exit(1);
              buttonPanel.add(exitButton);
              gui.add(southPanel, BorderLayout.SOUTH);
              gui.pack();
              gui.setVisible(true);
    }Thanks for any help you can give me!

  • Would like some help with hashmaps please :)

    Map<Integer, Double> probabilities = new HashMap<Integer, Double>();When i try to use the above code in a foreach loop
    for (Map.Entry<Integer, Double> entry : probabilities)i get this error
    Foreach not applicable to expressionCould anyone please enlighten me on what is wrong with that and maybe suggest another way of running through the HashMap.
    THANKS!

    for (Map.Entry<Integer, Double> entry : probabilities.entrySet())

  • Help with HashMap - what am I doing wrong?!?!

    I'm hoping to create multiple instances of an object and identify each one differently. On an earlier thread, someone recommended I use a hashmap to do this. I'm trying but failing. The following code is intended to allow me to ask for 1 and get apple and ask for 2 and get banana. Instead, when I ask for either I get banana, which is making me think that I'm just rewriting over my object and putting two of the same instances in the hashmap.
    Thanks in advance!
    import java.util.HashMap;
    import java.util.Map;
    public class HashMapTest {
         private static Map <Integer, Bids> map;
         public static void main (String[] args) {
              Map map = new HashMap<Integer, Bids>();
              Bids myBids = new Bids("apple", 1.5, 1);
              map.put(1, myBids);
              myBids = new Bids("banana", 2.0, 2);
              map.put(2, myBids);
              Bids aBids = (Bids) map.get(1);
              String cat = aBids.getProductCategory();
              System.out.println(cat);
    Bids code:
    public class Bids {
         static String productCategory;
         private static Double price;
         private static int id;
         public Bids(String myProductCategory, Double myPrice, int myId) {
              productCategory = myProductCategory;
              price = myPrice;
              id = myId;
         public String getProductCategory(){
              return productCategory;
         public Double getPrice(){
              return price;
         public int getId(){
              return id;
    }

    jverd wrote:
    You have to override equals() and hashCode() in your Bids class.I'm not questioning the desirability of that, but is it mandatory? This works fine, without overriding either.import java.util.HashMap;
    import java.util.Map;
    public class HashMapTest {
      public static void main(String[] args) {
        Map<Integer, Bids> map = new HashMap<Integer, Bids>();
        Bids myBids = new Bids("apple", 1.5, 1);
        map.put(1, myBids);
        myBids = new Bids("banana", 2.0, 2);
        map.put(2, myBids);
        Bids aBids = map.get(1);
        System.out.println("1: " + aBids.getProductCategory());
        aBids = map.get(2);
        System.out.println("2: " + aBids.getProductCategory());
    class Bids {
      private String productCategory;
      public Bids(String myProductCategory, Double myPrice, int myId) {
        productCategory = myProductCategory;
        price = myPrice;
        id = myId;
      public String getProductCategory() {
        return productCategory;
    }db
    Edited by: DarrylBurke - I hate a laptop keyboard!

  • Need help with locating a key using a value in a HashMap.

    I am quite new to Java and programming, and am just learning this in High School (enjoying it thoroughly). Sorry if I don't respect the etiquette or formatting of this board (it's unintentional).
    I am using the book, Objects First Wth Java A Practical Introduction Using Blue J and am working on extensively improving the "World of Zuul" project. Which is a text-based adventure game.
    Here is a code sample;
    public String getNameFromList(String name)
      boolean found = false;
      Set pairSet = xItemList.entrySet();
      for(Iterator iter = pairSet.iterator(); (found == false && iter.hasNext());){
      Item currentItem = (Item) iter.next().getValue();
      String currentKey = currentItem.getName();
      if(name.equals(currentKey)){
        String changedName = iter.next().getKey();
        return changedName;
    error; cannot resolve symbol:
    method: getValue()xItemList is a HashMap with String keys, and Item values.
    The relevant field of Item is name, which is a string.
    The currentKey local variable is a little misleading, it is the current name, but acts as the 'key' when looking for the actual key.
    changedName (if the parameter name is found from the item.getNames()), is what the method returns, the key associated with a object (by looking at the object's field).
    My objective for this method is for it to have a name as a parameter, which it searches for in the HashMap (by Iteration over the entrySet - or I suppose iteration over Set values(), but this loses which object value is tied to which key, doesn't it?), and returns the respective key.
    Any help would be very much appreciated (even if it is telling me that this can't be done with HashMaps!).

    It's not clear to me what your question is, or if indeed you even have a question.
    You seem to be having a problem with types. Iterators return Objects.
    So in this line:
      Item currentItem = (Item) iter.next().getValue();The iterator's next() method is returning an Object, and you're trying to call getValue() on that Object. But Object doesn't have a getValue() method. That would explain your error message. Map.Entry does; you apparently meant to call Map.Entry's getValue() method. You would cast the result of iter.next() to Map.Entry before you call getValue().
    Also you're calling next() on your iterator twice in the body of the loop, which means you're getting two different values... this is probably not what you intend.
    But you're making this more complicated than it needs to be anyway.
    Why are you iterating through the set of entries in the HashMap?
    The whole point of a Map is that you get an item using an object as the key. Just do xItemList.get(name). Right?

  • Urgent help with simple BPEL process for reading data from database

    Hello there,
    I need help with BPEL project.
    i have created a table Employee in Database.
    I did create application, BPEL project and connection to the database properly using Database Adapter.
    I need to read the records from the database and convert into xml fomat and it should to go approval for BPM worklist.
    Can someone please describe me step by step what i need to do.
    Thx,
    Dps

    I have created a table in Database with data like Empno,name,salary,comments.
    I created Database Connection in jsp page and connecting to BPEL process.
    It initiates the process and it goes automatically for approval.
    Please refer the code once which i created.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@page import="java.util.Map" %>
    <%@page import="com.oracle.bpel.client.Locator" %>
    <%@page import="com.oracle.bpel.client.NormalizedMessage" %>
    <%@page import="com.oracle.bpel.client.delivery.IDeliveryService" %>
    <%@page import="javax.naming.Context" %>
    <%@page import="java.util.Hashtable" %>
    <%@page import="java.util.HashMap" %>
    <%@ page import="java.sql.*"%>
    <%@ page import= "jspprj.DBCon"%>
    <html>
    <head>
    <title>Invoke CreditRatingService</title>
    </head>
    <body>
    <%
    DBCon dbcon=new DBCon();
    Connection conn=dbcon.createConnection();
    Statement st=null;
    PreparedStatement pstmt=null;
    Hashtable env= new Hashtable();
    ResultSet rs = null;
    Map payload =null;
    try
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.PROVIDER_URL, "opmn:ormi://localhost:port:home/orabpel");//bpel server
    env.put("java.naming.security.principal", "username");
    env.put("java.naming.security.credentials", "password");//bpel console
    Locator locator = new Locator("default","password",env);
    IDeliveryService deliveryService =
    (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME );
    // construct the normalized message and send to Oracle BPEL Process Manager
    NormalizedMessage nm = new NormalizedMessage();
    java.util.HashMap map = new HashMap();
    st=conn.createStatement();
    out.println("connected");
    String query1="Select * from EMPLOYEE";
    rs=st.executeQuery(query1);
    /*reading Data From Database and converting into XML format
    so that no need of going to BPEL console and entering the details.
    while (rs.next()){
    String xml1 = "<AsynchBPELProcess1ProcessRequest xmlns='http://xmlns.oracle.com/AsynchBPELProcess1'>"+
    "<Empno>"+rs.getString(1)+"</Empno>"+
    "<EmpName>"+rs.getString(2)+"</EmpName>"+
    "<Salary>"+rs.getString(3)+"</Salary>"+
    "<Comments>"+rs.getString(4)+"</Comments>"+
    "</AsynchBPELProcess1ProcessRequest>";
    out.println(xml1);
    nm.addPart("payload", xml1 );
    // EmployeeApprovalProcess is the BPEL process in which human task is implemented
    deliveryService.post("EmployeeApprovalProcess", "initiate", nm);
    // payload = res.getPayload();
    out.println( "BPELProcess CreditRatingService executed!<br>" );
    // out.println( "Credit Rating is " + payload.get("payload") );
    //Incase there is an exception while invoking the first server invoke the second server i.e lsgpas13.
    catch(Exception ee) {
    //("BPEL Server lsgpas14 invoking error.\n"+ee.toString());
    %>
    </body>
    </html>
    Its working fine.And i want it for Bulk approvals.please help me step by step procedure if any other way to implement this.

  • Need help with ending a game

    i'm making a game at the moment.......
    i need help with a way to check all the hashmaps of enimies in a class called room......i need to check if they all == 0...when they all equal zero the game ends......
    i know i can check the size of a hash map with size().....but i want to check if all the hashmaps within all the rooms == 0.

    First of all stop cross posting. These values in the HashMap, they are a "Collection" of values, so what is wrong with reply two and putting all these collections of values into a super collection? A collection of collections? You can have a HashMap of HashMaps. One HashMap that holds all your maps and then you can use a for loop to check if they are empty. A map is probably a bad choice for this operation as you don't need a key and an array will be much faster.
    HashMap [] allMaps = {new HashMap(),new HashMap()};

  • Help with Switch statements using Enums?

    Hello, i need help with writing switch statements involving enums. Researched a lot but still cant find desired answer so going to ask here. Ok i'll cut story short.
    Im writing a calculator program. The main problem is writing code for controlling the engine of calculator which sequences of sum actions.
    I have enum class on itself. Atm i think thats ok. I have another class - the engine which does the work.
    I planned to have a switch statement which takes in parameter of a string n. This string n is received from the user interface when users press a button say; "1 + 2 = " which each time n should be "1", "+", "2" and "=" respectively.
    My algorithm would be as follows checking if its a operator(+) a case carry out adding etc.. each case producing its own task. ( I know i can do it with many simple if..else but that is bad programming technique hence im not going down that route) So here the problem arises - i cant get the switch to successfully complete its task... How about look at my code to understand it better.
    I have posted below all the relevant code i got so far, not including the swing codes because they are not needed here...
    ValidOperators v;
    public Calculator_Engine(ValidOperators v){
              stack = new Stack(20);
              //The creation of the stack...
              this.v = v;          
    public void main_Engine(String n){
           ValidOperators v = ValidOperators.numbers;
                    *vo = vo.valueOf(n);*
         switch(v){
         case Add: add();  break;
         case Sub: sub(); break;
         case Mul: Mul(); break;
         case Div: Div(); break;
         case Eq:sum = stack.sPop(); System.out.println("Sum= " + sum);
         default: double number = Integer.parseInt(n);
                       numberPressed(number);
                       break;
                      //default meaning its number so pass it to a method to do a job
    public enum ValidOperators {
         Add("+"), Sub("-"), Mul("X"), Div("/"),
         Eq("="), Numbers("?"); }
         Notes*
    It gives out error: "No enum const class ValidOperators.+" when i press button +.
    It has nothing to do with listeners as it highlighted the error is coming from the line:switch(v){
    I think i know where the problem is.. the line "vo = vo.valueOf(n);"
    This line gets the string and store the enum as that value instead of Add, Sub etc... So how would i solve the problem?
    But.. I dont know how to fix it. ANy help would be good
    Need more info please ask!
    Thanks in advance.

    demo:
    import java.util.*;
    public class EnumExample {
        enum E {
            STAR("*"), HASH("#");
            private String symbol;
            private static Map<String, E> map = new HashMap<String, E>();
            static {
                put(STAR);
                put(HASH);
            public String getSymbol() {
                return symbol;
            private E(String symbol) {
                this.symbol = symbol;
            private static void put(E e) {
                map.put(e.getSymbol(), e);
            public static E parse(String symbol) {
                return map.get(symbol);
        public static void main(String[] args) {
            System.out.println(E.valueOf("STAR")); //succeeds
            System.out.println(E.parse("*")); //succeeds
            System.out.println(E.parse("STAR")); //fails: null
            System.out.println(E.valueOf("*")); //fails: IllegalArgumentException
    }

  • Help with Resizing of column widths in a pivot

    HI all,
    I m working on resizing the pivot coulmn width in a dashboard. Could anyone please help with resizing the pivot width. Autosize() works but user doesnt want that.
    Whats the code to do that?

    I read what was written but still am confused. I am completely lost at this pointWhat is confusing you? A TreeMap is just a HashMap where the key is stored is sorted order.
    Read the Collections tutorial found [url http://java.sun.com/docs/books/tutorial/]here.

  • Help with exam question

    Please can someone help with this exam question I have. I have no idea about it I have been looking through loads of website and class documentation but I still have no answer.
    Please can someone explain this to me thanks
    Consider the following code:
    Import java.util.hashmap;
    Import java.util.map;
    Public myClass {
         Private Map <Integer, Object> myMap = New HashMap <Integer, Object> ();
         Public void addStuff(int id, Object Stuff) {
                   myMap.add(new Integer(id), stuff);
         Public Map getMyMap() {
                   Return myMap;
    Why is myMap declared as a Map and not a HashMap?

    It's called programming against the interface.
    The code using myMap doesn't need to know that it's a HashMap, but only needs to know that it's a Map (Map is an interface that HashMap implements, so every HashMap is-a Map).
    Since that knowledge is not required it's better not to give it away.
    If at some point we decide that HashMap is not the best choice here we can easily change it to any other Map implementation (such as TreeMap for example) and only need to change that one line.

  • Please help with BufferedImage

    hi,
    I'm making a space invaders game and need some help with image buffering. I so far have classes for:
    ImageHandler - which should handle the loading of images
    GameEntities - which contains methods for the ship movements etc
    AlienEntitiy - which will draw an alien and have methods for its movement, shooting etc.
    SpaceInvaders - which extends Canvas and handles the main game
    The problem is that when I create a new alien which has a call to the setImageName(String name) method, which should call the getImage(String imageName) method in ImageHandler, a null pointer exception is thrown.
    I have searched my code and can't trace the error (by the way, this is the first ime I've used buffered image). Can someone PLEASE help.
    Here's my code:
    package InvadersGame;
    import java.awt.image.BufferedImage;
    import java.io.PrintStream;
    import java.util.HashMap;
    import javax.imageio.ImageIO;
    public class ImageHandler
        private HashMap images;
        public ImageHandler()
            images = new HashMap();
        public BufferedImage loadImage(String name)
            try
                java.net.URL url = null;
                url = getClass().getResource(name);
                return ImageIO.read(url);
            catch(Exception e)
                System.exit(0);
                System.out.println("image not found");
                return null;
        public BufferedImage getImage(String name)
            BufferedImage image = (BufferedImage)images.get(name);
            return image;
        public HashMap getImages()
            return images;
        public void setImages(HashMap val)
            images = val;
    }and
    package InvadersGame;
    import java.awt.Graphics;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.awt.Graphics2D;
    public class GameEntities {
        private double x, y;
        private int width, height;
        private String imageName;
        private boolean deletionMark = false;
        private SpaceInvaders invaders;
        private ImageHandler imageHandler;
        public GameEntities(SpaceInvaders invaders)
            this.invaders = invaders;
            imageHandler = invaders.getImageHandler();
        public double getX()
            return x;
        public double getY()
            return y;
        public int getWidth()
            return width;
        public int getHeight()
            return height;
        public Rectangle getBounds()
            return new Rectangle((int)x, (int)y, width, height);
        public void setX(int x)
            this.x = x;
        public void setY(int y)
            this.y = y;
        public void setWidth(int width)
            this.width = width;
        public void setHeight(int height)
            this.height = height;
        public boolean deletionMarked()
            return deletionMark;
        public void setDeletionMarkedTrue(boolean value)
            deletionMark = value;
       public String getImageName()
            return imageName;
        public void setImageName(String name)
            imageName = name;
            BufferedImage image = imageHandler.getImage(imageName);
            height = image.getHeight();
            width = image.getWidth();
        public boolean collidesWith(GameEntities other)
            Rectangle thisEntity = new Rectangle();
            Rectangle otherEntity = new Rectangle();       
            thisEntity.setBounds((int)this.getX(), (int)this.getY(), this.getWidth(), this.getHeight());
            otherEntity.setBounds((int)other.getX(),(int)other.getY(), other.getWidth(), other.getHeight());
            return thisEntity.intersects(otherEntity);
        public void move(){}
        public void paint(Graphics2D g)
             g.drawImage(imageHandler.getImage(imageName), (int)x, (int)y, invaders);
    }and
    package InvadersGame;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import java.awt.Graphics2D;
    import java.lang.Math;
    import java.util.Random;
    public class AlienEntity extends GameEntities {
        double x, y;
        int alienType;
        int speedx = 2;
        int speedy = 2;
        public AlienEntity(SpaceInvaders invaders)
            super(invaders); 
            setImageName("alien4.gif");
        public void move()
            y = y + speedy;      
    }and finally..
    package InvadersGame;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics2D;
    import java.awt.geom.*;
    import java.util.ArrayList;
    import java.util.Random;
    import java.awt.image.BufferStrategy;
    public class SpaceInvaders extends Canvas{
        JPanel panel;
        //AlienEntity al, al2;
        Graphics2D g2;
        boolean gameRunning = true;
        ArrayList<GameEntities> entitiesList;
        AnimationThread thread;
        AlienEntity alien;
        private BufferStrategy buffer;
        ImageHandler imageHandler;
        class AnimationThread extends Thread
            public void run()
                while(true)
                    //paintAlien();
                    try
                        sleep(50);
                    catch(InterruptedException e){}
        public SpaceInvaders()
            super();
            imageHandler = new ImageHandler();
            JFrame window = new JFrame("Space Invaders");
            JPanel panel = (JPanel)window.getContentPane();
            setBounds(0, 0, 800, 600);
            panel.add(this);
            window.setBounds(0, 0, 800, 600);
            window.setVisible(true);         
            window.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
            setFocusable(true);
            this.createBufferStrategy(2);
            buffer = getBufferStrategy();
            thread = new AnimationThread();  
           paintAlien();
        public void paintAlien()
            Graphics2D g = (Graphics2D)buffer.getDrawGraphics();
            g.setColor(Color.black);
            g.fillRect(0, 0, getWidth(), getHeight());
            alien = new AlienEntity(this);
            alien.paint(g);
            buffer.show();
        public void setBufferstrategy(BufferStrategy buffer)
            buffer = buffer;
        public ImageHandler getImageHandler()
            return imageHandler;
        public static void main(String[] args)
            SpaceInvaders canvas = new SpaceInvaders();  
            canvas.thread.start();
    }Can someone please take the time an give me some pointers.
    Cheers

    I've tracked the problem to this bit of the code in the ImageHandler class:
    public BufferedImage loadImage(String name)
            try
                java.net.URL url = null;
                url = getClass().getResource(name);
                System.out.println(url); //to check whether the image was found
                return ImageIO.read(url);           
            catch(Exception e)
                System.exit(0);
                System.out.println("image not found");
                return null;
        For some reason the url = getClass().getResource(name); equals null even though the name I supply as an argument is exactly the same as the file name (alien4.gif).
    I'm not too sure whether the problem's with my code or the way netbeans is setup. Can someone please help.

  • Help with if statement in cursor and for loop to get output

    I have the following cursor and and want to use if else statement to get the output. The cursor is working fine. What i need help with is how to use and if else statement to only get the folderrsn that have not been updated in the last 30 days. If you look at the talbe below my select statement is showing folderrs 291631 was updated only 4 days ago and folderrsn 322160 was also updated 4 days ago.
    I do not want these two to appear in my result set. So i need to use if else so that my result only shows all folderrsn that havenot been updated in the last 30 days.
    Here is my cursor:
    /*Cursor for Email procedure. It is working Shows userid and the string
    You need to update these folders*/
    DECLARE
    a_user varchar2(200) := null;
    v_assigneduser varchar2(20);
    v_folderrsn varchar2(200);
    v_emailaddress varchar2(60);
    v_subject varchar2(200);
    Cursor c IS
    SELECT assigneduser, vu.emailaddress, f.folderrsn, trunc(f.indate) AS "IN DATE",
    MAX (trunc(fpa.attemptdate)) AS "LAST UPDATE",
    trunc(sysdate) - MAX (trunc(fpa.attemptdate)) AS "DAYS PAST"
    --MAX (TRUNC (fpa.attemptdate)) - TRUNC (f.indate) AS "NUMBER OF DAYS"
    FROM folder f, folderprocess fp, validuser vu, folderprocessattempt fpa
    WHERE f.foldertype = 'HJ'
    AND f.statuscode NOT IN (20, 40)
    AND f.folderrsn = fp.folderrsn
    AND fp.processrsn = fpa.processrsn
    AND vu.userid = fp.assigneduser
    AND vu.statuscode = 1
    GROUP BY assigneduser, vu.emailaddress, f.folderrsn, f.indate
    ORDER BY fp.assigneduser;
    BEGIN
    FOR c1 IN c LOOP
    IF (c1.assigneduser = v_assigneduser) THEN
    dbms_output.put_line(' ' || c1.folderrsn);
    else
    dbms_output.put(c1.assigneduser ||': ' || 'Overdue Folders:You need to update these folders: Folderrsn: '||c1.folderrsn);
    END IF;
    a_user := c1.assigneduser;
    v_assigneduser := c1.assigneduser;
    v_folderrsn := c1.folderrsn;
    v_emailaddress := c1.emailaddress;
    v_subject := 'Subject: Project for';
    END LOOP;
    END;
    The reason I have included the folowing table is that I want you to see the output from the select statement. that way you can help me do the if statement in the above cursor so that the result will look like this:
    emailaddress
    Subject: 'Project for ' || V_email || 'not updated in the last 30 days'
    v_folderrsn
    v_folderrsn
    etc
    [email protected]......
    Subject: 'Project for: ' Jim...'not updated in the last 30 days'
    284087
    292709
    [email protected].....
    Subject: 'Project for: ' Kim...'not updated in the last 30 days'
    185083
    190121
    190132
    190133
    190159
    190237
    284109
    286647
    294631
    322922
    [email protected]....
    Subject: 'Project for: Joe...'not updated in the last 30 days'
    183332
    183336
    [email protected]......
    Subject: 'Project for: Sam...'not updated in the last 30 days'
    183876
    183877
    183879
    183880
    183881
    183882
    183883
    183884
    183886
    183887
    183888
    This table is to shwo you the select statement output. I want to eliminnate the two days that that are less than 30 days since the last update in the last column.
    Assigneduser....Email.........Folderrsn...........indate.............maxattemptdate...days past since last update
    JIM.........      jim@ aol.com.... 284087.............     9/28/2006.......10/5/2006...........690
    JIM.........      jim@ aol.com.... 292709.............     3/20/2007.......3/28/2007............516
    KIM.........      kim@ aol.com.... 185083.............     8/31/2004.......2/9/2006.............     928
    KIM...........kim@ aol.com.... 190121.............     2/9/2006.........2/9/2006.............928
    KIM...........kim@ aol.com.... 190132.............     2/9/2006.........2/9/2006.............928
    KIM...........kim@ aol.com.... 190133.............     2/9/2006.........2/9/2006.............928
    KIM...........kim@ aol.com.... 190159.............     2/13/2006.......2/14/2006............923
    KIM...........kim@ aol.com.... 190237.............     2/23/2006.......2/23/2006............914
    KIM...........kim@ aol.com.... 284109.............     9/28/2006.......9/28/2006............697
    KIM...........kim@ aol.com.... 286647.............     11/7/2006.......12/5/2006............629
    KIM...........kim@ aol.com.... 294631.............     4/2/2007.........3/4/2008.............174
    KIM...........kim@ aol.com.... 322922.............     7/29/2008.......7/29/2008............27
    JOE...........joe@ aol.com.... 183332.............     1/28/2004.......4/23/2004............1585
    JOE...........joe@ aol.com.... 183336.............     1/28/2004.......3/9/2004.............1630
    SAM...........sam@ aol.com....183876.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183877.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183879.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183880.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183881.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183882.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183883.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183884.............3/5/2004.........3/8/2004............     1631
    SAM...........sam@ aol.com....183886.............3/5/2004.........3/8/2004............     1631
    SAM...........sam@ aol.com....183887.............3/5/2004.........3/8/2004............     1631
    SAM...........sam@ aol.com....183888.............3/5/2004.........3/8/2004............     1631
    PAT...........pat@ aol.com.....291630.............2/23/2007.......7/8/2008............     48
    PAT...........pat@ aol.com.....313990.............2/27/2008.......7/28/2008............28
    NED...........ned@ aol.com.....190681.............4/4/2006........8/10/2006............746
    NED...........ned@ aol.com......95467.............6/14/2006.......11/6/2006............658
    NED...........ned@ aol.com......286688.............11/8/2006.......10/3/2007............327
    NED...........ned@ aol.com.....291631.............2/23/2007.......8/21/2008............4
    NED...........ned@ aol.com.....292111.............3/7/2007.........2/26/2008............181
    NED...........ned@ aol.com.....292410.............3/15/2007.......7/22/2008............34
    NED...........ned@ aol.com.....299410.............6/27/2007.......2/27/2008............180
    NED...........ned@ aol.com.....303790.............9/19/2007.......9/19/2007............341
    NED...........ned@ aol.com.....304268.............9/24/2007.......3/3/2008............     175
    NED...........ned@ aol.com.....308228.............12/6/2007.......12/6/2007............263
    NED...........ned@ aol.com.....316689.............3/19/2008.......3/19/2008............159
    NED...........ned@ aol.com.....316789.............3/20/2008.......3/20/2008............158
    NED...........ned@ aol.com.....317528.............3/25/2008.......3/25/2008............153
    NED...........ned@ aol.com.....321476.............6/4/2008.........6/17/2008............69
    NED...........ned@ aol.com.....322160.............7/3/2008.........8/21/2008............4
    MOE...........moe@ aol.com.....184169.............4/5/2004.......12/5/2006............629
    [email protected]/27/2004.......3/8/2004............1631
    How do I incorporate a if else statement in the above cursor so the two days less than 30 days since last update are not returned. I do not want to send email if the project have been updated within the last 30 days.
    Edited by: user4653174 on Aug 25, 2008 2:40 PM

    analytical functions: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions2a.htm#81409
    CASE
    http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/02_funds.htm#36899
    http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/04_struc.htm#5997
    Incorporating either of these into your query should assist you in returning the desired results.

  • I need help with Sunbird Calendar, how can I transfer it from one computer to the other and to my iphone?

    I installed Sunbird in one computer and my calendar has all my infos, events, and task that i would like to see on another computer that i just downloaded Sunbird into. Also, is it possible I can access Sunbird on my iphone?
    Thank you in advance,

    Try the forum here - http://forums.mozillazine.org/viewforum.php?f=46 - for help with Sunbird, this forum is for Firefox support.

  • Hoping for some help with a very frustrating issue!   I have been syncing my iPhone 5s and Outlook 2007 calendar and contacts with iCloud on my PC running Vista. All was well until the events I entered on the phone were showing up in Outlook, but not

    Hoping for some help with a very frustrating issue!
    I have been syncing calendar and contacts on my iPhone 5 and Outlook 2007 using iCloud  2.1.3 (my PC is running Vista). All was well until the events I entered on the phone were showing up in Outlook, but not the other way around. I’ve tried the usual recommended steps: deselecting calendar and contacts in the iCloud control panel and then re-selecting, signing out of the panel and back in, and repairing the Outlook installation in control panel.  I even uninstalled iCloud on the PC and downloaded it again (same version). 
    The furthest I’ve gotten is step 2 (and once, step 3) of 7 while performing “Outlook Setup For iCloud.” At that point I get, “Your setup couldn’t be started because of an unexpected error.”  After the first attempt at all this, all my calendar events disappeared from Outlook, although they are still in iCloud calendar and on my phone.
    Sound familiar?  Any ideas on how to solve this iCloud/Outlook issue?  Thanks much in advance!

    Hoping for some help with a very frustrating issue!
    I have been syncing calendar and contacts on my iPhone 5 and Outlook 2007 using iCloud  2.1.3 (my PC is running Vista). All was well until the events I entered on the phone were showing up in Outlook, but not the other way around. I’ve tried the usual recommended steps: deselecting calendar and contacts in the iCloud control panel and then re-selecting, signing out of the panel and back in, and repairing the Outlook installation in control panel.  I even uninstalled iCloud on the PC and downloaded it again (same version). 
    The furthest I’ve gotten is step 2 (and once, step 3) of 7 while performing “Outlook Setup For iCloud.” At that point I get, “Your setup couldn’t be started because of an unexpected error.”  After the first attempt at all this, all my calendar events disappeared from Outlook, although they are still in iCloud calendar and on my phone.
    Sound familiar?  Any ideas on how to solve this iCloud/Outlook issue?  Thanks much in advance!

  • Help with HP Laser Printer 1200se

    HP Support Line,
    Really need your assistance.  I have tried both contacting HP by phone (told they no longer support our printer via phone help), the tech told me that I needed to contact HP by e-mail for assistance.   I then sent an e-mail for assistance and got that reply today, the reply is as follows  "Randall, unfortunately, HP does not offer support via e-mail for your product.  However many resources are available on the HP web site that may provide the answer to your inquiry.  Support is also available via telephone.  A list of technical support numbers can be round at the following URL........."  The phone numbers listed are the ones I called and the ones that told me I needed to contact the e-mail support for help.
    So here I am looking for your help with my issue.
    We just bought a new HP Pavillion Slimline Desk Top PC (as our 6 year old HP Pavillion PC died on us).  We have 2 HP printers, one (an all-in-one type printer, used maily for copying and printing color, when needed) is connected and it is working fine with the exception of the scanning option (not supported by Windows 7).  However we use our Laser Printer for all of our regular prining needs.  This is the HP LaserPrinter 1200se, which is about 6 years old but works really well.  For this printer we currently only have a parallel connection type cord and there is not a parallel port on the Slimline HP PC.  The printer also has the option to connedt a USB cable (we do not currently have this type of cable).
    We posed the following two questions:
    1.  Is the Laser Jet 1200se compatible with Windows 7?
    and if this is the case
    2.  Can we purchase either a) a USC connection cord (generic or do we need a printer specific cord)? or b) is there there a printer cable converter adapater to attach to our parallel cable to convert to a USB connection?
    We do not want to purchase the USB cable if Windows 7 will not accept the connection, or if doing this will harm the PC.
    We really would appreciate any assitance that you might give us.
    Thank you,
    Randy and Leslie Gibson

    Sorry, both cannot be enabled by design.  That said, devices on a network do not care how others are connected.  You can print from a wireless connection to a wired (Ethernet) printer and v/v.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

Maybe you are looking for

  • Efficiently identify modified values in JTable

    Hi I have a table with about 20 columns and 800 rows, It was read only , now i have open this table for editing. The user will update cells,and then click update database which will update those cells in database, is there a efficient way to do this,

  • Best way to implement DataGrid in JSP

    Hi, Can anyone please guide me as to what is the best way to implement a DataGrid in JSP ? Thanks in advance. -Sharada

  • "System Group" in SOA Suite 11g

    Everything looks good while upgrading ESB of FW 10g to Mediator of 11g. But seems there is no "Service Group" concept, which is introduced in ESB for projects hierarchy. Does anybody know any similar ideas in FW 11g? What I want is to group projects

  • Why are DNG images saved at 240ppi?

    I'm just learning to shoot in RAW. The first big problem I'm encountering is that after I manipulate my RAW image and want to save it as a DNG image, it gets saved at 240 ppi (and not at 300 ppi). How can I tell PE 6.o to save at 300 ppi?

  • Count the rows which differes a column value

    msg deleted Edited by: user11253970 on Jul 14, 2009 11:33 AM