OTP Android

54 views
Skip to first unread message

Federico Olivares

unread,
Aug 7, 2014, 3:37:05 PM8/7/14
to opentripp...@googlegroups.com
Hi!
I'm trying to
embed android otp app in my android app but i get this error when i run it:

Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to my.package.OTPApp
08-07 21:34:40.597: E/AndroidRuntime(23110):     at my.package.fragments.MainFragment.onActivityCreated(MainFragment.java:545)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1508)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.app.Activity.performStart(Activity.java:5241)
08-07 21:34:40.597: E/AndroidRuntime(23110):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
08-07 21:34:40.597: E/AndroidRuntime(23110):     ... 11 more

Can someone help me?

Thanks

Federico

Sean Barbeau

unread,
Aug 8, 2014, 11:15:15 AM8/8/14
to opentripp...@googlegroups.com
Federico,
I'm assuming this code is throwing the exception:
   
    mOTPApp = ((OTPApp) getActivity().getApplication());

Did you modify the OTPApp class at all?

OTPApp class must extend android.app.Application for the cast to succeed.

Thanks,
Sean

Federico Olivares

unread,
Aug 8, 2014, 11:32:01 AM8/8/14
to opentripp...@googlegroups.com
Thanks for the reply!
Yes, the problem is that the class OTPApp already extends Application.

Thanks,

Federico

Sean Barbeau

unread,
Aug 8, 2014, 2:15:29 PM8/8/14
to opentripp...@googlegroups.com
Federico,
Check your AndroidManifest.xml for your project.  You’ll need something that looks like this:

<application
            android:name=".OTPApp"
            android:icon="@drawable/ic_launcher"
           android:label="@string/app_name"
            android:allowBackup="true">

With the “.” notation, the application android:name attribute assumes that the OTPApp class is in the package defined by the “package” attribute at the top of your manifest (package="edu.usf.cutr.opentripplanner.android", for main OTP project).

For example, if your main application package is “my.package”, then OTPApp.java must be in “main/java/my/package” directory in the project. 

Alternately, you can fully qualify the package in the manifest.  For example, if OTPApp is in “my.package.otherpackage”, your manifest would look like:

<application
            android:name="my.package.otherpackage.OTPApp"
            android:icon="@drawable/ic_launcher"
           android:label="@string/app_name"
            android:allowBackup="true">

If you can share how you’re using OTP Android, we’d be interested in hearing it!

Sean
Reply all
Reply to author
Forward
0 new messages