Does anyone have time to look over a 3 class program? I get a NULL POINTER ERROR. What is the best way to debug a variable that produces this error? Thanks

if it is null pointer exception, thn it must have told you the line number, and the show you the hierarchy of the method calls, exactly where it was created... post both code and the error message.

Does anyone have time to look over a 3 class program? I get a NULL POINTER ERROR. What is the best way to debug a variable that produces this error? Thanks

Yes, as mentioned, the stack trace should tell you which method the error occurred in and the line number.

You can also use "if" checks and System.out.println() to verify variables if you are having trouble locating the problem:

String s = null;
if (s==null)
  System.out.println("a is null here!");

or you can use assertions

String s=null;
assert s!=null : "s is null!";

To use assertions, you must run the program with the "-ea" flag to enable them (ie "java -ea MyClass"). If the condition of the assertion is false, it will stop the program with an assertion error and show the message that you have supplied.

Yes, as mentioned, the stack trace should tell you which method the error occurred in and the line number.

You can also use "if" checks and System.out.println() to verify variables if you are having trouble locating the problem:

String s = null;
if (s==null)
  System.out.println("a is null here!");

or you can use assertions

String s=null;
assert s!=null : "s is null!";

To use assertions, you must run the program with the "-ea" flag to enable them (ie "java -ea MyClass"). If the condition of the assertion is false, it will stop the program with an assertion error and show the message that you have supplied.

creditcardtest :test creditcard and debitcard the variable setAcctTypeCode () "int" is causing a problem.NUll Pointer. I need help debugging Please
thanks

package creditcard;
//Credit Card Test - tests CreditCard class

/*
 Debit or Credit transaction (1=Debit, 2=Credit, 0=Exit): 1
 
Transaction (0=no transaction, +=deposit, -=new charge, -1=Display Logs): -15
 
Transaction Description: Daily Parking
 
 */
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.sql.SQLException;
import creditcard.CreditCard.*;
import tio.*;

class CreditCardTest {
    private DebitCard dc;
    private CreditCard cc;
    private long x;
    private double Transval=-2;
    private String Transdesc;
    private String AcctType;
    public static void main(String[] args) throws IOException, SQLException, Exception {
        new CreditCardTest();
    }
    public CreditCardTest() throws IOException, SQLException, Exception{
        long x=0;
        int Inval=-2;
        long AccountNo;
        double Transval=0;
        String Transdesc = null;
        String f = "CC_Num_status.txt";
        File file = new File(f);
        FormattedWriter fw=new FormattedWriter(f);
        System.out.println("Welcome to the Credit Card simulator!");
        System.out.println("Debit or Credit transaction (1=Debit, 2=Credit, 0=Exit): ");
        cc.setAcctTypeCode(Console.in.readInt());
        System.out.println("Existing Account, New Account, or Exit? (Existing Account=1, New Account=2, Exit=0): ");
        cc.setInval(Console.in.readInt());
        if(Inval==0){
            return;
        }
        if(Inval==1){
            System.out.println("Existing Account: enter Account #: ");
            x=Console.in.readLong();
            cc.setAccountNo(x);
            if(x==0){
                return;
            }
            if(x>0){
                //cc=new CreditCard(x,Y);
            }
        }
        if(Inval==2){
            //cc= new CreditCard(Y);
        }
        if(cc.getAcctType().equals("Credit")){
            while(Inval!=0){
                System.out.println("Account Type: "+cc.getAcctType());
                System.out.println("Account#: " +cc.getAccountNo());
                System.out.println("Date: " +cc.getDate());
                System.out.println("Credit Limit: " + cc.getCreditLimit());
                System.out.println("Available Credit: " + cc.getAvailable());
                System.out.println("Outstanding Balance: " + cc.getBalance());
                System.out.println("Charge: " + cc.getCharge());
                System.out.println("Description; " + cc.getDescription());
                System.out.println("payment: " + cc.getPayment());
                System.out.println("Total Charges: " + cc.getTotalCharges());
                System.out.println("Total Payments " + cc.getTotalPayments());
                
                System.out.println("\n");
                System.out.println("Transaction (0=Quit, +$=charge, -$=payment, 9999=Limit increase): ");
                setTransval(Console.in.readDouble());
                
                if (Transval == 0)
                    break;
                if (Transval == 9999){
                    cc.creditIncrease();
                }else{
                    if (Transval > 0){
                        System.out.println("Transaction description: ");
                        setTransdesc(Console.in.readLine());
                        setTransdesc(Console.in.readLine());
                        cc.Transaction(Transval,Transdesc);
                    }else
                        if(Transval==-1){
                        return;//////////////pending
                        }else{
                        if(Transval < 0){
                            System.out.println("Transaction Description: ");
                            setTransdesc(Console.in.readLine());
                            cc.Transaction(Transval,Transdesc);
                        }
                        
                        }
                }
            }
        }
        if(cc.getAcctType().equals("Debit")){
            while(Inval!=0){
                System.out.println("Account Type: "+cc.getAcctType());
                System.out.println("Debit Account Balance: "+cc.getBank());
                System.out.println("Account#: " +cc.getAccountNo());
                System.out.println("Date: " +cc.getDate());
                System.out.println("Charge: " +cc.getCharge());
                System.out.println("Description; " +cc.getDescription());
                System.out.println("Deposit; "+cc.getPayment());
                System.out.println("Total Charges: " + cc.getTotalCharges());
                System.out.println("Total Deposits " + cc.getTotalPayments());
                
                System.out.println("\n");
                
                System.out.println("Transaction (0=no transaction, -=deposit, +=new charge, -1=Display Logs): ");
                setTransval(Console.in.readDouble());
                if (Transval == 0){
                    break;
                }
                if (Transval == -1){
                    //pending
                }else{
                    if (Transval > 0){
                        System.out.println("Transaction description: ");
                        setTransdesc(Console.in.readLine());
                        setTransdesc(Console.in.readLine());
                        cc.Transaction(Transval,Transdesc);
                    }else
                        if(Transval < 0){
                        System.out.println("Transaction Description: ");
                        setTransdesc(Console.in.readLine());
                        cc.Transaction(Transval,Transdesc);
                        }
                    
                }
            }
        }
    }
    double getTransval(){
        return Transval;
    }
    void setTransval(double Transval){
        this.Transval=Transval;
    }
    String getTransdesc(){
        return Transdesc;
    }
    void setTransdesc(String Transdesc){
        this.Transdesc=Transdesc;
    }
}
package creditcard;
import creditcard.CreditCardTest.*;
import creditcard.DebitCard;
import db.DBConnection;
import java.lang.Object.*;
import java.io.*;
import java.sql.*;
import creditcard.CreditCardService;
import creditcard.CreditCardTest;
import java.util.Date;
import tio.*;
import java.io.File.*;
import java.io.IOException;
class CreditCard {
    private DebitCard dc;
    private long AccountNo;
    private double CreditLimit;
    private double Payment;
    private double TotalCharges;
    private double TotalPayments;
    private double Amount;
    private double Charge;
    private double Available;
    private double Balance;
    private int TransResult;
    private String TransErr;
    private String Description;
    private double increase=100;
    private String log=null;
    public String AcctType=null;
    private int Type;
    private FormattedWriter out;
    public CreditCardTest cct;
    private Statement stm = null;
    private ResultSet rst = null;
    private String tableName = "acctdata";
    private long x;
    private String query;
    private DBConnection db;
    private CreditCardService ccs;
    public Connection conn = null;
    private String date;
    public int AcctTypeCode=-1;
    private int Inval;
    private double Bank;
    private int drone=0;
    
