Search code examples
androidandroid-support-libraryandroid-studio-2.0

How to set the about page library in android studio


I am trying to set the about page library with

compile 'com.github.medyo:android-about-page:1.0.2'

But I am getting a run time error I have set as it is given in the github here is my java code:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import mehdi.sakout.aboutpage.AboutPage;
import mehdi.sakout.aboutpage.Element;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Element versionElement = new Element();
    versionElement.setTitle("Version 6.2");

    Element adsElement = new Element();
    adsElement.setTitle("Advertise with us");

    View aboutPage = new AboutPage(this)
            .isRTL(false)
            .setImage(R.drawable.wall)
            .addItem(versionElement)
            .addItem(adsElement)
            .addGroup("Connect with us")
            .addEmail("[email protected]")
            .addFacebook("the.medy")
            .addTwitter("medyo80")
            .addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
            .addPlayStore("com.ideashower.readitlater.pro")
            .addInstagram("medyo80")
            .addGitHub("medyo")
            .create();

    setContentView(aboutPage);
}

} Can some one tell me what changes will I do in my code to set the support library.I am trying to import library from https://github.com/medyo/android-about-page I have sync the gradle. gradle file

 apply plugin: 'com.android.application'


buildscript {
repositories {
    jcenter()
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.union.test7"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
    buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.github.medyo:android-about-page:1.0.2'
}

I am able to compile the program But it is not running in my emulator error

 E/AndroidRuntime: FATAL EXCEPTION: main
                                           java.lang.RuntimeException: Unable to start activity ComponentInfo{com.union.test7/com.union.test7.MainActivity}: java.lang.NullPointerException
                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
                                               at android.app.ActivityThread.access$600(ActivityThread.java:130)
                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
                                               at android.os.Handler.dispatchMessage(Handler.java:99)
                                               at android.os.Looper.loop(Looper.java:137)
                                               at android.app.ActivityThread.main(ActivityThread.java:4745)
                                               at java.lang.reflect.Method.invokeNative(Native Method)
                                               at java.lang.reflect.Method.invoke(Method.java:511)
                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                               at dalvik.system.NativeStart.main(Native Method)
                                            Caused by: java.lang.NullPointerException

Solution

  • In order to use this Library you need to use jcenter.

    As it defines Available on Jcenter, Maven and JitPack.

    So modify your Build.Gradle as below.

    apply plugin: 'com.android.application'
    
    buildscript {
        repositories {
            jcenter()
        }
    }
    

    And here is the code you need to use.

    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            Element versionElement = new Element();
            versionElement.setTitle("Version 6.2");
    
            Element adsElement = new Element();
            adsElement.setTitle("Advertise with us");
    
            View aboutPage = new AboutPage(this)
                    .isRTL(false)
                    .setImage(R.drawable.dummy_image)
                    .addItem(versionElement)
                    .addItem(adsElement)
                    .addGroup("Connect with us")
                    .addEmail("[email protected]")
                    .addFacebook("the.medy")
                    .addTwitter("medyo80")
                    .addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
                    .addPlayStore("com.ideashower.readitlater.pro")
                    .addInstagram("medyo80")
                    .addGitHub("medyo")
                    .create();
    
            setContentView(aboutPage);
        }
    }
    

    Note: setContentView(R.layout.activity_main) is not Required to write in code because library Generating it Automatically.