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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:13+00:00 2026-05-30T17:25:13+00:00

Query: public List<Pontos> selectSpecific(String id) { List<Pontos> list = new ArrayList<Pontos>(); Cursor cursor =

  • 0

Query:

public List<Pontos> selectSpecific(String id) {
   List<Pontos> list = new ArrayList<Pontos>();
   Cursor cursor = this.db.query(TABLE_NAME, new String[] { "id", "name" },
           "id"+" = ?", new String[] { id }, null, null, null);
   if (cursor == null) {
          return list;
      }
   if (cursor.moveToFirst()) {
       do {
           Pontos p = new Pontos();
           p.id = cursor.getLong(0);
           p.name = cursor.getString(1);
           list.add(p); 
       } while (cursor.moveToNext());
  }
  if (cursor != null && !cursor.isClosed()) {
     cursor.close();
  }
   return list;

}

Fetching the result:

public class Showplace extends Activity {

   private String id;
   DataHelper dh = new DataHelper(Showplace.this);
   TextView txtTitle = null;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.showplace);

       Bundle extras = getIntent().getExtras();
       id = Integer.toString(extras.getInt("id"));
       txtTitle = (TextView) findViewById(R.id.txtTitle);
       List<Pontos> list = this.dh.selectSpecific(id);
       for(Pontos p : list){
           txtTitle.setText(p.getName().toString());
       }
   }

}

It’s giving me an NPE, I think that’s in this line:

Cursor cursor = this.db.query(TABLE_NAME, new String[] { "id", "name" },
       "id"+" = ?", new String[] { id }, null, null, null);

I tried various ways of doing this, searched a lot over StackOverflow and I can’t seem to find a solution to this.

Edit:

LogCat:

03-02 10:22:09.244: E/AndroidRuntime(341): Uncaught handler: thread main exiting due to uncaught exception
03-02 10:22:09.304: E/AndroidRuntime(341): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dotpro.android.bikevento/com.dotpro.android.bikevento.Showplace}: java.lang.NullPointerException
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.ActivityThread.access$2100(ActivityThread.java:116)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.os.Looper.loop(Looper.java:123)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.ActivityThread.main(ActivityThread.java:4203)
03-02 10:22:09.304: E/AndroidRuntime(341):  at java.lang.reflect.Method.invokeNative(Native Method)
03-02 10:22:09.304: E/AndroidRuntime(341):  at java.lang.reflect.Method.invoke(Method.java:521)
03-02 10:22:09.304: E/AndroidRuntime(341):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-02 10:22:09.304: E/AndroidRuntime(341):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
03-02 10:22:09.304: E/AndroidRuntime(341):  at dalvik.system.NativeStart.main(Native Method)
03-02 10:22:09.304: E/AndroidRuntime(341): Caused by: java.lang.NullPointerException
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
03-02 10:22:09.304: E/AndroidRuntime(341):  at com.dotpro.android.bikevento.DataHelper.<init>(DataHelper.java:28)
03-02 10:22:09.304: E/AndroidRuntime(341):  at com.dotpro.android.bikevento.Showplace.<init>(Showplace.java:14)
03-02 10:22:09.304: E/AndroidRuntime(341):  at java.lang.Class.newInstanceImpl(Native Method)
03-02 10:22:09.304: E/AndroidRuntime(341):  at java.lang.Class.newInstance(Class.java:1472)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
03-02 10:22:09.304: E/AndroidRuntime(341):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
03-02 10:22:09.304: E/AndroidRuntime(341):  ... 11 more
  • 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-30T17:25:15+00:00Added an answer on May 30, 2026 at 5:25 pm

    this line is wrong:
    DataHelper dh = new DataHelper(Showplace.this);

    you should move dh = new DataHelper(Showplace.this); to onCreate method

    Edit:

    why?
    because if you initialize field dh as you do Activity is not fully created and the context is not valid

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

Sidebar

Related Questions

How to expand this query: public Dictionary<int, List<TasksInDeal>> FindAllCreatedTasks() { return (from taskInDeal in
How to write this linq query using Lambda expression public List<Employee> GetList() { return
I have this public List<TableA> GetRecords(List<string> keys) { const string query = FROM TableA
my code : public List<tblBook> GetBook(string NameField, string Value) { return (this.Entities.Book.Where( it.@p0 NOT
public static IQueryable<TResult> ApplySortFilter<T, TResult>(this IQueryable<T> query, string columnName) where T : EntityObject {
I have something like this: class Movie { public string Title; public List<string> Genres
public List findCatalog() { Query query = getEntityManager().createQuery(SELECT pc.productCatalog, p.name, p.product FROM ProductCatalog pc
I'm using linq-to-sql for a query like this: public static List<MyModel> GetData(int TheUserID, DateTime
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)

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.