有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java当我将Interstitual ID更改为Admob上的ID,并尝试在手机上测试应用程序时

每当我将Interstitual ID更改为AdMob上的ID,并尝试在手机上测试应用程序时,它会在屏幕上向我显示此消息,不幸的是,应用程序已被停止。请如何处理此问题?? 这是我用来实现ads的代码,非常适合测试,但当我更改其ID时,应用程序不工作,indroid studio没有显示任何错误,只是一条消息,说明安装已成功完成,所以有什么想法吗

JAVA

    //View adContainer = findViewById(R.id.unitads);
        final String packageName = this.getPackageName();
        context = this;
        linearlayout = (LinearLayout)findViewById(R.id.unitads);
        admob.admobBannerCall(this, linearlayout);
        
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(SettingsClass.Interstitial);
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
            }
        });

        requestNewInterstitial();
        
        rateus = (Button)findViewById(R.id.rateus2);
        shareapp= (Button) findViewById(R.id.play2);
        
        rateus.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AppRater.rateLink(MainActivity.this);
                 
            }
        });
        
        shareapp.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                ShareApp();
            }
        });
        
        mDBHelper = new DataBaseHelper(this);
      //got it from here
        //Check exists database
        File database = getApplicationContext().getDatabasePath(DataBaseHelper.DBNAME);
        if(false == database.exists()) {
            mDBHelper.getReadableDatabase();
            //Copy db
            if(copyDatabase(this)) {
                //Toast.makeText(this, "Copy database succes", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(this, "Copy data error"+DataBaseHelper.DBLOCATION, Toast.LENGTH_LONG).show();
                return;
            }
        }
        //Get product list in db when db exists
        mItemList = new ArrayList<>();
        mItemList.clear();
        mItemList.addAll(mDBHelper.getListItem());
        //Init adapter
        adapter = new ListItemAdapter(this, mItemList);
        adapter.setClickListener(this);
        //Set adapter for listview
        try {
            lvItem.setAdapter(adapter);
        }catch (Exception ex){}
        //itemSelected();
    }
    
    private void ShareApp(){
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = "Hey my friend check out this app\n https://play.google.com/store/apps/details?id="+ getPackageName() +" \n";
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, "Share via"));
    }
    
    private boolean copyDatabase(Context context) {
        try {

            InputStream inputStream = context.getAssets().open(DataBaseHelper.DBNAME);
            String outFileName = DataBaseHelper.DBLOCATION + DataBaseHelper.DBNAME;
            OutputStream outputStream = new FileOutputStream(outFileName);
            byte[]buff = new byte[1024];
            int length = 0;
            while ((length = inputStream.read(buff)) > 0) {
                outputStream.write(buff, 0, length);
            }
            outputStream.flush();
            outputStream.close();
            Log.w("SplashActivity","DB copied");
            return true;
        }catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    
    
    @Override
    public void onBackPressed() {
        AppRater.app_launched(this);
    }
   
    private void requestNewInterstitial() {
         mInterstitialAd.loadAd(ConsentSDK.getAdRequest(context));
    } 
  /*
    private void itemSelected() {
        
        lvItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
             Item itemClicked = mItemList.get(position) ;
                
                try {
                    //Class classe= Class.forName(getPackageName()+".Details");
                    Intent intent=new Intent(MainActivity.this,Details.class);
                    intent.putExtra("detail",""+itemClicked.getText());
                    intent.putExtra("title",""+itemClicked.getTitle());
                    startActivityForResult(intent, 1);
                    //startActivity(intent);
                    //finish();
                    if(admob.mCount == admob.nbShowInterstitial) {
                        if (mInterstitialAd.isLoaded()) 
                            mInterstitialAd.show();
                            admob.mCount=0;
                    }
                    ++admob.mCount;
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
             
            };
        });
    }
*/
    @Override
    public void onItemClick(View view, int position) {
        if ((mItemList.get(position) instanceof Item)) {
            Item itemClicked = (Item) mItemList.get(position);
            try {

                //Class classe= Class.forName(getPackageName()+".Details");
                Intent intent = new Intent(MainActivity.this, Details.class);
                intent.putExtra("detail", "" + itemClicked.getText());
                intent.putExtra("title", "" + itemClicked.getTitle());
                startActivityForResult(intent, 1);
                //startActivity(intent);
                //finish();
                if (admob.mCount == admob.nbShowInterstitial) {
                    if (mInterstitialAd.isLoaded())
                        mInterstitialAd.show();
                    admob.mCount = 0;
                }
                ++admob.mCount;
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public void guide(View view) {
        switch (view.getId()) {
            case R.id.button12:
                Intent intent = new Intent(MainActivity.this, Data_one.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
        }
                break;
            case R.id.button13:
                intent = new Intent(MainActivity.this, Data_two.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
                break;
            case R.id.button14:
                intent = new Intent(MainActivity.this, Data_three.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
                break;
            case R.id.button:
                intent = new Intent(MainActivity.this, Data_four.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
                break;
            case R.id.button2:
                intent = new Intent(MainActivity.this, Data_five.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
                break;
            case R.id.button3:
                intent = new Intent(MainActivity.this, Data_six.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
                break;
            case R.id.button4:
                intent = new Intent(MainActivity.this, Data_seven.class);
                startActivity(intent);
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
        }

}
}

共 (0) 个答案