    public CreditCard() throws FileNotFoundException, IOException{
       
        if(getAcctTypeCode()==1){
            setAcctType("Debit");
        }
        if(getAcctTypeCode()==2){
            setAcctType("Credit");
        }
        if(getAcctTypeCode()==0){
            setAcctType("Exit");
        }
        
         if(getAcctType()==("Exit")){
            return;
        }
        if(getAcctType().equals("Credit")){
            if(getAcctTypeCode()==1){
                new CreditCard(getAccountNo());
            }else{
                new CreditCard(drone);
            }
        }
         if(getAcctType().equals("Debit")){
            if(getAcctTypeCode()==1){
                 DebitCard dc = new DebitCard(getAccountNo());
                
            }else{
                DebitCard dc = new DebitCard(drone);
            }
        }
    }   
    public CreditCard(long x)throws FileNotFoundException,IOException{
        setAccountNo(this.x);
        setCreditLimit(1000);
        setBank(1000);
        setTotalCharges(0);
        setTotalPayments(0);
        Available();
        Balance();
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
       
    }
    public CreditCard(int drone) throws FileNotFoundException, IOException  {        
        setAcctType(AcctType);
        newAccount();
        setCreditLimit(1000);
        setBank(1000);
        setTotalCharges(0);
        setTotalPayments(0);
        Available();
        Balance();
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
    }
    private void accountStatus() throws IOException, SQLException, Exception{
        
        String f = "CC_Num_status.txt";
        File file = new File(f);
        FormattedWriter fw=new FormattedWriter(f);
        if(f!=null){
            fw.printfln(("Account Type: "+getAcctType()));
            fw.printfln("Account: " + getAccountNo());
            fw.printfln("Date: "+getDate());
            if(AcctType.equals("Credit")){
                fw.printfln("Credit Limit: " + getCreditLimit());
                fw.println("Account Balance: "+getBank());
                fw.printfln("Available Credit: " +getAvailable());
                fw.printfln("Outstanding Balance: " +getBalance());
            }
            fw.printfln("Last Transaction was Charge of: " + getCharge()+ "on "+getDate());
            fw.printfln("Description; " + getDescription());
            if(AcctType.equals("Debit")){
                fw.printfln("Last Transaction was charge of: " + getPayment()+ "on "+getDate());
            }else{
                fw.printfln("Last Transaction was payment of: " + getPayment()+ "on "+getDate());
                fw.printfln("Total Charges: " + getTotalCharges());
                fw.printfln("Total Payments " + getTotalPayments());
            }
        }
    }
    private void newAccount() throws FileNotFoundException, IOException {
        double r = Math.random();
        long x = (long)(r * 100000000);
        setAccountNo(x);
    }
    private void writeLog() throws FileNotFoundException, IOException, SQLException, Exception {
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
        String f = "CC" + AccountNo + ".txt";
        File log = new File(f);
        FormattedWriter out = new FormattedWriter(new FileWriter(log,true));
        out.printfln(AcctType);
        out.printfln(AccountNo);
        out.printfln(getDate());
        out.printfln(getBank());
        out.printfln(getPayment());
        if(getPayment()==0.0){
            setDescription("Deposit");
        }
        out.printfln(Description);
        
        out.printfln(getPayment());
        
        out.printfln(Description);
        
        out.close();
        CreditCardService ccs = new CreditCardService();
    }
    public void creditIncrease()throws FileNotFoundException, IOException, SQLException, Exception{
        TransResult = 0;
        if (Math.random() > .25) {
            CreditLimit += increase;
            setCreditLimit(CreditLimit);
            setDescription("Creditlimit increase of: $"+increase);
            System.out.println("Creditlimit increase of: $"+increase);
            accountStatus();
        } else {
            setDescription("Creditlimit increase denied: "+getDate());
            System.out.println("Sorry, credit increase not possible at this time.");
            TransResult = 1;
            accountStatus();
        }
    }
    public void TotalPayments(){
        TotalPayments=TotalPayments+Payment;
        setTotalPayments(TotalPayments);
        setCharge(0);
        
    }
    public void TotalCharges(){
        TotalCharges=TotalCharges+Charge;
        setTotalCharges(TotalCharges);
        setPayment(0);
    }
    public void Available() {
        double Available = CreditLimit - ( TotalCharges - TotalPayments );
        
        setAvailable(Available);
        setBank(Available);
    }
    
    public void Balance() {
        double Balance = ( TotalCharges - TotalPayments );
        
        setBalance(Balance);
    }
    public void Transaction(double Amount,String Description) throws FileNotFoundException, IOException, SQLException, Exception {
        setAmount(this.Amount);
        setDescription(this.Description);
        
        TransResult = 0;
        if ( Amount == 0 ) {
            TransResult = 1;
            setAmount(Amount);
            setDescription("Transaction amount is 0.");
            return;
        }
        if ( Amount > Available ) {
            setAmount(Amount);
            TransResult = 1;
            setDescription("Transaction amount of $" + Amount + " has exceeded the available credit limit $" + getAvailable());
            return;
        }
        if ( Description == "" ) {
            TransResult = 1;
            setDescription("No transaction description entered.");
            return;
        }
        if ( Amount > 0 ) {
            
            
            setCharge(Amount);
            
            TotalCharges();
            Available();
            Balance();
            if(AcctType.equals("Debit")){
                setBank(getAvailable());
                
            }
            
            accountStatus();
            writeLog();
            
        }
        if ( Amount < 0 ) {
            
            setPayment(-Amount);//this actually is set up to increase Payment variable positively.
            if(getAcctType().equals("Debit")){
                
                setDescription(Description);
            }else{
                setDescription("Payment");
            }
            TotalPayments();
            Available();
            Balance();
            if(AcctType.equals("Debit")){
                setBank(getAvailable());
            }
            
            accountStatus();
            writeLog();
            
        }
    }
    int Inval(){
        return Inval;
    }
    int getAcctTypeCode() {
        return AcctTypeCode;
    }
    String getAcctType(){
        return AcctType;
    }
    long getAccountNo(){
        return AccountNo;
    }
    String getDate() {
        return date;
    }
    double getAmount(){
        return Amount;
    }
    double getBank(){
        return Bank;
    }
    double getPayment(){
        return Payment;
    }
    double getCreditLimit(){
        return CreditLimit;
    }
    
    double getTotalCharges() {
        return TotalCharges;
    }
    
    String getDescription() {
        return Description;
    }
    
    double getTotalPayments() {
        return TotalPayments;
    }
    double getAvailable(){
        return Available;
    }
    double getBalance(){
        return Balance;
    }
    double getCharge() {
        return Charge;
    }
    
