嗨,我收到此异常,未找到任何解决方案。任何建议?
E / AndroidRuntime:致命异常:主要 处理:com.example.developerfyk.winnerinno,PID:26127 java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.developerfyk.winnerinno / com.example.developerfyk.winnerinno.Activity.HomeActivity}: android.content.res.Resources $ NotFoundException:资源ID
0x7f070064
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.content.res.Resources$NotFoundException: Resource ID
0x7f070064
at android.content.res.Resources.getValue(Resources.java:1351) at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:330) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188) at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100) at android.support.design.widget.TabLayout$Tab.setIcon(TabLayout.java:1388) at com.example.developerfyk.winnerinno.Activity.HomeActivity.setupTabIcons(HomeActivity.java:113) at com.example.developerfyk.winnerinno.Activity.HomeActivity.initView(HomeActivity.java:65) at com.example.developerfyk.winnerinno.Activity.HomeActivity.onCreate(HomeActivity.java:71) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
与目标虚拟机断开连接,地址:' localhost:8629',传输: '插座'
我的代码是:
public class HomeActivity extends BaseActivity implements ViewPager.OnPageChangeListener{
/**
* Activity class name holder variable
*/
private static final String CLASS_NAME = HomeActivity.class.getSimpleName();
/**
* Variables
*/
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
@Override
protected int getLayoutResourceId() {
return R.layout.activity_home;
}
@Override
protected Activity getActivity() {
return this;
}
@Override
protected void initView() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initView();
}
@Override
protected void onPause() {
super.onPause();
JZVideoPlayer.releaseAllVideos();
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
JZVideoPlayer.releaseAllVideos();
}
@Override
public void onPageScrollStateChanged(int state) {
}
@Override
public void onBackPressed() {
if(JZVideoPlayer.backPress()){
return;
}
super.onBackPressed();
}
private void setupTabIcons() {
int[] tabIcons = {
R.drawable.ic_tab_call,
R.drawable.ic_tab_contacts,
R.drawable.ic_tab_favourite
};
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new JoinFragment(),"join");
adapter.addFrag(new RateFragment(),"rate");
adapter.addFrag(new WinnerFragment(),"winner");
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment,String title){
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
// return null to display only the icon
return null;
}
}
}
答案 0 :(得分:0)
这可能(不知道您的BaseActivity类),因为您没有在活动setContentView()
中添加onCreate()
的布局。其中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initView();
}
@Override
protected void initView() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
...
}
您必须首先使用以下内容添加布局:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_home);
initView();
}