Cannot cast class when using Google Analytics in Eclipse - android

I think I have all the elements right in my Eclipse projects but I still receive this error:
java.lang.ClassCastException: android.app.Application cannot be cast
to cam.main.AnalyticsApplication
Here's the AnalyticsApplication code:
package cam.main;
public class AnalyticsApplication extends Application {
private Tracker tracker;
public AnalyticsApplication() {
super();
}
synchronized public Tracker getDefaultTracker() {
if (tracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
tracker = analytics.newTracker(R.xml.analytics);
}
return tracker;
}
}
Here's the Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cam.main"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="6"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="#drawable/bot_img_1"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="cam.main.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<- other activities from the app ->
</application>
<application android:name="cam.main.AnalyticsApplication">
</application>
</manifest>
And I have this code on the OnCreate method of my starting activity (StartMenu)
AnalyticsApplication application = (AnalyticsApplication) getApplication();
Tracker mTracker = application.getDefaultTracker();
I don't know if it's important but I have AnalyticsApplication and StartMenu in the same file.
Is there a need to create an Activity inside the AnalyticsApplication or something?

Just include your android:name="cam.main.AnalyticsApplication" parameter to an exist application tag like this:
<application
android:name="cam.main.AnalyticsApplication"
android:icon="#drawable/bot_img_1"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity android:name="cam.main.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<- other activities from the app ->
</application>
Your custom Application class works incorrectly because of 2nd tag.

Related

Android&Quickblox (api 3.2): Subscribing to push notifications

I'm not able to subscribe to push notifications. I did:
1) I created a firebase application, with the same package name as my MainActivity package name;
2) I downloaded the google-service.json file and stored it in my /app/ next to the gradle file;
3) I added the C2D and WAKE-LOCK permissions as the google guide showed;
4) I added the API-KEY in the pushnotification's setting tab in quickblox admin panel;
5) I modified the manifest as showed by the quickblox guide;
6) I added a push-notification listener and a local broadcast receiver as shown by the same guide as above.
That's how my manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.unical.sistemidistribuiti.ddf.appraia">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:name="it.unical.sistemidistribuiti.ddf.appraia.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="it.unical.sistemidistribuiti.ddf.appraia.permission.C2D_MESSAGE"/>
<meta-data android:name="com.quickblox.messages.TYPE" android:value="FCM" />
<meta-data android:name="com.quickblox.messages.SENDER_ID" android:value="#string/sender_id" />
<meta-data android:name="com.quickblox.messages.QB_ENVIRONMENT" android:value="DEVELOPMENT" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:theme="#style/AppTheme"
android:name="it.unical.sistemidistribuiti.ddf.appraia.AppraiaApplication">
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.StartActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.NewsDetailActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.CreatePostActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<activity
android:name="it.unical.sistemidistribuiti.ddf.appraia.UserProfileActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service
android:name="com.quickblox.messages.services.fcm.QBFcmPushListenerService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
Since I'm using 3.2 sdk version, the app should automatically subscribe the user to push-notifications, but this not happen. Actually the listener code prints nothing:
//This is in AppraiaApplication extends Application
#Override
public void onCreate() {
super.onCreate();
QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
QBPushManager.getInstance().addListener(new QBPushManager.QBSubscribeListener() {
#Override
public void onSubscriptionCreated() {
System.out.println("onSubscriptionCreated");
}
#Override
public void onSubscriptionError(final Exception e, int resultCode) {
System.out.println("onSubscriptionError" + e);
if (resultCode >= 0) {
System.out.println("Google play service exception");
}
System.out.println("onSubscriptionError " + e.getMessage());
}
});
QBSettings.getInstance().setEnablePushNotification(true);
LocalBroadcastManager.getInstance(this).registerReceiver(pushBroadcastReceiver,
new IntentFilter("new-push-event"));
System.out.println("Application creation ended");
}
What am I doing wrong?
Looks like you don't make signIn with user, and subscription is not performed. Also have a look in logs, there is can be info something like D/QBASDK: SubscribeService: SubscribeService created. So, you can figure out whether the subscription is executed at all.

Fatal Exception applicationId is null Parse

