本文介绍了奇怪的NPE:尝试从空对象引用上的字段'com.google.android.gms.ads.internal.client.o com.google.android.gms.ads.i.a'中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用程序中启动特定活动时,我得到了这个奇怪的NPE。



I'm getting this strange NPE when launching a specific activity in my android App.

java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.o com.google.android.gms.ads.i.a' on a null object reference 09-13 09:13:07.220 14820 14820 E AndroidRuntime: at dancam.com.chords.ChordsList.b.a(Unknown Source) 09-13 09:13:07.220 14820 14820 E AndroidRuntime: at dancam.com.chords.ChordsList.g.onClick(Unknown Source)





从这里你可以看到来源似乎未知。



这个是导致NPE的活动的代码:






As you can see from here the source seems to be unknown.

This is my code for the Activity causing the NPE:


public class ChordActivity extends Activity {
ViewPager viewPager;
PagerAdapter adapter;
TextView name, note;
CirclePageIndicator _indicator;
ImageButton sound;
boolean isPremium;
static final String PREFERENCES = "prefs";


@Override
public void onCreate(Bundle b){
    super.onCreate(b);
    setContentView(R.layout.chord_layout);

    SharedPreferences settings = getSharedPreferences(PREFERENCES,0);
    isPremium = settings.getBoolean("status", false);

    /** gestisce le pubblicita */
    if (!isPremium) {
        MobileAds.initialize(getApplicationContext(), "ca-app-pub-6723047396589178/2515152442");
        AdView chordBanner = (AdView) findViewById(R.id.chord_banner);
        AdRequest adRequest = new AdRequest.Builder().build();
        chordBanner.loadAd(adRequest);
    }

    Intent intent = this.getIntent();
    Bundle bundle = intent.getExtras();
    final Accordo selectedAccordo = bundle.getParcelable("selected");

    viewPager = (ViewPager) findViewById(R.id.pager);
    adapter = new ChordPagerAdapter(ChordActivity.this, selectedAccordo);
    viewPager.setAdapter(adapter);

    _indicator = (CirclePageIndicator) findViewById(R.id.dot_indicator);
    _indicator.setViewPager(viewPager);

    name = (TextView) findViewById(R.id.chord_view_nome);
    note = (TextView) findViewById(R.id.accordo_view_note);

    name.setText(getResources().getString(selectedAccordo.getName()));
    //note.setText(selectedAccordo.getNote());

    /** gestisce il pulsante: riproduci accordo*/

    final MediaPlayer player = MediaPlayer.create(this, selectedAccordo.getSound());

    sound.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            player.start();
        }

    });
}
}





这是我目前所理解的(我会尽快更新)当我发现其他事情时):

只有当isPremium为true时才会出现此错误,因此当广告未加载时





之前有没有人有这个错误?这是什么意思?我怎么修理它?






我在Android应用程序中启动特定活动时遇到这个奇怪的NPE 。



java.lang.NullPointerException:尝试从字段'com.google.android.gms.ads.internal.client.o com.google.android中读取。 gms.ads.i.a'对空对象引用09-13 09:13:07.220 14820 14820 E AndroidRuntime:at dancam.com.chords.ChordsList.ba(Unknown Source)09-13 09:13:07.220 14820 14820 E AndroidRuntime:在dancam.com.chords.ChordsList.g.onClick(未知来源)

从这里可以看到来源似乎未知。



这是我导致NPE的活动的代码:



公共类ChordActivity扩展活动{

ViewPager viewPager;

PagerAdapter适配器;

TextView名称,注意;

CirclePageIndicator _indicator;

ImageButton声音;

boolean isPremium;

static final String PREFERENCES =pref s;





@Override

public void onCreate(Bundle b){

super.onCreate(b);

setContentView(R.layout.chord_layout);



SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);

isPremium = settings.getBoolean(status,false);



/ ** gestisce le pubblicita * /

if(!isPremium){

MobileAds.initialize(getApplicationContext(),ca-app-pub-6723047396589178/2515152442);

AdView chordBanner =(AdView)findViewById(R.id.chord_banner);

AdRequest adRequest = new AdRequest.Builder()。build();

chordBanner.loadAd(adRequest) ;

}



意图intent = this.getIntent();

Bundle bundle = intent.getExtras( );

最终Accordo选择了Acordo = bundle.getParcelable(选中);



viewPager =(ViewPage r)findViewById(R.id.pager);

adapter = new ChordPagerAdapter(ChordActivity.this,selectedAccordo);

viewPager.setAdapter(adapter);



_indicator =(CirclePageIndicator)findViewById(R.id.dot_indicator);

_indicator.setViewPager(viewPager);



name =(TextView)findViewById(R.id.chord_view_nome);

note =(TextView)findViewById(R.id.accordo_view_note);



name.setText(getResources()。getString(selectedAccordo.getName()));

//note.setText(selectedAccordo.getNote());



/ ** gestisce il pulsante:riproduci accordo * /



最终MediaPlayer播放器= MediaPlayer.create(这个,selectedAccordo.getSound());



sound.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(查看v){

player.start();

}



});

}

}

这就是我的意思到目前为止已经理解了(我会在发现其他事情后立即更新):



只有当isPremium为true时才会出现此错误,因此当广告未加载时

之前有没有人有这个错误?这是什么意思?我怎么修理它?







这是我的build.gradle:







This is what I understood so far (I will update it as soon as I discover other things):
this error happens only when isPremium is true, so when the Ads are NOT loaded


Has anyone had this error before? what does it mean? how ca I fix it?



