Results 1 to 3 of 3

Thread: App chrashing

  1. #1
    newProgrammer is offline Member
    Join Date
    Mar 2012
    Posts
    8
    Rep Power
    0

    Default App chrashing

    im building a budgetting app and currently when i start the app it chrashes im only having two class interact at the point it chrashes any help is welcomed line 29 is where the problem occours
    Java Code:
    package budget.app;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Spinner;
    
    public class BudgetStart extends Activity {
    
    	Spinner spinner;
    	
    	@Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_budget_start);
            Button a = (Button)findViewById(R.id.pay_day);
            Button b = (Button)findViewById(R.id.edit_budget);
            Button c = (Button)findViewById(R.id.record_expeance);
            Button d = (Button)findViewById(R.id.add_budget);
            Button e = (Button)findViewById(R.id.delete_budget);
            Button f = (Button)findViewById(R.id.review_details);
    
            BudgetDB entry = new BudgetDB();
            entry.open();
            entry.close();
            a.setOnClickListener(new OnClickListener() 
            {
    			
    			public void onClick(View v) 
    			{
    				// TODO Auto-generated method stub
    				
    			}
    		});
            b.setOnClickListener(new OnClickListener() 
            {
    			
    			public void onClick(View v) 
    			{
    				// TODO Auto-generated method stub
    				startActivity(new Intent(BudgetStart.this,EditBudget.class));
    			}
    		});
            c.setOnClickListener(new OnClickListener() 
            {
    			
    			public void onClick(View v) 
    			{
    				// TODO Auto-generated method stub
    				startActivity(new Intent(BudgetStart.this, RecordExpeance.class));
    			}
    		});
            d.setOnClickListener(new OnClickListener() 
            {
    			
    			public void onClick(View v) 
    			{
    				// TODO Auto-generated method stub
    				startActivity(new Intent(BudgetStart.this, AddBudget.class));
    			}
    		});
            e.setOnClickListener(new OnClickListener() 
            {
    			
    			public void onClick(View v) 
    			{
    				// TODO Auto-generated method stub
    				
    			}
    		});
            f.setOnClickListener(new OnClickListener() 
            {
    			
    			public void onClick(View v) 
    			{
    				// TODO Auto-generated method stub
    				startActivity(new Intent(BudgetStart.this, ReviewBudget.class));
    			}
    		});
    
            
            spinner = (Spinner) findViewById(R.id.sBudgets);
        }
    
    
    	@Override
        public boolean onCreateOptionsMenu(Menu menu) 
        {
            getMenuInflater().inflate(R.menu.activity_budget_start, menu);
            return true;
        }
    }
    this is the 2nd class that is being used
    Java Code:
    package budget.app;
    
    import android.content.ContentValues;//
    import android.content.Context;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteDatabase.CursorFactory;//
    import android.database.sqlite.SQLiteOpenHelper;
    
    public class BudgetDB {
    	
    	public static final String KEY_CATEGORYID = "category_id";
    	public static final String KEY_NAME = "budget_name";
    	public static final String KEY_AMOUNT = "budget_amount";
    	public static final String KEY_DATE = "edit_date";
    	public static final String KEY_DISCRIPTION = "trans_description";
    	public static final String KEY_TRANSACTION = "_transaction";
    	public static final String KEY_MEMO = "_memo";
    	public static final String KEY_PAYDAY = "pay_day";
    	
    	private static final String DATABASE_NAME = "Budgets List";
    	private static final String DATABASE_TABLE1 = "Budget Category";
    	private static final String DATABASE_TABLE2 = "Budget Items";
    	private static final String DATABASE_TABLE3 = "bTransaction types";
    	private static final String DATABASE_TABLE4 = "Budget Memos";
    	private static final int DATABASE_VERSION = 1;
    	
    	private static final String CREATE_TABLE_1 = "CREATE TABLE" +DATABASE_TABLE1 +" (" +
    			KEY_CATEGORYID + "INTEGER PRIMARY KEY AUTOINCREMENT, " +
    			KEY_NAME + "TEXT NOT NULL" +
    			KEY_PAYDAY + "INTEGER NOT NULL);";
    	private static final String CREATE_TABLE_2 ="CREATE TABLE" + DATABASE_TABLE2 + " (" +
    			KEY_CATEGORYID + "INTEGER FOREIGN KEY, " + 
    			KEY_TRANSACTION + "INTEGER PRIMARY KEY, " +
    			KEY_AMOUNT+ "INTEGER NOT NULL, " + 
    			KEY_DATE + "TEXT NOT NULL);" ;
    	private static final String CREATE_TABLE_3 ="CREATE TABLE" + DATABASE_TABLE3 + " (" +
    			KEY_TRANSACTION + "INTEGER FOREIGN KEY, " + 
    			KEY_DISCRIPTION + " TEXT NOT NULL);" ;
    	private static final String CREATE_TABLE_4 ="CREATE TABLE" + DATABASE_TABLE4 + " (" +
    			KEY_CATEGORYID + "INTEGER FOREIGN KEY, " + 
    			KEY_DATE + " TEXT NOT NULL" + 
    			KEY_MEMO + " TEXT NOT NULL);" ;
    	
    	
    	
    	private DBHelper ourHelper;
        private static Context ourContext;
    	private SQLiteDatabase ourDatabase;//
    	
    	private static class DBHelper extends SQLiteOpenHelper{
    
    		public DBHelper(Context context) {
    			super(context, DATABASE_NAME, null, DATABASE_VERSION);
    			
    		}
    
    		@Override
    		public void onCreate(SQLiteDatabase db) {
    			// TODO Auto-generated method stub
    			db.execSQL(CREATE_TABLE_1);
    			db.execSQL(CREATE_TABLE_2);
    			db.execSQL(CREATE_TABLE_3);
    			db.execSQL(CREATE_TABLE_4);
    			
    		}
    
    		@Override
    		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    			// TODO Auto-generated method stub
    			db.execSQL("DROP TABLE IF EXIXSTS" + DATABASE_TABLE1);
    			onCreate(db);
    		}
    		public void BudgetDB(Context c){//
    			ourContext = c;
    			
    		}
    		}
    		public BudgetDB open() throws SQLException{
    			
    			ourHelper = new DBHelper(ourContext);
    			ourDatabase = ourHelper.getWritableDatabase();
    			return this;			
    		}
    	public void close() {
    		// TODO Auto-generated method stub
    		ourHelper.close();
    		
    	}
    
    
    }
    this is the logcat
    Java Code:
    10-30 09:10:00.972: E/Trace(607): error opening trace file: No such file or directory (2)
    10-30 09:10:01.582: D/AndroidRuntime(607): Shutting down VM
    10-30 09:10:01.591: W/dalvikvm(607): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
    10-30 09:10:01.611: E/AndroidRuntime(607): FATAL EXCEPTION: main
    10-30 09:10:01.611: E/AndroidRuntime(607): java.lang.RuntimeException: Unable to start activity ComponentInfo{budget.app/budget.app.BudgetStart}: java.lang.NullPointerException
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.ActivityThread.access$600(ActivityThread.java:130)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.os.Looper.loop(Looper.java:137)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at java.lang.reflect.Method.invokeNative(Native Method)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at java.lang.reflect.Method.invoke(Method.java:511)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at dalvik.system.NativeStart.main(Native Method)
    10-30 09:10:01.611: E/AndroidRuntime(607): Caused by: java.lang.NullPointerException
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at budget.app.BudgetDB.open(BudgetDB.java:82)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at budget.app.BudgetStart.onCreate(BudgetStart.java:29)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.Activity.performCreate(Activity.java:5008)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
    10-30 09:10:01.611: E/AndroidRuntime(607): 	... 11 more

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: App chrashing

    It looks to me like the context is null here:
    Java Code:
     public BudgetDB open() throws SQLException{
                 
                ourHelper = new DBHelper(ourContext);
    You never set/pass the context.
    Java Code:
       public void BudgetDB(Context c){//
                ourContext = c;
                 
            }
    Maybe you wanted to use this as constructor? Then you have to delete the void and change the code from the inner class out to the BudgetDB class and pass the context (this.getApplicationContext()) to the constructor at "BudgetDB entry = new BudgetDB();"
    Then you have many syntax errors in your db statements. Check the missing whitespaces/(commas) between "CREATE TABLE" and the Table name. And if you have table names with white spaces use '.....'.

  3. #3
    newProgrammer is offline Member
    Join Date
    Mar 2012
    Posts
    8
    Rep Power
    0

    Default Re: App chrashing

    thank you for the help i have gotten the program running and currently error free

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •