我正在尝试使用
设置about页面库compile' 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导入库 我已经同步了这个等级。 gradel文件
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
答案 0 :(得分:3)
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)
不需要在代码中编写,因为库会自动生成它。