我的应用程序运行正常,直到我添加了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();
}
}
}
答案 0 :(得分:0)
根据您的logcat,您将在ArrayIndexOutOfBoundsException
中获得onItemClick()
。这是因为您从position
的从零开始AdapterView
减去1,所以如果index
为0,则得到-1,这显然超出了{{1}的范围}}
将其更改为仅使用Array
。
index
答案 1 :(得分:0)
可替换地,
刚才我注意到你的代码,你没有导入任何Airpush SDK类,而是我可以看到Admob SDK导入的语法。