我的應用程序工作完美,直到我添加了airpush SDK。現在,當我運行它,並嘗試使用它,我得到這些錯誤和應用程序關閉:添加Airpush SDK後應用程序不再工作
應用代碼:
package com.etqanapps.EtqanChannel.UI;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.MyChannel.R;
import com.etqanapps.EtqanChannel.Adapters.PlayListAdapterSliding;
import com.etqanapps.EtqanChannel.Controllers.Consts;
import com.etqanapps.EtqanChannel.DataModel.PlayListModel;
import com.etqanapps.EtqanChannel.DataModel.VideoModel;
import com.etqanapps.EtqanChannel.Listeners.MenuActionsListener;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
public class UIPlayList extends RelativeLayout implements OnItemClickListener,
OnClickListener {
ListView lv;
TextView tv_title;
Button btn_open_menu;
Button btn_open_info;
ArrayList<VideoModel> feed;
Context c;
PlayListAdapterSliding ad;
MenuActionsListener listener;
Activity ac;
AdView ad1;
AdView ad2;
String AD_UNIT_ID;
public UIPlayList(Context context, MenuActionsListener listener,Activity ac) {
super(context);
feed = new ArrayList<VideoModel>();
this.listener = listener;
c = context;
this.ac=ac;
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getContext().getSystemService(
inflater);
if(isTablet(c)){
if(Consts.isEnglish()){
li.inflate(R.layout.ui_play_list_tab, this, true);
}else{
li.inflate(R.layout.ui_play_list_tab_ar, this, true);
}
}else{
if(Consts.isEnglish()){
li.inflate(R.layout.ui_play_list_phone, this, true);
}else{
li.inflate(R.layout.ui_play_list_phone_ar, this, true);
}
}
lv = (ListView) findViewById(R.id.lv);
tv_title = (TextView) findViewById(R.id.tv_title);
btn_open_menu = (Button) findViewById(R.id.btn_open_menu);
btn_open_info = (Button) findViewById(R.id.btn_open_info);
btn_open_menu.setOnClickListener(this);
btn_open_info.setOnClickListener(this);
AD_UNIT_ID=c.getString(R.string.AD_UNIT_ID);
if(AD_UNIT_ID.length()>1){
initAds();
}
lv.setAdapter(ad);
}
private void initAds() {
ad1=new AdView(ac, AdSize.SMART_BANNER,AD_UNIT_ID);
ad2=new AdView(ac, AdSize.SMART_BANNER,AD_UNIT_ID);
lv.addHeaderView(ad1);
lv.addFooterView(ad2);
reLoadAds();
}
public void reLoadAds() {
ad1.loadAd(new AdRequest());
ad2.loadAd(new AdRequest());
}
public UIPlayList refreshData(PlayListModel pl) {
feed.clear();
feed.addAll(0, pl.getVideos());
if (isTablet(c)) {
if(Consts.isEnglish()){
ad = new PlayListAdapterSliding(c, R.layout.row_video_tab, feed,ac);
}else{
ad = new PlayListAdapterSliding(c, R.layout.row_video_tab_ar, feed,ac);
}
} else {
if(Consts.isEnglish()){
ad = new PlayListAdapterSliding(c, R.layout.row_video_phone, feed,ac);
}else{
ad = new PlayListAdapterSliding(c, R.layout.row_video_phone_ar, feed,ac);
}
}
tv_title.setText(pl.getTitle());
lv.setAdapter(ad);
lv.setOnItemClickListener(this);
ad.notifyDataSetChanged();
if(ad1!=null){
reLoadAds();
}
return this;
}
public static boolean isTablet(Context c) {
DisplayMetrics displayMetrics = c.getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels/displayMetrics.densityDpi;
int height = displayMetrics.heightPixels/displayMetrics.densityDpi;
double screenDiagonal = Math.sqrt(width * width + height * height);
System.out.println("screenDiagonal : " + screenDiagonal);
return (screenDiagonal >= 6.0);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
VideoModel video = feed.get(index-1);
listener.onOpenVideo(video);
}
@Override
public void onClick(View v) {
if (v == btn_open_info) {
listener.openInfo();
}else if (v == btn_open_menu) {
listener.showMenu();
}
}
}
你爲什麼要做'VideoModel video = feed.get(index-1);'而不是'index'?當'index'爲0時,它試圖獲得-1的索引,它給你'IndexOutOfBounds Exception' – codeMagic
我認爲嘗試刪除=返回(screenDiagonal> = 6.0); –
@ManetiVinay只是說'返回true',如果該表達式爲'true',否則'返回false' – codeMagic