关于android 页面滑动,滑动到第四个页面调试时闪退

qq_23848895 2016-09-20 10:08:15
下边贴代码:
这是DetailActivity 里边的代码:
public class DetailActivity extends FragmentActivity {
private ViewPager viewPager;
private PagerAdapter adapter;

private String test;


/* private Intent intent ;
private TextView songname;
private TextView singer;
private ImageView image;
private TextView content;
private Musics musics;*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
this.viewPager = (ViewPager) this.findViewById(R.id.fragement_main);
FragmentManager fm =getSupportFragmentManager();
this.adapter = new MyPagerAdapter(fm);
this.viewPager.setAdapter(adapter);
this.getActionBar().setDisplayHomeAsUpEnabled(true);


}
public class MyPagerAdapter extends FragmentPagerAdapter{

public MyPagerAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}

@Override
public Fragment getItem(int num) {


Fragment fragment = new DetailFragment(num);
Bundle bundle =new Bundle();
bundle.putString("test", test);
fragment.setArguments(bundle);
// TODO Auto-generated method stub
return fragment;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return 10;
}

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main_page, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();
switch (id) {
case R.id.share:
actionShare();
break;



}
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}





private void actionShare() {
// TODO Auto-generated method stub
Toast.makeText(this, "成功分享", Toast.LENGTH_SHORT).show();
}
//使用XML文件生成上下文菜单
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.main_page, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
//上下文设置事件
@Override
public boolean onContextItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.share:
actionShare();
break;

}
return super.onContextItemSelected(item);
}
}

接下来是DetailFragment 代码
public class DetailFragment extends Fragment {
private int index;
private DataProvider provider;
private Loves loves;



public DetailFragment(int arg0) {
this.index = arg0;
// TODO Auto-generated constructor stub
}



@Override
public void onCreate(Bundle savedInstanceState) {


this.provider = new DataProvider();
this.loves = this.provider.getLovesByIndex(index);
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_detail_fragment, container, false);
TextView songname = (TextView) view.findViewById(R.id.Dsongname);
ImageView image = (ImageView) view.findViewById(R.id.Dimage);


//image2.setAlpha(100);
songname.setText(loves.getSongname());
image.setImageResource(loves.getImage());


return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);



}


}

数据是写了一个dataprovider 提供的




为什么在调试的时候,滑动到第四个页面就闪退了 实在找不到原因
...全文
131 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_23848895 2016-09-20
  • 打赏
  • 举报
回复
引用 9 楼 afunx 的回复:
前辈不敢当。希望问题能顺利解决。
嗯嗯 顺利解决了。谢谢您
afunx 2016-09-20
  • 打赏
  • 举报
回复
前辈不敢当。希望问题能顺利解决。
qq_23848895 2016-09-20
  • 打赏
  • 举报
回复
引用 7 楼 afunx 的回复:
给你一个建议。先找一个差不多的模板代码,确认模板代码ok,然后再根据你的需求来改。这样,比你全部自己写要好多了,尤其是刚开始学的时候。
主要我是原来系统学过一阵子,因为确定自己代码没有问题,所以就是找不到原因。。。 刚刚经过前辈提醒,内存过大,才知道可能是照片太大了 导致的
afunx 2016-09-20
  • 打赏
  • 举报
回复
给你一个建议。先找一个差不多的模板代码,确认模板代码ok,然后再根据你的需求来改。这样,比你全部自己写要好多了,尤其是刚开始学的时候。
afunx 2016-09-20
  • 打赏
  • 举报
回复
是不是图片占用内存了,导致内存溢出了?
qq_23848895 2016-09-20
  • 打赏
  • 举报
回复
引用 4 楼 afunx 的回复:
OutOfMemoryError,内存溢出。。。 log越上面就离你出错的代码越近
会不会是因为照片太大 内存不够导致的
afunx 2016-09-20
  • 打赏
  • 举报
回复
OutOfMemoryError,内存溢出。。。 log越上面就离你出错的代码越近
qq_23848895 2016-09-20
  • 打赏
  • 举报
回复
引用 1 楼 afunx 的回复:
代码格式有点乱。 log能比较快的定位问题。
log贴出,因为是学生,不怎么看的懂
qq_23848895 2016-09-20
  • 打赏
  • 举报
回复
下边贴出log
afunx 2016-09-20
  • 打赏
  • 举报
回复
代码格式有点乱。 log能比较快的定位问题。

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