I'm getting this strange NPE when launching a specific activity in my android App.

java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.o com.google.android.gms.ads.i.a' on a null object reference 09-13 09:13:07.220 14820 14820 E AndroidRuntime: at dancam.com.chords.ChordsList.b.a(Unknown Source) 09-13 09:13:07.220 14820 14820 E AndroidRuntime: at dancam.com.chords.ChordsList.g.onClick(Unknown Source)
As you can see from here the source seems to be unknown.

This is my code for the Activity causing the NPE:

public class ChordActivity extends Activity {
ViewPager viewPager;
PagerAdapter adapter;
TextView name, note;
CirclePageIndicator _indicator;
ImageButton sound;
boolean isPremium;
static final String PREFERENCES = "prefs";


@Override
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.chord_layout);

SharedPreferences settings = getSharedPreferences(PREFERENCES,0);
isPremium = settings.getBoolean("status", false);

/** gestisce le pubblicita */
if (!isPremium) {
MobileAds.initialize(getApplicationContext(), "ca-app-pub-6723047396589178/2515152442");
AdView chordBanner = (AdView) findViewById(R.id.chord_banner);
AdRequest adRequest = new AdRequest.Builder().build();
chordBanner.loadAd(adRequest);
}

Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
final Accordo selectedAccordo = bundle.getParcelable("selected");

viewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ChordPagerAdapter(ChordActivity.this, selectedAccordo);
viewPager.setAdapter(adapter);

_indicator = (CirclePageIndicator) findViewById(R.id.dot_indicator);
_indicator.setViewPager(viewPager);

name = (TextView) findViewById(R.id.chord_view_nome);
note = (TextView) findViewById(R.id.accordo_view_note);

name.setText(getResources().getString(selectedAccordo.getName()));
//note.setText(selectedAccordo.getNote());

/** gestisce il pulsante: riproduci accordo*/

final MediaPlayer player = MediaPlayer.create(this, selectedAccordo.getSound());

sound.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player.start();
}

});
}
}
This is what I understood so far (I will update it as soon as I discover other things):

this error happens only when isPremium is true, so when the Ads are NOT loaded
Has anyone had this error before? what does it mean? how ca I fix it?



this is my build.gradle:


apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.dancam.chords"
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 8
        versionName "1.0"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    }

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:recyclerview-v7:24.2.0'
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
    compile 'com.google.firebase:firebase-ads:9.4.0'
    compile 'com.google.firebase:firebase-invites:9.4.0'
    compile 'com.google.firebase:firebase-crash:9.4.0'
    }

    apply plugin: 'com.google.gms.google-services'





我尝试了什么:



我试过禁用proguard并复制了测试。它不起作用,这是logcat输出:



09-13 11:42:28.264 26502 26502 E AndroidRuntime:主题:主题:{com.google.android .googlequicksearchbox = overlay:system} 09-13 11:42:28.264 26502 26502 E AndroidRuntime:java.lang.NullPointerException:尝试从com.google.android.gms.ads.internal.client.o com.google字段中读取.android.gms.ads.i.a'关于空对象引用09-13 11:42:28.264 26502 26502 E AndroidRuntime:at dancam.com.chords.ChordsList.ba(Unknown Source)09-13 11:42: 28.264 26502 26502 E AndroidRuntime:at dancam.com.chords.ChordsList.g.onClick(Unknown Source)09-13 11:42:28.264 26502 26502 E AndroidRuntime:at android.view.View.performClick(View.java:5204) 09-13 11:42:28.264 26502 26502 E AndroidRuntime:在android.view.View $ PerformClick.run(View.java:21158)09-13 11:42:28.264 26502 26502 E AndroidRuntime:在android.os.Handler。 handleCallback(Handler.java:739)09-13 11:43:28.264 26502 26502 E AndroidRuntime:at android.os.Handler.dispatchM essage(Handler.java:95)09-13 11:42:28.264 26502 26502 E AndroidRuntime:at android.os.Looper.loop(Looper.java:148)09-13 11:42:28.264 26502 26502 E AndroidRuntime:at android.app.ActivityThread.main(ActivityThread.java:5461)09-13 11:42:28.264 26502 26502 E AndroidRuntime:at java.lang.reflect.Method.invoke(Native Method)09-13 11:42:28.264 26502 26502 E AndroidRuntime:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)09-13 11:42:28.264 26502 26502 E AndroidRuntime:at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)09-13 11:42:28.266 18150 18649 W ActivityManager:强制完成活动com.dancam.chords / dancam.com.chords.ChordsList.ChordsListActivity



What I have tried:

I have tried disabling proguard and replicated the test. It does not work, this is the logcat output:

09-13 11:42:28.264 26502 26502 E AndroidRuntime: Theme: themes:{com.google.android.googlequicksearchbox=overlay:system} 09-13 11:42:28.264 26502 26502 E AndroidRuntime: java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.o com.google.android.gms.ads.i.a' on a null object reference 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at dancam.com.chords.ChordsList.b.a(Unknown Source) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at dancam.com.chords.ChordsList.g.onClick(Unknown Source) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at android.view.View.performClick(View.java:5204) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at android.view.View$PerformClick.run(View.java:21158) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5461) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 09-13 11:42:28.264 26502 26502 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 09-13 11:42:28.266 18150 18649 W ActivityManager: Force finishing activity com.dancam.chords/dancam.com.chords.ChordsList.ChordsListActivity

推荐答案



这篇关于奇怪的NPE:尝试从空对象引用上的字段'com.google.android.gms.ads.internal.client.o com.google.android.gms.ads.i.a'中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 06:29