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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:59:26+00:00 2026-06-08T06:59:26+00:00

Im trying to create a basic AsyncTask to get a certificate from the key

  • 0

Im trying to create a basic AsyncTask to get a certificate from the key store.

for some reason even the most simple AsyncTask doesnt work for me, i keep getting an error about ExceptionInIntilizationError.

This is the test code im using to just get a basic asynctask working:

public class Authenticator extends Activity {

PrivateKey privateKey = null;
String SavedAlias = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getCertificates("TEST");

    doSomething();

}

public void doSomething()
{
    new additionalStuff().execute();
}

public class AliasLoader extends AsyncTask<Void, Void, X509Certificate[]> 
{
    X509Certificate[] chain = null;

    @Override protected X509Certificate[] doInBackground(Void... params) {
        android.os.Debug.waitForDebugger();

        if(!SavedAlias.isEmpty())
        {
                try {
                    chain = KeyChain.getCertificateChain(getApplicationContext(),SavedAlias);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                }
        }
        else
        {
            this.cancel(true);
        }

        return chain;
    }
    @Override protected void onPostExecute(X509Certificate[] chain) 
    {
        try {
            privateKey = KeyChain.getPrivateKey(getApplicationContext(), SavedAlias);
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
        }

        if (privateKey != null) {
            Signature signature = null;
            try {
                signature = Signature.getInstance("SHA1withRSA");
            } catch (NoSuchAlgorithmException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
            try {
                signature.initSign(privateKey);
            } catch (InvalidKeyException e) {
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    }
}

public void getCertificates(String Host)
{
    KeyChainAliasCallback callBack = new KeyChainAliasCallback() {

        @Override
        public void alias(String alias) {
            if (alias != null) 
            {
                saveAlias(alias);
                //doSomething();
            }
        }
    };

    KeyChain.choosePrivateKeyAlias(this, callBack,
    new String[] {"RSA", "DSA"}, // List of acceptable key types. null for any
    null,                        // issuer, null for any
    null,      // host name of server requesting the cert, null if unavailable
    443,                         // port of server requesting the cert, -1 if unavailable
    null);                       // alias to preselect, null if unavailable

}

public void saveAlias(String alias)
{
    SavedAlias = alias;
}

public class additionalStuff extends AsyncTask<String, String, Void>
{
    String test = "This is a Test!!!";

    @Override
    protected void onPreExecute() 
    {
    }
    @Override
    protected Void doInBackground(String... params) {
        return null;
    }

    @Override
    protected void onProgressUpdate(String... values) 
    {
            super.onProgressUpdate(values);
    }
    @Override
    protected void onPostExecute(Void unused) 
    {
        Log.d("DEEPAM", "THIS IS A TEST");
        return;
    }

}
}

Why does this fail? =(

** UPDATE **
I made the changes to add the @Override on the postexcecution and the parameters Void Void and it still comes up with the same ExceptionInInitilizationError =(

** UPDADE **

Im guessing i cannot create a new thread using Asynctask in the UI, which is probably why it was failing before, is there anyway i can get the AsyncTask to be called once the user has selected a certificate?

  • 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-08T06:59:28+00:00Added an answer on June 8, 2026 at 6:59 am

    I Figured out the problem, whatappserv, Vladimir and n_benbourahla mentioned probably would have been problems later on once my initial mistake had been fixed.

    essentially i forgot to add in a bit of code that is using the execution.
    I am calling the doSomething.execute() in the callback of a KeyChain.choosePrivateKeyAlias.

    which it looks like putting it outside that and the asynctask works fine.

    I still have the problem of how can i call the asynctask inside the callback from the keychain.choosePrivateAlias as it is essential that it is only run once that has executed. I will update the code with what i now have.

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

Sidebar

Related Questions

I'm trying to create a basic database trigger that conditionally deletes rows from database1.table1
I'm trying to create a reusable component to display some photo collection. The basic
I'm trying to create a simple visual basic 6 program/database that uses ms access
I'm trying to create a basic version of this example in CoffeeScript: http://davidsulc.com/blog/2012/04/15/a-simple-backbone-marionette-tutorial/ .
Simple question. I am trying to create a basic lambda expression that returns the
I'm trying to create some sort of many-to-one association. The basic premise is a
I am trying to create a Basic Form from an existing markup. I did
I'm trying to implement the WMD editor used on StackOverflow to create some basic
I am trying to create a basic WPF application that can store an encrypted
I am trying to create some basic button rollover functionality using Jquery and toggleClass.

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.