Solved

errors...

Posted on 2006-06-13
4
252 Views
Last Modified: 2010-03-31
first add setters and getter to your class

public class Transaction {

  private String recordTrans ;
  private String accountNumber1 ;
  private String accountNumber2 ;
  private double amt ;
  private Calendar date ;
  private String type ;

     Calendar date;
     private Object rec;
     
     public Transaction(){
     
     }

     public void setType(String type) {
        this.type = type;
     }

     public String getType() {
        return type;    
    }

     
}



Transaction tx = new Transaction();
tx.setType("xxx");
tx.setDate(Calendar.getInstance());
}

this is my file and I am getting errors...cld someone help to fix...i dont get what its saying.

these are the errors: --------------------Configuration: <Default>--------------------
C:\Documents and Settings\Transaction.java:1: 'class' or 'interface' expected
first add setters and getter to your class
^
C:\Documents and Settings\Transaction.java:2: <identifier> expected
^
C:\Documents and Settings\Transaction.java:3: '{' expected
public class Transaction {
       ^
C:\Documents and Settings\Transaction.java:33: <identifier> expected
tx.setType("xxx");
          ^
C:\Documents and Settings\Transaction.java:34: <identifier> expected
tx.setDate(Calendar.getInstance());
          ^
5 errors

Process completed.

for the setters and getters, my entry in is correct..but it still says an error...why?
0
Comment
Question by:basgen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
Javatm earned 500 total points
ID: 16898557
You can't just intanciate the class ijust like that, better yet call it in a different class or create a main method to test it like :

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Transaction {

      private String recordTrans;
      private String accountNumber1;
      private String accountNumber2;
      private double amt;
      private Calendar date;
      private Object rec;
      private String type;

      public Transaction() {      }

      public void setType(String type) {
            this.type = type;
      }

      public String getType() {
            System.out.println(type);
            return type;
      }
      
      public void setDate(Calendar date) {
            this.date = date;
      }
      
      public Calendar getDate() {
            // Formatter for Date
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd - HH.mm.ss");
            System.out.println(sdf.format(date.getTime()));
            //System.out.println(s);
            return date;
      }

      public static void main(String args[]) {
            Transaction tx = new Transaction();
            tx.setType("Type String !");
            tx.setDate(Calendar.getInstance());
            tx.getType();
            tx.getDate();
            System.exit(0);
      }
}

PS: I removed some un-neccessary data.
0
 

Author Comment

by:basgen
ID: 16898634
hey Javatm would you be able to help in a problem that I was trying to figure out from the start?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 16904733
Shoot I'll try.
0
 

Author Comment

by:basgen
ID: 16908384
okie, i have this prob...this prog has so many errors and i cant understand where this is coming from? hava a look...ill give u the prog n the errors..

 public class AuditedTest {
  public static void main(String[] args) {
            
            AuditedCard  wallet[] = new AuditedCard [10]; ;         
          wallet[0] = new AuditedCard("5391 0375 9387 5309", "John Bowman",
                                   "California Savings", 0.0, 2500);
          wallet[1] = new AuditedCard("3485 0399 3395 1954", "John Bowman",
                                   "California Federal", 0.0, 3500);
          wallet[2] = new AuditedCard("6011 4902 3294 2994", "John Bowman",
                                   "California Finance", 0.0, 5000);
                            
          System.out.println("Credit Card Payments:");
   
          for(int j=0; j<wallet.length; j++) {
                if(j==0){
                      wallet[j].recordTrans("new", 0);
                      for (int i=1; i<=16; i++) {
                            wallet[j].recordTrans("debit", (double) i);      
                      }
                      wallet[j].print();
                      wallet[j].recordTrans("credit", 100.0);
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].print();
                } else if(j==1){
                      wallet[j].recordTrans("new", 0);
                      for (int i=1; i<=16; i++) {
                              wallet[j].recordTrans("debit", 2.0 * i);      
                      }
                      System.out.println();
                      wallet[j].print();
                      wallet[j].recordTrans("credit", 100.0);
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].recordTrans("credit", 100.0);                
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].print();
                } else {
                      wallet[j].recordTrans("new", 0);
                      for (int i=1; i<=16; i++) {
                              wallet[j].recordTrans("debit", (double) 3 * i);      
                      }
                      System.out.println();
                      wallet[j].print();
                      wallet[j].recordTrans("credit", 100.0);
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].recordTrans("credit", 100.0);
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].recordTrans("credit", 100.0);                
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].recordTrans("credit", 100.0);                
                      System.out.println("New Balance = " + wallet[j].getBalance());
                      wallet[j].print();
                }           
          }
    }
}


when i run the prog, i get an error, exception in thread "main" java .lang.NullpointerException at AuditedTest.main...would you be able to have a look?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question