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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:08:31+00:00 2026-06-18T13:08:31+00:00

I’m creating an Android app which uses Microsoft Hawaii OCR; during the test of

  • 0

I’m creating an Android app which uses Microsoft Hawaii OCR; during the test of my app, it crashes giving me this error:

02-08 11:38:38.861: E/AndroidRuntime(4704): FATAL EXCEPTION: main
02-08 11:38:38.861: E/AndroidRuntime(4704): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mobile/com.example.mobile.RecognitionActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to microsoft.hawaii.sampleappbase.HawaiiBaseApplication
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.os.Looper.loop(Looper.java:137)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.ActivityThread.main(ActivityThread.java:4476)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at java.lang.reflect.Method.invokeNative(Native Method)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at java.lang.reflect.Method.invoke(Method.java:511)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at dalvik.system.NativeStart.main(Native Method)
02-08 11:38:38.861: E/AndroidRuntime(4704): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to microsoft.hawaii.sampleappbase.HawaiiBaseApplication
02-08 11:38:38.861: E/AndroidRuntime(4704):     at microsoft.hawaii.sampleappbase.HawaiiBaseAuthActivity.getBaseApplication(HawaiiBaseAuthActivity.java:204)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at microsoft.hawaii.sampleappbase.HawaiiBaseAuthActivity.getAuthenticationTypeFromApp(HawaiiBaseAuthActivity.java:117)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at microsoft.hawaii.sampleappbase.HawaiiBaseAuthActivity.onCreate(HawaiiBaseAuthActivity.java:52)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at com.example.mobile.RecognitionActivity.onCreate(RecognitionActivity.java:32)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.Activity.performCreate(Activity.java:4636)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)
02-08 11:38:38.861: E/AndroidRuntime(4704):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924)
02-08 11:38:38.861: E/AndroidRuntime(4704):     ... 11 more

The error refers to an imported project, in particular to this code:

package microsoft.hawaii.sampleappbase;

import microsoft.hawaii.hawaiiClientLibraryBase.Identities.ClientIdentity;
import microsoft.hawaii.hawaiiClientLibraryBase.Util.Utility;
import microsoft.hawaii.sampleappbase.HawaiiBaseApplication.AuthenticationType;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.widget.Toast;

/**
 * Base Activity for Hawaii authentication
 */
public class HawaiiBaseAuthActivity extends Activity {

/**
 * Error code for missing authentication type in configuration file
 */
static final int MISSING_NETWORK_CONNECTION = 0;

/**
 * Error code for missing authentication value in configuration file
 */
static final int MISSING_AUTHENTICATION_TYPE = 1;

/**
 * Error code for missing authentication value in configuration file
 */
static final int MISSING_AUTHENTICATION_VALUES = 2;

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

    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnected()) {
        this.showDialog(MISSING_NETWORK_CONNECTION);
        return;
    }

    if (!this.shouldAuthenticate()) {
        return;
    }

    AuthenticationType authType = this.getAuthenticationTypeFromApp();
    if (authType == AuthenticationType.NOVALUE) {
        this.showDialog(MISSING_AUTHENTICATION_TYPE);
        return;
    }

    // create ClientIdentity object based on configured Hawaii client
    // credential
    ClientIdentity identity = null;
    try {
        switch (authType) {
        case GUID:
            String appId = this.getString(R.string.hawaii_GUID_app_ID);
            if (Utility.isStringNullOrEmpty(appId)) {
                this.showDialog(MISSING_AUTHENTICATION_VALUES);
                return;
            }

            identity = ClientIdentity.createClientIdentity(appId);
            break;
        case ADM:
            String clientId = this.getString(R.string.hawaii_ADM_client_ID);
            String clientSecret = this
                    .getString(R.string.hawaii_ADM_client_secret);
            String serviceScope = this
                    .getString(R.string.hawaii_ADM_service_scope);

            if (Utility.isStringNullOrEmpty(clientId)
                    || Utility.isStringNullOrEmpty(clientSecret)
                    || Utility.isStringNullOrEmpty(serviceScope)) {
                this.showDialog(MISSING_AUTHENTICATION_VALUES);
                return;
            }
            identity = ClientIdentity.createClientIdentity(clientId,
                    clientSecret, serviceScope);
            break;
        case NOVALUE:
            this.showErrorMessage(
                    "Couldn't configure client identity for calling Hawaii service",
                    null);
            return;
        }
    } catch (Exception exception) {
        this.showErrorMessage(
                "Couldn't configure client identity for calling Hawaii service",
                exception);
    }

    if (identity != null) {
        this.getBaseApplication().setClientIdentity(identity);
    } else {
        this.showErrorMessage(
                "Couldn't configure client identity for calling Hawaii service",
                null);
    }
}

