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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:58:54+00:00 2026-05-25T01:58:54+00:00

I am trying to query my database and sort my start column in descending

  • 0

I am trying to query my database and sort my start column in descending order then get the first row.

public Cursor getLowestEvent(){
    String sort = "SELECT * FROM " + EVENTS_TABLE + " ORDER_BY " + START + " DESC";

    Cursor c = db.query(EVENTS_TABLE, new String[] {ID,START},null,null,null,null,sort); //error
    if(c != null){
        c.moveToFirst();
    }
    return c;
}

doing this gives me a null pointer exception and I dont know why, there are items in the database so it has to be a problem with my sort?

08-25 11:03:14.503: ERROR/AndroidRuntime(2367): java.lang.NullPointerException
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at com.app.notifyme.CalendarDB.getLowestEvent(CalendarDB.java:106)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at com.app.notifyme.Calendar$5.onClick(Calendar.java:162)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.widget.ListView.performItemClick(ListView.java:3513)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.os.Handler.handleCallback(Handler.java:587)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.os.Looper.loop(Looper.java:123)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at android.app.ActivityThread.main(ActivityThread.java:3839)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at java.lang.reflect.Method.invokeNative(Native Method)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at java.lang.reflect.Method.invoke(Method.java:507)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-25 11:03:14.503: ERROR/AndroidRuntime(2367):     at dalvik.system.NativeStart.main(Native Method)
  • 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-25T01:58:55+00:00Added an answer on May 25, 2026 at 1:58 am

    Please see this link. Your last parameter (order by) is not supposed to be an ENTIRE sql statement (SELECT * FROM …). It is supposed to be formatted as a SQL ORDER BY clause. Since it says exclude the ORDER BY itself, I think it would just be the column you want to order by and the identifier to determine which way to order (“ID DESC”).

    How to order the rows, formatted as an SQL ORDER BY clause (excluding
    the ORDER BY itself). Passing null will use the default sort order,
    which may be unordered.

    The way you are building your query (in the string “sort”), you could also execute db.rawQuery.

    EDIT: What resolved the issue was adding db.open() before the db.query() call.

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

Sidebar

Related Questions

I am trying to sort order-entries by their status, however in my database there
I'm trying to query a database view that's not located on the same server
I'm trying to query a MySQL database using an array but I'm having trouble!
I am trying to reconstruct a database query I created for MySQL in Microsoft
I have a Microsoft Access database query that I'm trying to import into a
I'm trying to learn LINQ to SQL and I'm able to query the database
I'm currently trying to run a LINQ query over a MS SQL database. This
I'm trying to create a simple database table using the PHP MySQL query Create
I'm trying to get the output of the query 'SHOW TABLES FROM database_name' into
i'm trying to get a query that returns rows only with a specified name,

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.