如何在安卓工作室中设置关于页面库



我正在尝试使用

编译 'com.github.medyo:android-about-page:1.0.2'

但是我收到我在 github 中设置的运行时错误这是我的Java代码:

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("elmehdi.sakout@gmail.com")
            .addFacebook("the.medy")
            .addTwitter("medyo80")
            .addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
            .addPlayStore("com.ideashower.readitlater.pro")
            .addInstagram("medyo80")
            .addGitHub("medyo")
            .create();
    setContentView(aboutPage);
}

}有人可以告诉我我将在代码中进行哪些更改以设置支持库。我正在尝试从 https://github.com/medyo/android-about-page 导入库我已经同步了成绩。格拉德尔文件

 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'
}

我能够编译程序,但它没有在我的模拟器中运行错误

 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

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

As it defines Available on Jcenter, Maven and JitPack .

因此,请按如下方式修改您的Build.Gradle

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

这是您需要使用的代码。

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("elmehdi.sakout@gmail.com")
                .addFacebook("the.medy")
                .addTwitter("medyo80")
                .addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
                .addPlayStore("com.ideashower.readitlater.pro")
                .addInstagram("medyo80")
                .addGitHub("medyo")
                .create();
        setContentView(aboutPage);
    }
}

注意:setContentView(R.layout.activity_main)不需要编写代码,因为库会自动生成它。

相关内容

  • 没有找到相关文章

最新更新