This is my second question in SO, I have a problem about Fatal Main error. Before I ask it, I found some other problem in SO, but what I found is about Facebook app
This is my error
java.lang.RuntimeException: applicationId is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
But, I have a class that declared it
package com.example.michael.eksperimen6chatting;
import android.app.Application;
import com.parse.Parse;
/**
* Created by Michael on 03/12/2015.
*/
public class ChattApp extends Application
{
#Override
public void onCreate()
{
super.onCreate();
Parse.initialize(this, "urkcFwvUmgSYvuOFTInJmkA3iWv0ArV3XT128TNb", "WvBC0cnGXHkVhTBbkFwLyxGDRgqR6qC8ft7DIleT");
}
}
and this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.michael.eksperimen6chatting" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
</activity>
<activity android:name=".UserList"></activity>
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chat">
</activity>
</application>
</manifest>
Did I miss something here, can anyone help me? Gratia
Specifying ChattApp Application class name in your AndroidManifest.xml's <application> tag.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:name="com.example.michael.eksperimen6chatting.ChattApp">
....
</application>
import com.parse.Parse;
import android.app.Application;
public class ChattApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}
}
AndroidManifest.xml
<application
android:name="com.example.michael.eksperimen6chatting.ChattApp"
.
.
.
</application>

ACRA not sending to eMail

I am trying to send crash reports to email but when my app crashes nothing happens. I tried messing around with configurations but i just kept getting errors (unknown member mostly, wth that is). Here's my code for the class.
#ReportsCrashes(
mailTo = "me#gmail.com")
public class MyApplication extends Application
{
#Override
public void onCreate() {
super.onCreate();
// The following line triggers the initialization of ACRA
ACRA.init(this);
}
}
My manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ghostdevelopment.ueni2"
android:versionCode="1"
android:versionName="1.0"
android:debuggable="true">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="25" />
<application
android:name="MyApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:label="#string/app_name"
android:name="com.ghostdevelopment.ueni2.MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="Ship Database"
android:name=".ShipInfo" />
</application>
</manifest>
According to your logcat it appears that your app has not included the ACRA library. You need to configure your build so that ACRA is included in your APK.

Unable to connect android application to parse

I am trying to connect my android application to parse.com but I am stuck at last step.On Parse website it is mentioned Add the following to your ApplicationonCreate():
Parse.enableLocalDatastore(this);
Parse.initialize(this, "yDdwwIjw0jmTnTEAzc3CQaXXXXXXXXXXXX", "kljfnAt3XXXXXXXXXXXX");
I am unable to understand how and where to add this code.Please guide through the steps.
Create Application class inside main package
public class MyApplication extends Application{
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, getString(R.string.parse_app_id), getString(R.string.parse_client_key));
}
}
Add permissions to your Manifest file.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Create a class which extends the Application class
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, getString(R.string.parse_application_id), getString(R.string.parse_client_key));
}
}
Don't forget to add android:name=".MyApp" to the application in your Manifest file.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name=".MyApp" >
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Google Maps NoClassDefFoundError

I'm working on an android project in which one of the activities includes a Maps view. I'm only after doing the code for displaying a simple Google Map but I bumped into this NoClassDefFoundError. I have checked some similar questions and tried the suggested solutions but still won't work. I have activated the Internet permision in the manifest file and the user library for the application. Does anyone have any suggestions on what might be the problem? Here's the activity code:
package com.mad.mylit;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class LocationsActivity extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
And here's my manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mad.mylit"
android:versionCode="1"
android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".MyLitActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MapsActivity"></activity>
<activity android:name=".MyProfileActivity"></activity>
<activity android:name=".BusActivity"></activity>
<activity android:name=".EventsActivity"></activity>
<activity android:name=".LocationsActivity"></activity>
<activity android:name=".NotesActivity"></activity>
<activity android:name=".TimetableActivity"></activity>
<activity android:name=".MondayActivity"></activity>
<activity android:name=".TuesdayActivity"></activity>
<activity android:name=".WednesdayActivity"></activity>
<activity android:name=".ThursdayActivity"></activity>
<activity android:name=".FridayActivity"></activity>
<activity android:name=".CaherdavinActivity"></activity>
<activity android:name=".RaheenActivity"></activity>
<activity android:name=".UniversityActivity"></activity>
<activity android:name=".SplashScreen"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
All of the activities are in the same package.
Try to get new maps API key with your personal keystore.
Have you recently updated your ADT plugin?
Here and here are some talks about same prblem..

Categories

Resources