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 8360449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:28:15+00:00 2026-06-09T11:28:15+00:00

I have 3 Activities: The Form Activity, DataBase Helper, and the Main Activity. The

  • 0

I have 3 Activities: The Form Activity, DataBase Helper, and the Main Activity.
The Main Activity should display list view of the “compNameAdd” that stores in the DataBase.
When i am trying to populate the list view through setAdapter

    DataBase dbc = new DataBase(NituachActivity.this);
    dbc.open();

    String[] cs = new String[] { DataBase.RAW_COMPNAMEADD };

    Log.d(TAG, cs.toString());

     blv.setAdapter(new ArrayAdapter<String>(this,
     android.R.layout.simple_list_item_1, cs));

    dbc.close();

I get the name of the column and not the values in the column. what is the problem?

DataBase Helper:

package com.nituach.nituach;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBase {

public static final String RAW_ID = "_id";
public static final String RAW_COMPNAMEADD = "compNameAdd";
public static final String RAW_CASH = "etCash";
public static final String RAW_CUSTOMERS = "castumers";
public static final String RAW_STOCK = "stock";
public static final String RAW_FIXED_ASSETS = "fixedAssets";
public static final String RAW_ACCUMULTED_DEPRECIATION = "accumultedDepreciation";
public static final String RAW_BONDS = "bonds";
public static final String RAW_LOANS = "loans";
public static final String RAW_EQUITY = "equity";

public static final String RAW_COMPNAME_ID = "_id";
public static final String RAW_COMPNAME = "compName";

private static final String DATABASE_NAME = "ProsseDatBase";
static final String DATABASE_TABLE = "data";
static final String DATABASE_TABLE_SETTINGS = "compNameConnector";

private static final int DATABASE_VERSION = 1;

private ProsseDatBase thdb;
private static Context tcontext;
private SQLiteDatabase tdb;

private static class ProsseDatBase extends SQLiteOpenHelper {

    public ProsseDatBase(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String pdb = "CREATE TABLE  " + DATABASE_TABLE + " ( " + RAW_ID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
RAW_COMPNAMEADD
                + " TEXT, " + RAW_CASH + " TEXT, " + RAW_CUSTOMERS
                + " TEXT, " + RAW_STOCK + " TEXT, " + RAW_FIXED_ASSETS
                + " TEXT, " + RAW_ACCUMULTED_DEPRECIATION + " TEXT, "
                + RAW_BONDS + " TEXT, " + RAW_LOANS + " TEXT, " + 
RAW_EQUITY
                + " TEXT);";
        db.execSQL(pdb);

        String cndb = "CREATE TABLE  " + DATABASE_TABLE_SETTINGS + " ( "
                + RAW_COMPNAME_ID + " INTEGER PRIMARY KEY 
AUTOINCREMENT, "
                + RAW_COMPNAME + " TEXT);";
        db.execSQL(cndb);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_SETTINGS);
        onCreate(db);
    }
}

public DataBase(Context c) {
    tcontext = c;
}

public DataBase open() throws SQLiteException {
    thdb = new ProsseDatBase(tcontext);
    tdb = thdb.getWritableDatabase();
    return this;
}

public SQLiteDatabase getDatabase() {
    return tdb;
}

public void close() {
    tdb.close();
}

public long createEntry(String cm, String ch, String sk, String ot,
        String fs, String an, String bs, String ls, String ey) {
    ContentValues cv = new ContentValues();
    cv.put(RAW_COMPNAMEADD, cm);
    cv.put(RAW_CASH, ch);
    cv.put(RAW_CUSTOMERS, ot);
    cv.put(RAW_STOCK, sk);
    cv.put(RAW_FIXED_ASSETS, fs);
    cv.put(RAW_ACCUMULTED_DEPRECIATION, an);
    cv.put(RAW_BONDS, bs);
    cv.put(RAW_LOANS, ls);
    cv.put(RAW_EQUITY, ey);

    return tdb.insert(DATABASE_TABLE, null, cv);
}

public String getData() {
    String[] columns = new String[] { RAW_COMPNAMEADD };
    Cursor c = tdb.query(DATABASE_TABLE, columns, null, null, null, null,
            null);
    String results = "";

    int iCM = c.getColumnIndex(RAW_COMPNAMEADD);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        results = results + c.getString(iCM) + "\n";
    }
    return results;
}
}

The Main Activity:

package com.nituach.nituach;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class NituachActivity extends Activity implements OnClickListener {

Button addNewBuisness;
ListView blv;
TextView tay;
String tyy;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final String TAG = NituachActivity.class.getSimpleName();
    addNewBuisness = (Button) findViewById(R.id.btnAddNewBuisness);
    addNewBuisness.setOnClickListener(NituachActivity.this);
    blv = (ListView) findViewById(R.id.listView1);
    tay = (TextView) findViewById(R.id.TempArray);

    Log.d(TAG, "All Variables was created");
    DataBase dbc = new DataBase(NituachActivity.this);
    dbc.open();

    String[] cs = new String[] { DataBase.RAW_COMPNAMEADD };

    Log.d(TAG, cs.toString());

     blv.setAdapter(new ArrayAdapter<String>(this,
     android.R.layout.simple_list_item_1, cs));

    dbc.close();


}

public void onClick(View v) {
    Intent addnbIntent = new Intent(NituachActivity.this,
            AddNewBuisness.class);
    NituachActivity.this.startActivity(addnbIntent);

}
}
  • 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-06-09T11:28:16+00:00Added an answer on June 9, 2026 at 11:28 am

    You did not actually call getData() to get your values from your main activity.

    First, change the method signature getData() to return array of string instead:

    public List<String> getData() {
        String[] columns = new String[] { RAW_COMPNAMEADD };
        Cursor c = tdb.query(DATABASE_TABLE, columns, null, null, null, null,
            null);
        String results = "";
        List<String> results = new ArrayList<String>();
        int iCM = c.getColumnIndex(RAW_COMPNAMEADD);
    
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            results.add(c.getString(iCM);
        }
        return results;
    }
    

    Then in your mainactivity, change to this:

    DataBase dbc = new DataBase(NituachActivity.this);
    dbc.open();
    
    List<String> cs = dbc.getData();
     blv.setAdapter(new ArrayAdapter<String>(this,
     android.R.layout.simple_list_item_1, cs));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have 2 activities. The first activity is an activity that parses JSON data
I have an Activity that has some form elements. This can be called from
I have two activities A and B . Activity A has a form and
I have 40 activities that do not depend on each other. I want to
I have five activities/screens that I would like to be able to swipe between,
I have two activities. In first I come to the second activity from first
I have a Windows Service that performs a number of periodic activities, and I
I have two activities; Home is my first activity and Settings is my second

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.