chat-sdk-android icon indicating copy to clipboard operation
chat-sdk-android copied to clipboard

help with chat skd set up, null error on Configuration.java of chat_sdk_core

Open lHernan opened this issue 9 years ago • 7 comments

I followed the steps on readme, i configure using android manifest and but when i try to run the app this error is thrown

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.hernan.ingeviajes, PID: 24615 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hernan.ingeviajes/com.hernan.ingeviajes.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at co.chatsdk.core.session.Configuration$Builder.firebase(Configuration.java:163) at co.chatsdk.core.session.Configuration$Builder.configureFromManifest(Configuration.java:371) at co.chatsdk.core.session.Configuration$Builder.<init>(Configuration.java:121) at com.hernan.ingeviajes.MainActivity.onCreate(MainActivity.java:27) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)  E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hernan.ingeviajes/com.hernan.ingeviajes.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at co.chatsdk.core.session.Configuration$Builder.firebase(Configuration.java:163) at co.chatsdk.core.session.Configuration$Builder.configureFromManifest(Configuration.java:371) at co.chatsdk.core.session.Configuration$Builder.<init>(Configuration.java:121) at com.hernan.ingeviajes.MainActivity.onCreate(MainActivity.java:27) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

when i debug, on this method

public Builder firebase (String url, String rootPath, String storageUrl, String cloudMessagingServerKey) {
            if(!url.substring(url.length() - 1).equals('/')) {
                url += "/";
            }
            if(!rootPath.substring(rootPath.length() - 1).equals('/')) {
                rootPath += "/";
            }
            config.firebaseUrl = url;
            config.firebaseRootPath = rootPath;
            config.firebaseStorageUrl = storageUrl;
            config.firebaseCloudMessagingServerKey = cloudMessagingServerKey;
            return this;
        }

the url and other parameters are null but i don't know why, im new at android development, any help please? also the facebook app id is correct on my firebase console but an error is thrown:

A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.

This is my manifest file:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hernan.ingeviajes">
    <meta-data android:name="firebase_url" android:value="@string/firebase_url" />
    <meta-data android:name="firebase_root_path" android:value="@string/firebase_root_path" />
    <meta-data android:name="firebase_storage_url" android:value="@string/firebase_storage_url" />
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_api_key"/>
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
    <meta-data android:name="cloud_messaging_server_key" android:value="@string/firebase_cloud_messaging_server_key" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
       >
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="co.chatsdk.ui.login.LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

lHernan avatar Nov 03 '17 21:11 lHernan

I am facing the same issue even though I believed I have followed the set up correctly

SimpleAesthetics avatar Nov 04 '17 16:11 SimpleAesthetics

Mine works but I put those at the bottom and inside the tag. It can't recognize them when they are outside the tag. The facebook instructions for their SDK is unclear about this as well - it actually says to put it after the application tag which is incorrect.

StevenWoo avatar Nov 05 '17 09:11 StevenWoo

Do you mind explaining that a little or showing a screenshot. What tag did you put it inside

SimpleAesthetics avatar Nov 05 '17 17:11 SimpleAesthetics

Sorry, this commenting system strips out xml tags.

"<"application ">" meta tags must go here "</"application">"

NOT meta tags "<"application ">" "</"application">"

When you do the latter, the compile does not complain but you get the run time exception. The facebook SDK instructions actually tell you to do the wrong thing by putting the meta tags after the application but it must be inside.

StevenWoo avatar Nov 05 '17 21:11 StevenWoo

Thanks Steven, it works but now i have the following error:

11-05 16:24:54.031 5851-5851/com.hernan.ingeviajes E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: com.hernan.ingeviajes, PID: 5851
                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hernan.ingeviajes/co.chatsdk.ui.login.LoginActivity}: java.lang.NullPointerException: Attempt to read from field 'co.chatsdk.core.handlers.AuthenticationHandler co.chatsdk.core.base.BaseNetworkAdapter.auth' on a null object reference
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                         at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                         at android.os.Looper.loop(Looper.java:164)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                      Caused by: java.lang.NullPointerException: Attempt to read from field 'co.chatsdk.core.handlers.AuthenticationHandler co.chatsdk.core.base.BaseNetworkAdapter.auth' on a null object reference
                                                                         at co.chatsdk.core.session.NM.auth(NM.java:37)
                                                                         at co.chatsdk.ui.login.LoginActivity.initViews(LoginActivity.java:99)
                                                                         at co.chatsdk.ui.login.LoginActivity.onCreate(LoginActivity.java:76)
                                                                         at android.app.Activity.performCreate(Activity.java:6975)
                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                         at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                         at android.os.Looper.loop(Looper.java:164) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
11-05 16:24:54.032 5851-5851/com.hernan.ingeviajes E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hernan.ingeviajes/co.chatsdk.ui.login.LoginActivity}: java.lang.NullPointerException: Attempt to read from field 'co.chatsdk.core.handlers.AuthenticationHandler co.chatsdk.core.base.BaseNetworkAdapter.auth' on a null object reference
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                            at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                            at android.os.Looper.loop(Looper.java:164)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                         Caused by: java.lang.NullPointerException: Attempt to read from field 'co.chatsdk.core.handlers.AuthenticationHandler co.chatsdk.core.base.BaseNetworkAdapter.auth' on a null object reference
                                                                            at co.chatsdk.core.session.NM.auth(NM.java:37)
                                                                            at co.chatsdk.ui.login.LoginActivity.initViews(LoginActivity.java:99)
                                                                            at co.chatsdk.ui.login.LoginActivity.onCreate(LoginActivity.java:76)
                                                                            at android.app.Activity.performCreate(Activity.java:6975)
                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                            at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                            at android.os.Looper.loop(Looper.java:164) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

i guess is something about facebook login is wrong, but i disabled that option on my main activity.

        builder.facebookLoginEnabled(false);
        builder.twitterLoginEnabled(false);

Still get the same error, any suggestion?

lHernan avatar Nov 05 '17 21:11 lHernan

I think this is a problem with your setup code. I think the network adapter is null. You need something like:

Context context = getApplicationContext();
Configuration.Builder builder = new Configuration.Builder(context);
ChatSDK.initialize(builder.build());
UserInterfaceModule.activate(context);
FirebaseModule.activate(context);
FirebaseFileStorageModule.activate();

In your app start method.

bensmiley avatar Nov 09 '17 17:11 bensmiley

The problem is that your setup code isn't being called. You need to add this code to either your main activity (if you call a different activity before starting the Chat SDK) or in your Application onCreate method.

If you don't have that method you can create it by making a new class that inherits from Application.

public class MainApp extends Application {

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

        Context context = getApplicationContext();

        Configuration.Builder builder = new Configuration.Builder(context);

        // Initialize the Chat SDK
        ChatSDK.initialize(builder.build());

        UserInterfaceModule.activate(context);
        FirebaseModule.activate();
        FirebaseFileStorageModule.activate();

    }
}

Then registering this class in the AndroidManifest.xml file by adding the android:name attribute to the application tag:

android:name=".MainApp"

bensmiley avatar Nov 13 '17 17:11 bensmiley