Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointer exception on beginChat #2

Closed
omaroskars opened this issue Aug 27, 2020 · 11 comments
Closed

NullPointer exception on beginChat #2

omaroskars opened this issue Aug 27, 2020 · 11 comments
Assignees

Comments

@omaroskars
Copy link

omaroskars commented Aug 27, 2020

Followed the installation for Android. When i try to start the chat I get a nullpointer exception.

<activity android:name="com.livechatinc.inappchat.ChatWindowActivity" android:configChanges="orientation|screenSize" /> Is in the manifest

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
E/MethodChannel#livechat( 7569): 	at android.content.ComponentName.<init>(ComponentName.java:131)
E/MethodChannel#livechat( 7569): 	at android.content.Intent.<init>(Intent.java:6510)
E/MethodChannel#livechat( 7569): 	at tech.mastersam.livechat.LivechatPlugin.onMethodCall(LivechatPlugin.java:82)
E/MethodChannel#livechat( 7569): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
E/MethodChannel#livechat( 7569): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#livechat( 7569): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/MethodChannel#livechat( 7569): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#livechat( 7569): 	at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#livechat( 7569): 	at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#livechat( 7569): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#livechat( 7569): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#livechat( 7569): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#livechat( 7569): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/flutter ( 7569): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference, null) 
@Mastersam07
Copy link
Owner

Have you added:
<activity android:name="com.livechatinc.inappchat.ChatWindowActivity" android:configChanges="orientation|screenSize" />

in your android manifest?

@Mastersam07 Mastersam07 self-assigned this Aug 27, 2020
@omaroskars
Copy link
Author

@Mastersam07 Yes, The activity is in the manifest.

@omaroskars
Copy link
Author

When I open the app in Intelli J, The manifest doesn't recognize ChatWindow activity for some reason. Do I need to install LiveChat in android Gradle?

@Mastersam07
Copy link
Owner

Can I have a minimum reproducible project?

@Mastersam07
Copy link
Owner

Where exactly in your manifest are you adding this?

<activity android:name="com.livechatinc.inappchat.ChatWindowActivity" android:configChanges="orientation|screenSize" />

@Mastersam07
Copy link
Owner

@omaroskars can you check the manifest in the example and confirm with what you have?

@omaroskars
Copy link
Author

omaroskars commented Aug 27, 2020

The thing is it works on a minimum reproducible project, but when i add it to my enterprise app it seems the activity doesn't get initalized for some reason. This has probably something to do with my project but i was hoping you could help me figure it out.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="MY_PROJECT">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
    <!-- Access to biometrics-->
    <uses-permission android:name="android.permission.USE_FINGERPRINT"/>
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            
            <!-- Notification for onResume and onLaunch-->
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter> 
        </activity>
        <activity android:name="com.livechatinc.inappchat.ChatWindowActivity" android:configChanges="orientation|screenSize" />
    </application>
</manifest>

@Mastersam07
Copy link
Owner

What plugin version are you using?

@Mastersam07
Copy link
Owner

Can I also get a reproducible project?

@Mastersam07
Copy link
Owner

I just tried replicating with livechat version livechat: ^1.0.0+1 and I didn't encounter issues.

@omaroskars
Copy link
Author

I think your plugin works as expected. The problem is probably with cached dependencies in my project, because I implemented the live chat plugin natively to begin with. I changed my native code to run "intent" like in this plugin does and everything works as expected.

Thanks a lot for your help

@zjoart zjoart mentioned this issue Sep 10, 2020
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants