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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:46:23+00:00 2026-05-24T16:46:23+00:00

I am trying to to AsyncTask to install a fairly large database using this

  • 0

I am trying to to AsyncTask to install a fairly large database using this code:

package samples.employeedirectory;


import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListAdapter;
import android.widget.ListView;

public class EmployeeList extends ListActivity {

    protected SQLiteDatabase db;
    protected Cursor cursor;
    protected ListAdapter adapter;
    protected Context context;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        grabURL();

    }

    public void grabURL() {
        new GrabURL().execute();
    }

    public void onListItemClick(ListView parent, View view, int position, long id) {
        Intent intent = new Intent(this, displayE.class);
        Cursor cursor = (Cursor) adapter.getItem(position);
        intent.putExtra("eID", cursor.getInt(cursor.getColumnIndex("eID")));
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.pref:
                // Launch Preference activity
                Intent intent = new Intent(this, Preferences.class);
                startActivity(intent);
             break;
        }
        return true;
    }


    private class GrabURL extends AsyncTask<Object, Void, Void> {
        private ProgressDialog Dialog = new ProgressDialog(EmployeeList.this);

        protected void onPreExecute() {
            Dialog.setMessage("Downloading source..");
            Dialog.show();
        }

        protected Void doInBackground(Object ... string) {
            db = (new DatabaseHelper(EmployeeList.this)).getWritableDatabase();
            cursor = db.rawQuery("SELECT * FROM employee", new String[]{});

            return null;
        }

        protected void onPostExecute(Void unused) {
            adapter = new qCursorAdapter(EmployeeList.this, cursor);
            Dialog.dismiss();
            setListAdapter(adapter);

    }
    }
}

This is the main activity for the app and the issue is that every time I run for the first time the app crashes. I am not sure why, but this is the message that I get.

 08-16 01:07:27.783: ERROR/WindowManager(8908): android.view.WindowLeaked: Activity samples.employeedirectory.EmployeeList has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2afd0298 that was originally added here

There are number of topics on SO discussing this error but I could not exactly understand how they are related to this particular case.

EDIT:

08-16 01:24:31.073: ERROR/AndroidRuntime(8995): FATAL EXCEPTION: AsyncTask #1
08-16 01:24:31.073: ERROR/AndroidRuntime(8995): java.lang.RuntimeException: An error occured while executing doInBackground()
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.lang.Thread.run(Thread.java:1019)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.os.Handler.<init>(Handler.java:121)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.widget.Toast.<init>(Toast.java:68)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.widget.Toast.makeText(Toast.java:231)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at samples.employeedirectory.DatabaseHelper.onCreate(DatabaseHelper.java:42)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at samples.employeedirectory.EmployeeList$GrabURL.doInBackground(EmployeeList.java:79)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at samples.employeedirectory.EmployeeList$GrabURL.doInBackground(EmployeeList.java:1)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     ... 4 more
08-16 01:24:31.083: ERROR/WindowManager(8995): Activity samples.employeedirectory.EmployeeList has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2afd1760 that was originally added here
08-16 01:24:31.083: ERROR/WindowManager(8995): android.view.WindowLeaked: Activity samples.employeedirectory.EmployeeList has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2afd1760 that was originally added here
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.view.ViewRoot.<init>(ViewRoot.java:265)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.Dialog.show(Dialog.java:241)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at samples.employeedirectory.EmployeeList$GrabURL.onPreExecute(EmployeeList.java:75)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.os.AsyncTask.execute(AsyncTask.java:391)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at samples.employeedirectory.EmployeeList.grabURL(EmployeeList.java:40)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at samples.employeedirectory.EmployeeList.onCreate(EmployeeList.java:30)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.os.Looper.loop(Looper.java:123)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at android.app.ActivityThread.main(ActivityThread.java:3701)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at java.lang.reflect.Method.invokeNative(Native Method)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at java.lang.reflect.Method.invoke(Method.java:507)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
08-16 01:24:31.083: ERROR/WindowManager(8995):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
08-16 01:24:31.083: ERROR/WindowManager(8995):     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-24T16:46:25+00:00Added an answer on May 24, 2026 at 4:46 pm

    The issue is in the onCreate method of your DatabaseHelper where you are attempting to display a Toast outside of the UI thread (it is being executed within doInBackground).

    You can spot this here:

    08-16 01:24:31.073: ERROR/AndroidRuntime(8995): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.os.Handler.<init>(Handler.java:121)
    08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.widget.Toast.<init>(Toast.java:68)
    08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at android.widget.Toast.makeText(Toast.java:231)
    08-16 01:24:31.073: ERROR/AndroidRuntime(8995):     at samples.employeedirectory.DatabaseHelper.onCreate(DatabaseHelper.java:42)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and
I have a listview which is filled by AsyncTask and I am trying to
I'm trying to make a utility httpClient class My code works great the first
Trying to squeeze in a fairly new gem, and its causing me to stumble
Trying to use this following script to load a page so that I can
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to make a make generic select control that I can dynamically add elements

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.