    void setAcctType(String AcctType){
        this.AcctType=AcctType;
    }
    void setAccountNo(long AccountNo) {
        this.AccountNo=AccountNo;
    }
    void setDate(String date) {
        this.date=date;
    }
    void setAmount(double Amount){
        this.Amount=Amount;
    }
    void setBank(double Bank){
        this.Bank=Bank;
    }
    void setPayment(double Payment){
        this.Payment=Payment;
    }
    void setCreditLimit(double CreditLimit){
        this.CreditLimit=CreditLimit;
    }
    
    void setTotalCharges(double TotalCharges) {
        this.TotalCharges=TotalCharges;
    }
    
    void setDescription(String Description) {
        this.Description=Description;
    }
    
    void setTotalPayments(double TotalPayments) {
        this.TotalPayments=TotalPayments;
    }
    
    void setAvailable(double Available) {
        this.Available=Available;
    }
    
    void setBalance(double Balance) {
        this.Balance=Balance;
    }
   void setCharge(double Charge){
        this.Charge=Charge;
    }
    void setAcctTypeCode(int AcctTypeCode){
        this.AcctTypeCode=AcctTypeCode;                
    }
    void setInval(int Inval) {
        this.Inval=Inval;
    }
    
    
    
    
    
}
/*
 * DebitCard.java
 *
 * Created on September 25, 2007, 5:20 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package creditcard;
import creditcard.CreditCardTest.*;
import creditcard.DebitCard;
import db.DBConnection;
import java.lang.Object.*;
import java.io.*;
import java.sql.*;
import creditcard.CreditCardService;
import creditcard.CreditCardTest;
import java.util.Date;
import tio.*;
import java.io.File.*;
import java.io.IOException;

/**
 *
 * @author fpcampus
 */
public class DebitCard extends CreditCard{
    private CreditCardTest cct;
    private CreditCard cc;
    private long x;
    private int drone;
    /** Creates a new instance of DebitCard */
    public  DebitCard(long x) throws FileNotFoundException, IOException{
        super();
    }
    public  DebitCard(int drone) throws FileNotFoundException, IOException{
        super();
    }
    private void accountStatus() throws IOException, SQLException, Exception{
        String f = "DC_Num_status.txt";
        File file = new File(f);
        FormattedWriter fw=new FormattedWriter(f);
        if(f!=null){
            fw.printfln(("Account Type: "+cc.getAcctType()));
            fw.printfln("Account: " + cc.getAccountNo());
            fw.printfln("Date: "+cc.getDate());
            fw.println("Account Balance: "+cc.getBank());
            fw.printfln("Available Credit: " +cc.getAvailable());
            fw.printfln("Outstanding Balance: " +cc.getBalance());
            fw.printfln("Last Transaction was Charge of: " + cc.getCharge()+ "on "+ cc.getDate());
            fw.printfln("Description; " + cc.getDescription());
            fw.printfln("Last Transaction was charge of: " + cc.getCharge()+ "on "+ cc.getDate());
            fw.printfln("Last Transaction was payment of: " + cc.getPayment()+ "on "+ cc.getDate());
            fw.printfln("Total Charges: " + cc.getTotalCharges());
            fw.printfln("Total Payments " + cc.getTotalPayments());
        }
    }
    private void writeLog() throws FileNotFoundException, IOException, SQLException, Exception {
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
        String f = "DC" + this.getAccountNo() + ".txt";
        File log = new File(f);
        FormattedWriter out = new FormattedWriter(new FileWriter(log,true));
        out.printfln( cc.getAcctType());
        out.printfln( cc.getAccountNo());
        out.printfln( cc.getDate());
        out.printfln(cc.getBank());
        out.printfln(cc.getPayment());
        if(getPayment()==0.0){
            cc.setDescription("Charge");
        }
        out.printfln(cc.getDescription());
        out.printfln(cc.getCharge());
        out.printfln(cc.getDescription());
        out.close();
        CreditCardService ccs = new CreditCardService();
    }
}







        /*
        super.CreditCard( x,Y);
        super.CreditCard(Y);
        super.accountStatus();
        super.newAccount();
        super.writeLog();
        super.creditIncrease();
        super.TotalPayments();
        super.TotalCharges();
        super.Available();
        super.Balance();
        super.Transaction(Amount,Description);
         
        super.getAcctTypeCode();
        super.getAcctType();
        super.getAccountNo();
        super.getDate();
        super.getAmount();
        super.getBank();
        super.getPayment();
        super.getCreditLimit();
        super.getTotalCharges();
        super.getDescription();
        super.getTotalPayments();
        super.getAvailable();
        super. getBalance();
        super. getCharge();
        super.setAcctTypeCode(AcctTypeCode);
        super.setAcctType(AcctType);
        super.setAccountNo(AccountNo);
        super.setDate(date);
        super.setAmount(Amount);
        super.setBank(Bank);
        super.setPayment(Payment);
        super.setCreditLimit(CreditLimit);
        super.setTotalCharges(TotalCharges);
        super.setDescription(Description);
        super.setTotalPayments( TotalPayments);
        super.setAvailable( Available);
        super.setBalance(Balance);
        super.setCharge(Charge);
         */

