GMaxera / QtFacebook

Code for use Facebook SDK from C++ and Qt Quick 2 in Qt 5 projects targeted on mobile devices (Android & iOS)
49 stars 21 forks source link

NullPointerException when creating a session #11

Open bbernhard opened 8 years ago

bbernhard commented 8 years ago

Hi,

first of all, thanks for the great project! I am really looking forward to integrating QtFacebook into my application. I just tried to add QtFacebook to my Qt 5.6 (Android) application, but unfortunately when I run the following small sample program...

import QtQuick 2.6
import QtQuick.Window 2.2
import org.qtproject.example 1.0

Window {
    visible: true

    MouseArea {
        anchors.fill: parent
        onClicked: {
            console.log("login");
            Facebook.login()
        }
    }
}

...I get the following NullPointerException:

D/libqtfacebook_test.so(16218): qrc:/main.qml:19 (onClicked): qml: login
I/QFacebook(16218): Facebook Creating a new Session
W/System.err(16218): java.lang.NullPointerException
W/System.err(16218):    at org.gmaxera.qtfacebook.QFacebookBinding.createSessionIfNeeded(QFacebookBinding.java:123)
W/System.err(16218):    at org.gmaxera.qtfacebook.QFacebookBinding.login(QFacebookBinding.java:132)
W/System.err(16218):    at dalvik.system.NativeStart.run(Native Method) 

Do you have an idea what could be the reason for the NullPointerException? I tried to do all the things you described in the Readme file.

Thanks for your time!

Kind Regards Bernhard

GMaxera commented 8 years ago

It seems to me that the method QFacebookBinding.onCreate(this, bundle); has not been called during the creation of the app.

Did you created a custom Android Activity as described into the readme ? And are you sure that the app has been created using your custom Android Activity ?

Could you post me the Android Activity source code and the AndroidManifest.xml are you using ?

bbernhard commented 8 years ago

Hi,

thanks for the quick reply! I did create the custom activitiy and also added the activity to the AndroidManifest.xml file, as described in the readme file. However, I am relatively new to the android stuff, so maybe I misunderstood something.

The AndroidManifest.xml and my custom activity are attached. I renamed both files to .txt, as github doesn't support those filetypes (I also added a .zip file with the files and their original file ending, in case renaming the files to *.txt messes up the formatting). MyCustomAppActivity.txt AndroidManifest.txt

qtfacebook_issue.zip

Thanks again for helping me with this!

Kind Regards Bernhard

GMaxera commented 8 years ago

The android manifest is wrong. I'll post the correct one asap.

GMaxera commented 8 years ago

Here the changes that you have to apply in order to make it working:

It's the 4th line of your AndroidManifest.xml that has been changed. Look at the attribute 'android:name' changed from the default QtActivity to MyCustomAppActivity.

GMaxera commented 8 years ago

AndroidManifest.xml.txt MyCustomAppActivity.java.txt

bbernhard commented 8 years ago

Thanks for the detailed description. I checked my sourcecode again step by step and changed it accordingly. However, now I am getting a few error messages during compilation:


MyCustomAppActivity.java:4: error: package org.gmaxera.qtfacebook does not exist
import org.gmaxera.qtfacebook.QFacebookBinding;
                             ^
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:12: error: cannot find symbol
        QFacebookBinding.onCreate(this, bundle);
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:13: error: cannot find symbol
        QFacebookBinding.setApplicationName(getString(R.string.app_name));
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:18: error: cannot find symbol
        QFacebookBinding.onResume();
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:23: error: cannot find symbol
        QFacebookBinding.onSaveInstanceState(outState);
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:28: error: cannot find symbol
        QFacebookBinding.onPause();
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:32: error: cannot find symbol
        QFacebookBinding.onDestroy();
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity
C:\build-qtfacebook_test-Android\android-build\src\org\qtproject\example\MyCustomAppActivity.java:38: error: cannot find symbol
        QFacebookBinding.onActivityResult(requestCode, resultCode, data);
        ^
  symbol:   variable QFacebookBinding
  location: class MyCustomAppActivity

I am pretty sure, that I am just making a stupid little mistake, but I can't find it. I'll definitely take a look at it again tommorrow, maybe I just can't see it right now.

If you want to take a look, I attached my project. (only replaced the app_name and app_id in strings.xml with some dummy values). I would really appreciate it.

Kind Regards Bernhard qtfacebook_test.zip

GMaxera commented 8 years ago

qtfacebook_test_fixed.zip

Here it is :-)

Sorry, the error was coming from something I didn't documented. The standard approach of adding Android java sources in Qt projects doesn't work very well when there are java sources coming from different repository like when you need to use my library.

So, I moved the java source file (MyCustomAppActivity) away the android directory and placed into a directory called java. Then I added an explicit Install rule for copy the java source in the proper location during the build.

bbernhard commented 8 years ago

Hi,

it's working! I can't tell you how happy I am right now ;-)

Now it's time to play a little bit with your library. Hopefully I understand anything and maybe even can contribute something to QtFacebook in the future as well.

Many thanks for your help and patience!

Just an idea, but would it make sense to add your fixed example as an Android sample project?

Thanks and have a nice day

Kind Regards Bernhard

GMaxera commented 8 years ago

Yes, it's a good idea to add an Android sample project. Can you do and pull a request ?

bbernhard commented 8 years ago

I just decided to extend the sample project a little bit and add other stuff (at least the possibility to logout) too. It will probably take a little while, but I will create a pull request once I'm done.

Kind Regards Bernhard