Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:31:05+00:00 2026-05-31T08:31:05+00:00

Having issue with displaying the Data from a second Activity. when I run the

  • 0

Having issue with displaying the Data from a second Activity.
when I run the method getData form the second Activity it will crash.

Class Dabase

public static final String KEY_ROWID = "ExpenseID";     
    public static final String KEY_Expense = "ExpenseDescription";
    public static final String KEY_Amount = "Amount";

    private static final String DATABASE_NAME = "CSolutionsLlcBudget";
    private static final String DATABASE_TABLE = "Expense";

    private static final int DATABASE_VERSION = 4;
    private static final String CREATE_TABLE_1 = "CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " 
    + KEY_Expense + "TEXT NOT NULL, " + KEY_Amount + "TEXT NOT NULL);";

    private DbHelper ourHelper;
    private final Context ourContext;
    private SQLiteDatabase ourDatabase;

    private static class DbHelper extends SQLiteOpenHelper{

        public DbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub

        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub          
            db.execSQL(CREATE_TABLE_1);         
        }//end of onCreate

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);           
            onCreate(db);
        }

    }//end of class
    public BudgetInfo(Context c){
        ourContext = c;
    }

    public BudgetInfo open() throws SQLException{
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }
    public void close(){
        ourHelper.close();
    }

    public long createEntry(String expense, String amount) {
        // TODO Auto-generated method stub
        ContentValues cv = new ContentValues();
        cv.put(KEY_Expense, expense);
        cv.put(KEY_Amount, amount);
        return ourDatabase.insert(DATABASE_TABLE, null, cv);
    }   

    public String getData() {
        // TODO Auto-generated method stub
        String[] columns = new String[]{KEY_ROWID, KEY_Expense, KEY_Amount};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
        String result = "";


        int iRow = c.getColumnIndex(KEY_ROWID);
        int iExpense = c.getColumnIndex(KEY_Expense);
        int iAmount = c.getColumnIndex(KEY_Amount);

        for(c.moveToFirst();!c.isAfterLast(); c.moveToNext()){
            result = result + c.getString(iRow) + " " + c.getString(iExpense) + " " + c.getString(iAmount) + "\n";
        }
        return result;
    }

Second Activity

public class SQLView extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sqlview);
        TextView tv = (TextView) findViewById(R.id.tvSQLinfo);
        BudgetInfo info = new BudgetInfo(this);
        info.open();
        String data = info.getData();        
        tv.setText(data);
        info.close();
    }
}

The app crashes every time I click to view the second Activity

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:31:06+00:00Added an answer on May 31, 2026 at 8:31 am

    Here a few things u gotto try first. I am assuming you are inserting data into ure table in a previous activity.

    1. Check that your database is getting created properly.

    2. Check that you have data in your database.

    3. Also check that your cursor is not null and returns true for movetofirst(). ( This you must do even if you get your solution from other posts).

    4. Always close the cursor after you are done with it. I don’t see u r doing it here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue with the using jqGrid with JSON data returned from
I am having an issue selecting and displaying a substring from each of the
I am quite new to rails... I am having an issue with displaying of
I'm having an issue with the PDF displaying outside the viewable area of the
I'm having an issue displaying an object in a checked list box in C#.
I'm having some troubles with displaying a graph. It's a very strange issue, because
I'm having an issue where our cell table is only displaying 15 rows. I
I'm having trouble displaying an image in a UIWebView. I retrieve html content from
Having issues with screen progress. I have a screen displaying information from a database.
currently im working on symfony based large application. i m having issue on displaying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.