I think the problem is most likely with your Console.in.readInt() method. Are you sure this Console class is working correctly? Why not simply use Scanner for reading the values?

Sorry I'm not farmilar with scanner. My instructor gave me class "tio" it's methods seem to have always worked.

Ah, never mind, it is not the Console method. On that line you are calling

cc.setAcctTypeCode(Console.in.readInt());

but you haven't initialized "cc" yet. You can't call methods on objects that are not yet created.

Ah, never mind, it is not the Console method. On that line you are calling

cc.setAcctTypeCode(Console.in.readInt());

but you haven't initialized "cc" yet. You can't call methods on objects that are not yet created.

Would you be able to run this It did help to create a new creditcard. but now I have run out of ideas because it runs and then exits and I don't know where to start looking. Take your time. I would appreciate some ideas of what it is doing if you have time.
Thanks
ceyesuma

package creditcard;
//Credit Card Test - tests CreditCard class

/*
 Debit or Credit transaction (1=Debit, 2=Credit, 0=Exit): 1
 
Transaction (0=no transaction, +=deposit, -=new charge, -1=Display Logs): -15
 
Transaction Description: Daily Parking
 
 */
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.sql.SQLException;
import creditcard.CreditCard.*;
import tio.*;

class CreditCardTest {
    private DebitCard dc;
    private CreditCard cc;
    private long x;
    private double Transval=-2;
    private String Transdesc;
    private String AcctType;
    public static void main(String[] args) throws IOException, SQLException, Exception {
        new CreditCardTest();
    }
    public CreditCardTest() throws IOException, SQLException, Exception{
        CreditCard cc = new CreditCard();
        long x=0;
        int Inval=-2;
        long AccountNo;
        double Transval=0;
        String Transdesc = null;
        String f = "CC_Num_status.txt";
        File file = new File(f);
        FormattedWriter fw=new FormattedWriter(f);
        System.out.println("Welcome to the Credit Card simulator!");
        System.out.println("Debit or Credit transaction (1=Debit, 2=Credit, 0=Exit): ");
        cc.setAcctTypeCode(Console.in.readInt());
        System.out.println("Existing Account, New Account, or Exit? (Existing Account=1, New Account=2, Exit=0): ");
        cc.setInval(Console.in.readInt());
        if(Inval==0){
            return;
        }
        if(Inval==1){
            System.out.println("Existing Account: enter Account #: ");
            x=Console.in.readLong();
            cc.setAccountNo(x);
            if(x==0){
                return;
            }
            if(x>0){
                //cc=new CreditCard(x,Y);
            }
        }
        if(Inval==2){
            //cc= new CreditCard(Y);
        }
        if(cc.getAcctType()==("Credit")){
            while(Inval!=0){
                System.out.println("Account Type: "+cc.getAcctType());
                System.out.println("Account#: " +cc.getAccountNo());
                System.out.println("Date: " +cc.getDate());
                System.out.println("Credit Limit: " + cc.getCreditLimit());
                System.out.println("Available Credit: " + cc.getAvailable());
                System.out.println("Outstanding Balance: " + cc.getBalance());
                System.out.println("Charge: " + cc.getCharge());
                System.out.println("Description; " + cc.getDescription());
                System.out.println("payment: " + cc.getPayment());
                System.out.println("Total Charges: " + cc.getTotalCharges());
                System.out.println("Total Payments " + cc.getTotalPayments());
                
                System.out.println("\n");
                System.out.println("Transaction (0=Quit, +$=charge, -$=payment, 9999=Limit increase): ");
                setTransval(Console.in.readDouble());
                
                if (Transval == 0)
                    break;
                if (Transval == 9999){
                    cc.creditIncrease();
                }else{
                    if (Transval > 0){
                        System.out.println("Transaction description: ");
                        setTransdesc(Console.in.readLine());
                        setTransdesc(Console.in.readLine());
                        cc.Transaction(Transval,Transdesc);
                    }else
                        if(Transval==-1){
                        return;//////////////pending
                        }else{
                        if(Transval < 0){
                            System.out.println("Transaction Description: ");
                            setTransdesc(Console.in.readLine());
                            cc.Transaction(Transval,Transdesc);
                        }
                        
                        }
                }
            }
        }
        if(cc.getAcctType()==("Debit")){
            while(Inval!=0){
                System.out.println("Account Type: "+cc.getAcctType());
                System.out.println("Debit Account Balance: "+cc.getBank());
                System.out.println("Account#: " +cc.getAccountNo());
                System.out.println("Date: " +cc.getDate());
                System.out.println("Charge: " +cc.getCharge());
                System.out.println("Description; " +cc.getDescription());
                System.out.println("Deposit; "+cc.getPayment());
                System.out.println("Total Charges: " + cc.getTotalCharges());
                System.out.println("Total Deposits " + cc.getTotalPayments());
                
                System.out.println("\n");
                
                System.out.println("Transaction (0=no transaction, -=deposit, +=new charge, -1=Display Logs): ");
                setTransval(Console.in.readDouble());
                if (Transval == 0){
                    break;
                }
                if (Transval == -1){
                    //pending
                }else{
                    if (Transval > 0){
                        System.out.println("Transaction description: ");
                        setTransdesc(Console.in.readLine());
                        setTransdesc(Console.in.readLine());
                        cc.Transaction(Transval,Transdesc);
                    }else
                        if(Transval < 0){
                        System.out.println("Transaction Description: ");
                        setTransdesc(Console.in.readLine());
                        cc.Transaction(Transval,Transdesc);
                        }
                    
                }
            }
        }
    }
    double getTransval(){
        return Transval;
    }
    void setTransval(double Transval){
        this.Transval=Transval;
    }
    String getTransdesc(){
        return Transdesc;
    }
    void setTransdesc(String Transdesc){
        this.Transdesc=Transdesc;
    }
}
package creditcard;
import creditcard.CreditCardTest.*;
import creditcard.DebitCard;
import db.DBConnection;
import java.lang.Object.*;
import java.io.*;
import java.sql.*;
import creditcard.CreditCardService;
import creditcard.CreditCardTest;
import java.util.Date;
import tio.*;
import java.io.File.*;
import java.io.IOException;
class CreditCard {
    private DebitCard dc;
    private long AccountNo;
    private double CreditLimit;
    private double Payment;
    private double TotalCharges;
    private double TotalPayments;
    private double Amount;
    private double Charge;
    private double Available;
    private double Balance;
    private int TransResult;
    private String TransErr;
    private String Description;
    private double increase=100;
    private String log=null;
    public String AcctType=null;
    private int Type;
    private FormattedWriter out;
    public CreditCardTest cct;
    private Statement stm = null;
    private ResultSet rst = null;
    private String tableName = "acctdata";
    private long x;
    private String query;
    private DBConnection db;
    private CreditCardService ccs;
    public Connection conn = null;
    private String date;
    public int AcctTypeCode=-1;
    private int Inval;
    private double Bank;
    private int drone=0;
    
    public CreditCard() throws FileNotFoundException, IOException{
       
        if(getAcctTypeCode()==1){
            setAcctType("Debit");
        }
        if(getAcctTypeCode()==2){
            setAcctType("Credit");
        }
        if(getAcctTypeCode()==0){
            setAcctType("Exit");
        }
        
         if(getAcctType()==("Exit")){
            return;
        }
        if(getAcctType()==("Credit")){
            if(getAcctTypeCode()==1){
                new CreditCard(getAccountNo());
            }else{
                new CreditCard(drone);
            }
        }
         if(getAcctType()==("Debit")){
            if(getAcctTypeCode()==1){
                 DebitCard dc = new DebitCard(getAccountNo());
                
            }else{
                DebitCard dc = new DebitCard(drone);
            }
        }
    }   
    public CreditCard(long x)throws FileNotFoundException,IOException{
        setAccountNo(this.x);
        setCreditLimit(1000);
        setBank(1000);
        setTotalCharges(0);
        setTotalPayments(0);
        Available();
        Balance();
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
       
    }
    public CreditCard(int drone) throws FileNotFoundException, IOException  {        
        setAcctType(AcctType);
        newAccount();
        setCreditLimit(1000);
        setBank(1000);
        setTotalCharges(0);
        setTotalPayments(0);
        Available();
        Balance();
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
    }
    private void accountStatus() throws IOException, SQLException, Exception{
        
        String f = "CC_Num_status.txt";
        File file = new File(f);
        FormattedWriter fw=new FormattedWriter(f);
        if(f!=null){
            fw.printfln(("Account Type: "+getAcctType()));
            fw.printfln("Account: " + getAccountNo());
            fw.printfln("Date: "+getDate());
            if(AcctType==("Credit")){
                fw.printfln("Credit Limit: " + getCreditLimit());
                fw.println("Account Balance: "+getBank());
                fw.printfln("Available Credit: " +getAvailable());
                fw.printfln("Outstanding Balance: " +getBalance());
            }
            fw.printfln("Last Transaction was Charge of: " + getCharge()+ "on "+getDate());
            fw.printfln("Description; " + getDescription());
            if(AcctType==("Debit")){
                fw.printfln("Last Transaction was charge of: " + getPayment()+ "on "+getDate());
            }else{
                fw.printfln("Last Transaction was payment of: " + getPayment()+ "on "+getDate());
                fw.printfln("Total Charges: " + getTotalCharges());
                fw.printfln("Total Payments " + getTotalPayments());
            }
        }
    }
    private void newAccount() throws FileNotFoundException, IOException {
        double r = Math.random();
        long x = (long)(r * 100000000);
        setAccountNo(x);
    }
    private void writeLog() throws FileNotFoundException, IOException, SQLException, Exception {
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
        String f = "CC" + AccountNo + ".txt";
        File log = new File(f);
        FormattedWriter out = new FormattedWriter(new FileWriter(log,true));
        out.printfln(AcctType);
        out.printfln(AccountNo);
        out.printfln(getDate());
        out.printfln(getBank());
        out.printfln(getPayment());
        if(getPayment()==0.0){
            setDescription("Deposit");
        }
        out.printfln(Description);
        
        out.printfln(getPayment());
        
        out.printfln(Description);
        
        out.close();
        CreditCardService ccs = new CreditCardService();
    }
    public void creditIncrease()throws FileNotFoundException, IOException, SQLException, Exception{
        TransResult = 0;
        if (Math.random() > .25) {
            CreditLimit += increase;
            setCreditLimit(CreditLimit);
            setDescription("Creditlimit increase of: $"+increase);
            System.out.println("Creditlimit increase of: $"+increase);
            accountStatus();
        } else {
            setDescription("Creditlimit increase denied: "+getDate());
            System.out.println("Sorry, credit increase not possible at this time.");
            TransResult = 1;
            accountStatus();
        }
    }
    public void TotalPayments(){
        TotalPayments=TotalPayments+Payment;
        setTotalPayments(TotalPayments);
        setCharge(0);
        
    }
    public void TotalCharges(){
        TotalCharges=TotalCharges+Charge;
        setTotalCharges(TotalCharges);
        setPayment(0);
    }
    public void Available() {
        double Available = CreditLimit - ( TotalCharges - TotalPayments );
        
        setAvailable(Available);
        setBank(Available);
    }
    
    public void Balance() {
        double Balance = ( TotalCharges - TotalPayments );
        
        setBalance(Balance);
    }
    public void Transaction(double Amount,String Description) throws FileNotFoundException, IOException, SQLException, Exception {
        setAmount(this.Amount);
        setDescription(this.Description);
        
        TransResult = 0;
        if ( Amount == 0 ) {
            TransResult = 1;
            setAmount(Amount);
            setDescription("Transaction amount is 0.");
            return;
        }
        if ( Amount > Available ) {
            setAmount(Amount);
            TransResult = 1;
            setDescription("Transaction amount of $" + Amount + " has exceeded the available credit limit $" + getAvailable());
            return;
        }
        if ( Description == "" ) {
            TransResult = 1;
            setDescription("No transaction description entered.");
            return;
        }
        if ( Amount > 0 ) {
            
            
            setCharge(Amount);
            
            TotalCharges();
            Available();
            Balance();
            if(AcctType==("Debit")){
                setBank(getAvailable());
                
            }
            
            accountStatus();
            writeLog();
            
        }
        if ( Amount < 0 ) {
            
            setPayment(-Amount);//this actually is set up to increase Payment variable positively.
            if(getAcctType()==("Debit")){
                
                setDescription(Description);
            }else{
                setDescription("Payment");
            }
            TotalPayments();
            Available();
            Balance();
            if(AcctType.equals("Debit")){
                setBank(getAvailable());
            }
            
            accountStatus();
            writeLog();
            
        }
    }
    int Inval(){
        return Inval;
    }
    int getAcctTypeCode() {
        return AcctTypeCode;
    }
    String getAcctType(){
        return AcctType;
    }
    long getAccountNo(){
        return AccountNo;
    }
    String getDate() {
        return date;
    }
    double getAmount(){
        return Amount;
    }
    double getBank(){
        return Bank;
    }
    double getPayment(){
        return Payment;
    }
    double getCreditLimit(){
        return CreditLimit;
    }
    
    double getTotalCharges() {
        return TotalCharges;
    }
    
    String getDescription() {
        return Description;
    }
    
    double getTotalPayments() {
        return TotalPayments;
    }
    double getAvailable(){
        return Available;
    }
    double getBalance(){
        return Balance;
    }
    double getCharge() {
        return Charge;
    }
    
    void setAcctType(String AcctType){
        this.AcctType=AcctType;
    }
    void setAccountNo(long AccountNo) {
        this.AccountNo=AccountNo;
    }
    void setDate(String date) {
        this.date=date;
    }
    void setAmount(double Amount){
        this.Amount=Amount;
    }
    void setBank(double Bank){
        this.Bank=Bank;
    }
    void setPayment(double Payment){
        this.Payment=Payment;
    }
    void setCreditLimit(double CreditLimit){
        this.CreditLimit=CreditLimit;
    }
    
    void setTotalCharges(double TotalCharges) {
        this.TotalCharges=TotalCharges;
    }
    
    void setDescription(String Description) {
        this.Description=Description;
    }
    
