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

  • SEARCH
  • Home
  • 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 7535197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:15:08+00:00 2026-05-30T06:15:08+00:00

I am trying to write a query for retrieving data from SQLite database. I

  • 0

I am trying to write a query for retrieving data from SQLite database. I wanted to print the result of a query in a text box. So I used a getint() method for the cursor. Below is my code. It does not start in my Android emulator. Is it the correct way to write the query? It is showing no errors.

import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.*;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class SQLDemo1Activity extends Activity {
  private SQLiteDatabase db;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try{
      db= SQLiteDatabase.openDatabase(
        "/data/data/cis493.sqldatabases/databases/multilinguialdatabase.sqlite",
        null,
        SQLiteDatabase.CREATE_IF_NECESSARY);
      db.beginTransaction();
      Cursor cursor =  db.query(
        "colors" /* table */,
        new String[] { "ID" } /* columns */,
        "English = ?" /* where or selection */,
        new String[] { "green" } /* selectionArgs i.e. value to replace ? */,
        null /* groupBy */,
        null /* having */,
        null /* orderBy */
      );
      int id = cursor.getInt(0);
      TextView met = (TextView) findViewById(R.id.t1);
      met.setText(id);
      db.endTransaction();
      db.close();
    }
    catch(SQLiteException e) {
      Toast.makeText(this, e.getMessage(), 1).show();
    }
  }
}
  • 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-30T06:15:09+00:00Added an answer on May 30, 2026 at 6:15 am

    You need to put cursor.moveToNext() or cursor.moveToFirst() before trying to get the int with getInt(). Put it in an if statement as there may be no results in the cursor.

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

Sidebar

Related Questions

I'm trying to write a query that extracts and transforms data from a table
I'm trying to write a query that returns the same result from three different
I am trying to write a query that grabs information from one database and
Im trying to write query in linq Select UserId, UserNumber FROM User where UserNumber
I'm trying to write a query for a database that will left join a
I am trying to write a query to select all records from users table
I am trying to write a query in SQLite.The application is like, when user
I'm trying to write a query that returns the most recent GPS positions from
I'm trying to write this query using Hibernate 3 and Oracle 10. from Alert
I'm trying to write query to a MYSQL database that queries for products that

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.