我想在我的Android应用中显示全屏横幅.
在onCreate我称之为这个功能:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showInterstitial();
}
Run Code Online (Sandbox Code Playgroud)
我的功能:
private void showInterstitial() {
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.ad_banner_id));
interstitialAd.show();
Toast.makeText(this, "Ad will load", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序将崩溃此消息:
引起:java.lang.IllegalStateException:必须在调用show之前在InterstitialAd上设置广告单元ID.
但是我在节目之前设置了广告ID,不是吗?
我想在ButterKnife中使用ViewStub,这就是我所做的:
public class ExampleFragment extends Fragment {
@InjectView ( R.id.stub )
ViewStub mStub;
/* A TextView in the ViewStub */
@InjectView ( R.id.text )
@Optional
TextView mText;
@Override
public View onCreateView ( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
View rootView = inflater.inflate ( R.layout.rootview, container, false );
ButterKnife.inject ( this, rootView );
mStub.setLayoutResource ( R.layout.stub_layout );
View inflated = mStub.inflate ();
ButterKnife.inject ( mStub, inflated );
mText.setText("test.");
return rootView;
}
}
Run Code Online (Sandbox Code Playgroud)
并且日志说:
mText is a null object reference …
我正在尝试使用Android Studio编译项目,并且出现此错误。我已经将导入appcompat到build.gradle文件中:
dependencies {
compile 'com.android.support:support-v4:21.0.+'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.melnykov:floatingactionbutton:1.1.0'
}
Run Code Online (Sandbox Code Playgroud)
在几个文件中,我导入了这个文件:
import android.support.v7.app.ActionBarActivity;
Run Code Online (Sandbox Code Playgroud) sdk android android-appcompat android-support-library android-studio
这是一个使用gradle的Android应用程序.点击后Run,我找到了,但事件日志说:APP_V1.3.4_2016-02-22_11:30:29_google_play.apkoutputs/apk
11:30:31 EmptyThrowable:APK文件/.../WorkSpace/Android/.../app/build/outputs/apk/APP_V1.3.4_2016-02-22_ 11:30:14 _google_play.apk不存在在磁盘上.
11:30:32会话'app':安装APK时出错
这是我的build.gradle档案:
apply plugin: 'com.android.application'
def releaseTime() {
return new Date().format("yyyy-MM-dd_HH:mm:ss",
TimeZone.getTimeZone("GMT+08:00"))
}
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 23
versionCode 29
versionName "1.3.4"
manifestPlaceholders = [SOME_CHANNEL_VALUE: "some_channel"]
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
debug {}
release {
// ...
}
}
buildTypes {
debug {
zipAlignEnabled true
minifyEnabled false
shrinkResources true
}
release {
zipAlignEnabled true
minifyEnabled true …Run Code Online (Sandbox Code Playgroud) [
{
"id": "a",
"pid": "a",
"name": "AA",
},
{
"id": "b",
"pid": "a",
"name": "BB",
},
{
"id": "c",
"pid": "a",
"name": "CC",
},
{
"id": "x",
"pid": "b",
"name": "XX",
}
]
Run Code Online (Sandbox Code Playgroud)
上面是我从数据库中获得的数据。每个人都有一个id和一个pid,pid指向该人的较高级别的人id。如果一个人的水平最高,则id等于pid。
我想将原始数据转换为分层JSON,如下所示:
[
{
"id": "a",
"name": "AA",
"child": [
{
"id": "b",
"name": "BB"
"child": [
{
"id": "x",
"name": "XX"
}
]
},
{
"id": "c",
"name": "CC"
}
]
}
] …Run Code Online (Sandbox Code Playgroud)