    void setTotalPayments(double TotalPayments) {
        this.TotalPayments=TotalPayments;
    }
    
    void setAvailable(double Available) {
        this.Available=Available;
    }
    
    void setBalance(double Balance) {
        this.Balance=Balance;
    }
   void setCharge(double Charge){
        this.Charge=Charge;
    }
    void setAcctTypeCode(int AcctTypeCode){
        this.AcctTypeCode=AcctTypeCode;                
    }
    void setInval(int Inval) {
        this.Inval=Inval;
    }
    
    
    
    
    
}
/*
 * DebitCard.java
 *
 * Created on September 25, 2007, 5:20 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package creditcard;

import creditcard.DebitCard;
import db.DBConnection;
import java.lang.Object.*;
import java.io.*;
import java.sql.*;
import creditcard.CreditCardService;
import creditcard.CreditCardTest;
import java.util.Date;
import tio.*;
import java.io.File.*;
import java.io.IOException;

/**
 *
 * @author fpcampus
 */
public class DebitCard extends CreditCard{
    private CreditCardTest cct;
    private CreditCard cc;
    private long x;
    private int drone;
    /** Creates a new instance of DebitCard */
    public  DebitCard(long x) throws FileNotFoundException, IOException{
        super();
    }
    public  DebitCard(int drone) throws FileNotFoundException, IOException{
        super();
    }
    private void accountStatus() throws IOException, SQLException, Exception{
        String f = "DC_Num_status.txt";
        File file = new File(f);
        FormattedWriter fw=new FormattedWriter(f);
        if(f!=null){
            fw.printfln(("Account Type: "+cc.getAcctType()));
            fw.printfln("Account: " + cc.getAccountNo());
            fw.printfln("Date: "+cc.getDate());
            fw.println("Account Balance: "+cc.getBank());
            fw.printfln("Available Credit: " +cc.getAvailable());
            fw.printfln("Outstanding Balance: " +cc.getBalance());
            fw.printfln("Last Transaction was Charge of: " + cc.getCharge()+ "on "+ cc.getDate());
            fw.printfln("Description; " + cc.getDescription());
            fw.printfln("Last Transaction was charge of: " + cc.getCharge()+ "on "+ cc.getDate());
            fw.printfln("Last Transaction was payment of: " + cc.getPayment()+ "on "+ cc.getDate());
            fw.printfln("Total Charges: " + cc.getTotalCharges());
            fw.printfln("Total Payments " + cc.getTotalPayments());
        }
    }
    private void writeLog() throws FileNotFoundException, IOException, SQLException, Exception {
        Date dt = new Date();
        String z = dt.toString();
        setDate(z);
        String f = "DC" + this.getAccountNo() + ".txt";
        File log = new File(f);
        FormattedWriter out = new FormattedWriter(new FileWriter(log,true));
        out.printfln( cc.getAcctType());
        out.printfln( cc.getAccountNo());
        out.printfln( cc.getDate());
        out.printfln(cc.getBank());
        out.printfln(cc.getPayment());
        if(getPayment()==0.0){
            cc.setDescription("Charge");
        }
        out.printfln(cc.getDescription());
        out.printfln(cc.getCharge());
        out.printfln(cc.getDescription());
        out.close();
        CreditCardService ccs = new CreditCardService();
    }
}







        /*
        super.CreditCard( x,Y);
        super.CreditCard(Y);
        super.accountStatus();
        super.newAccount();
        super.writeLog();
        super.creditIncrease();
        super.TotalPayments();
        super.TotalCharges();
        super.Available();
        super.Balance();
        super.Transaction(Amount,Description);
         
        super.getAcctTypeCode();
        super.getAcctType();
        super.getAccountNo();
        super.getDate();
        super.getAmount();
        super.getBank();
        super.getPayment();
        super.getCreditLimit();
        super.getTotalCharges();
        super.getDescription();
        super.getTotalPayments();
        super.getAvailable();
        super. getBalance();
        super. getCharge();
        super.setAcctTypeCode(AcctTypeCode);
        super.setAcctType(AcctType);
        super.setAccountNo(AccountNo);
        super.setDate(date);
        super.setAmount(Amount);
        super.setBank(Bank);
        super.setPayment(Payment);
        super.setCreditLimit(CreditLimit);
        super.setTotalCharges(TotalCharges);
        super.setDescription(Description);
        super.setTotalPayments( TotalPayments);
        super.setAvailable( Available);
        super.setBalance(Balance);
        super.setCharge(Charge);
         */

your question is not clear at this point... besides, we can not run your code (you did not provide creditCard pkg)... as ezzaral mentioned, your problem is with initializing cc... you can not access any object which you have not created.... (your cc does not exist)... very natural to get null pointer exception... initialize cc first somewhere... it should work... good luck!

This question has already been answered. Start a new discussion instead.