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

NullPointerException when creating a session #11

Open
bbernhard opened this issue Jun 7, 2016 · 10 comments
Open

NullPointerException when creating a session #11

bbernhard opened this issue Jun 7, 2016 · 10 comments

Comments

@bbernhard
Copy link
Contributor

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
Copy link
Owner

GMaxera commented Jun 7, 2016

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
Copy link
Contributor Author

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
Copy link
Owner

GMaxera commented Jun 8, 2016

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

@GMaxera
Copy link
Owner

GMaxera commented Jun 8, 2016

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

  • you should have an Android package directory in you project where you placed the AndroidManifest.xml and the MyCustomAppActivity.java
  • the directory tree when MyCustomAppActivity.java should match the package name of your app. Let's suppose the package name of the app is com.mycompany.myapp then the MyCustomAppActivity.java source should be placed into src/com/mycompany/myapp
  • the first line of MyCustomAppActivity.java has to declare in which package the class belongs:
    package com.mycompany.myapp;
  • then into the AndroidManifest.xml the tag declaring the activity has to specify MyCustomAppActivity as starting class:
    <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.mycompany.myapp.MyCustomAppActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">

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
Copy link
Owner

GMaxera commented Jun 8, 2016

@bbernhard
Copy link
Contributor Author

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
Copy link
Owner

GMaxera commented Jun 8, 2016

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
Copy link
Contributor Author

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
Copy link
Owner

GMaxera commented Jun 9, 2016

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

@bbernhard
Copy link
Contributor Author

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

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