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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:55:43+00:00 2026-06-02T00:55:43+00:00

Method causing error inside my ContentProvider public static Cursor getSuggestions(String query) { SQLiteDatabase db

  • 0

Method causing error inside my ContentProvider

public static Cursor getSuggestions(String query) {
    SQLiteDatabase db = dbHelper.getReadableDatabase();
    db.beginTransaction();
    try {
        String selection = Formula.FORMULA_NAME + " LIKE %?%";
        String[] selectionArgs = { query + "*" };
        Cursor cursor = dbHelper.getReadableDatabase().query(
                FORMULA_TABLE_NAME,
                new String[] { BaseColumns._ID,
                        SearchManager.SUGGEST_COLUMN_TEXT_1, 
                        BaseColumns._ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID 
                        }, 
                        selection,
                selectionArgs, null, null, null);
        db.setTransactionSuccessful();
        return cursor;
    } catch (SQLiteException e) {
    } finally {
        db.endTransaction();
    }
    throw new SQLException("Failed to begin transaction");
}

Database creation:

db.execSQL("CREATE TABLE " + FORMULA_TABLE_NAME + " (" +
                BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                SearchManager.SUGGEST_COLUMN_TEXT_1 + " TEXT," +
                Formula.CATEGORY + " TEXT" +
                ");");

Constants used:

    public static final String FORMULA_NAME = SearchManager.SUGGEST_COLUMN_TEXT_1;
    public static final String CATEGORY = "category";

The problem is that in my method, the transaction is unsuccessful because it throws the error: throw new SQLException("Failed to begin transaction"); What I’m trying to do is to search through the database as part of a search. When the user activates the search box, then I have it set up so that this method should be returning a cursor with the suspected items based on their name. Through debugging, I deduced that the problem was with the method of search inside my Content Provider. Any solutions or thoughts?

  • 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-02T00:55:45+00:00Added an answer on June 2, 2026 at 12:55 am

    I’m guessing the line throw new SQLException("Failed to begin transaction"); is meant to be inside your catch block.

    What if we simplify everything to:

    public static Cursor getSuggestions(String query) {
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        String selection = Formula.FORMULA_NAME + " LIKE %?%";
        String[] selectionArgs = { query + "*" };
        Cursor cursor = db.query(
                FORMULA_TABLE_NAME,
                new String[] { BaseColumns._ID,
                        SearchManager.SUGGEST_COLUMN_TEXT_1, 
                        BaseColumns._ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID 
                        }, 
                selection,
                selectionArgs, null, null, null);
        return cursor;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The method signature of a Java main method is: public static void main(String[] args)
I have the following method in some nemerle code: private static getLinks(text : string)
This relates to my previous post: jQuery .load Method causing page refresh AJAX I
Every method I write to encode a string in Java using 3DES can't be
What are the best strategies for finding that missing semicolon that's causing the error?
Following methods gets called from didFinishLaunchingWithOptions,when I run on Instruments openDatabase method causing leaks..
What is causing this error? I believe it is an incorrect accept header. Shouldn't
getting error 1061: Call to a possibly undefined method stop through a reference with
Method chaining is the only way I know to build fluent interfaces. Here's an
Method chaining is the practice of object methods returning the object itself in order

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.