/**
 * 
 * getAuthenticationTypeFromApp Return authentication type which assigned by
 * application
 * 
 * @return AuthenticationType
 */
protected AuthenticationType getAuthenticationTypeFromApp() {
    return this.getBaseApplication().getAuthType();
}

/**
 * Return a flag to indicate whether current Activity needs authentication
 * 
 * @return boolean
 */
protected boolean shouldAuthenticate() {
    return true;
}

/**
 * show ErrorMessage using AlertDialog
 * 
 * @param title
 *            title to display on the dialog
 * @param exception
 *            exception to display on the dialog
 */
protected void showErrorMessage(String title, Throwable exception) {
    if (exception != null) {
        exception.printStackTrace();
        System.out.println(exception.toString());
    }

    AlertDialog dialog = dialogToShow(title, exception).create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();
}

/**
 * show ErrorMessage using AlertDialog
 * 
 * @param title
 *            title to display on the dialog
 * @param exception
 *            exception to display on the dialog
 */
protected void showErrorMessage(AlertDialog.Builder builder) {
    if (builder == null) {
        return;
    }

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();
}

/**
 * show specified message in toast
 * 
 * @param message
 *            specified message
 */
protected void showMessage(String message) {
    if (!Utility.isStringNullOrEmpty(message)) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }
}

/**
 * create a {@link AlertDialog.Builder} to show dialog
 * 
 * @param title
 *            title to display on the dialog
 * @param exception
 *            exception to display on the dialog
 * @return AlertDialog.Builder
 */
protected AlertDialog.Builder dialogToShow(String title, Throwable exception) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(title);
    if (exception != null) {
        builder.setMessage(exception.getLocalizedMessage());
    }

    builder.setCancelable(true);
    return builder;
}

/**
 * gets current {@link HawaiiBaseApplication} object
 * 
 * @return HawaiiBaseApplication
 */
protected HawaiiBaseApplication getBaseApplication() {
    return (HawaiiBaseApplication) this.getApplication();
}

@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle(getString(R.string.configuration_error_title));
    dialog.setCanceledOnTouchOutside(true);
    dialog.setCancelable(true);

    String errorMessage = this.getErrorMessage(id);
    dialog.setMessage(errorMessage);

    final Activity activity = this;
    dialog.setOnCancelListener(new OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            activity.finish();
        }
    });

    return dialog;
}

protected String getErrorMessage(int id) {
    switch (id) {
    case MISSING_NETWORK_CONNECTION:
        return getString(R.string.error_missing_network_connection);
    case MISSING_AUTHENTICATION_TYPE:
        return getString(R.string.error_missing_authentication_type);
    case MISSING_AUTHENTICATION_VALUES:
        return getString(R.string.error_missing_authentication_value);
    default:
        return null;
    }
}
}

This is the code of HawaiiBaseApplication

/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 */
package microsoft.hawaii.sampleappbase;

import microsoft.hawaii.hawaiiClientLibraryBase.Identities.ClientIdentity;
import android.app.Application;

/**
 * Base application class for Hawaii sample applications
 */
public class HawaiiBaseApplication extends Application {

/**
 * Hawaii authentication type
 */
private AuthenticationType authType;

/**
 * ClientIdentity object
 */
private ClientIdentity identity;

/**
 * Enum class to represent Hawaii authentication type
 */
public enum AuthenticationType {
    GUID, ADM, NOVALUE;

    /**
     * Convert to authentication type enum for specified String
     * 
     * @param str
     *            specified String
     * @return AuthenticationType
     */
    public static AuthenticationType convertToAuthType(String str) {
        try {
            return valueOf(str.toUpperCase());
        } catch (Exception ex) {
            return NOVALUE;
        }
    }
}

/**
 * Gets current authentication type
 * 
 * @return AuthenticationType
 */
public AuthenticationType getAuthType() {
    if (authType == null) {
        authType = AuthenticationType
                .convertToAuthType(getString(R.string.hawaii_authentication_type));
    }

    return authType;
}

/**
 * Gets current ClientIdentity object
 * 
 * @return ClientIdentity
 */
public ClientIdentity getClientIdentity() {
    return this.identity;
}

/**
 * Sets current ClientIdentity object
 * 
 * @param identity
 *            current ClientIdentity object
 */
public void setClientIdentity(ClientIdentity identity) {
    this.identity = identity;
}

}

May someone help me,please? I’m stuck in this point and i don’t know what is wrong with it..

Thank you so much!

  • 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-18T13:08:32+00:00Added an answer on June 18, 2026 at 1:08 pm

    Does your application element have an android:name="microsoft.hawaii.sampleappbase.HawaiiBaseApplication" attribute in your AndroidManifest.xml? That’s probably what’s missing.

    http://developer.android.com/guide/topics/manifest/application-element.html

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words

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.