与滑动活动: - 资源未发现异常 [英] Swipe with Activity:- Resource Not Found Exception

查看:239
本文介绍了与滑动活动: - 资源未发现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想轻扫屏幕的某些部分。我用PageAdapter这一点。在刷卡的部分,我有三个活动结果
1. ShowMap结果
2. ShowAddress结果
3. ShowContact

我试图让ShowMap活动的布局ID,但它显示未发现异常的资源。这里是我的code MyPageAdapter

 公共类anyclass延伸活动{
    私有类MyPagerAdapter扩展PagerAdapter {        公众诠释的getCount(){
            返回3;
        }        公共对象instantiateItem(查看收集,INT位置){            LayoutInflater吹气=(LayoutInflater)collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);            INT渣油= 0;
            开关(位置){
            情况下0:
                渣油= showHotelContact();
                打破;
            情况1:
                渣油= showHotelAddress();
                打破;
            案例2:
                渣油= showHotelMap();
                打破;
            }            查看查看= inflater.inflate(渣油,NULL);
            ((ViewPager)集合).addView(查看,0);
            返回视图。
        }    }    公众诠释showHotelMap()
    {        意图bookIntent =新的Intent();
        bookIntent.setClass(HotelMap.this,ShowMap.class);
        startActivityForResult(bookIntent,RESID);        返回残差;
    }
    公众诠释showHotelAddress()
    {
        INT渣油;
        渣油= R.layout.hoteladdress;
        返回渣油;
    }
    公众诠释showHotelContact()
    {
        INT渣油;
        渣油= R.layout.hotelcontact;
        返回渣油;
    }
    @覆盖
    保护无效的onActivityResult(INT申请code,INT结果code,意图数据){        如果(结果code == RESULT_OK){
            RESID = data.getIntExtra(SelectedBook,结果code);
        }
    }
   }

我需要showMap布局的ID,我试图将其返回到我的PageAdapter但它显示出异常。
这里是的 ShowMap活动code

 公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.hotelmap);               INT渣油= R.layout.hotelmap;
           意图returnIntent =新的Intent();
           returnIntent.putExtra(SelectedBook,渣油);
           的setResult(RESULT_OK,returnIntent);
           完();        MapView类MapView类=(图形页面)findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(真);
        mapView.setStreetView(真);
        MapController MC = mapView.getController();
        双纬度= Double.parseDouble(48.85827758964043); //纬度
        双经度= Double.parseDouble(2.294543981552124); //经度
        GeoPoint对象的GeoPoint =新的GeoPoint((INT)(LAT * 1E6),(INT)(LON * 1E6));
        mc.animateTo(GeoPoint对象);
        mc.setZoom(15);
        mapView.invalidate();
        清单<&叠加GT; mapOverlays =调用MapView.getOverlays();
        可绘制可绘制= this.getResources()getDrawable(R.drawable.ic_launcher)。   }

下面是我的 logcat的

  12-31 13:14:26.740:E / AndroidRuntime(31140):$ android.content.res.Resources NotFoundException:资源编号为0x0
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.content.res.Resources.getValue(Resources.java:1104)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.content.res.Resources.loadXmlResourceParser(Resources.java:2342)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.content.res.Resources.getLayout(Resources.java:943)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在com..HotelMap $ MyPagerAdapter.instantiateItem(HotelMap.java:52)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.support.v4.view.ViewPager.addNewItem(ViewPager.java:801)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.support.v4.view.ViewPager.populate(ViewPager.java:930)
    12-31 13:14:26.740:E / AndroidRuntime(31140):在android.support.v4.view.ViewPager.populate(ViewPager.java:881)


解决方案

  startActivityForResult(bookIntent,RESID);

我想这是一个异步调用。计划不会等到活动开始活动结束并返回结果,而它只是执行这一行,并移动到下一行。所以这就是为什么 RESID 该方法返回 showHotelMap() 0

I am trying to swipe some part of the screen. I use PageAdapter for this. In swiping part I have three activity
1. ShowMap
2. ShowAddress
3. ShowContact

I am trying to getting id of layout of ShowMap Activity but it's showing resource not found exception. Here is my code of MyPageAdapter class

 public class anyclass extends Activity{
    private class MyPagerAdapter extends PagerAdapter {

        public int getCount(){
            return 3;
        }

        public Object instantiateItem(View collection, int position) {

            LayoutInflater inflater = (LayoutInflater) collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            int resId = 0;
            switch (position) {
            case 0: 
                resId = showHotelContact();             
                break;
            case 1:
                resId = showHotelAddress();         
                break;              
            case 2:     
                resId = showHotelMap();             
                break;      
            }

            View view = inflater.inflate(resId, null);
            ((ViewPager) collection).addView(view, 0);
            return view;
        }

    }

    public int showHotelMap()
    {

        Intent bookIntent = new Intent();     
        bookIntent.setClass(HotelMap.this,ShowMap.class);
        startActivityForResult(bookIntent,RESID);

        return RESID;
    }
    public int showHotelAddress()
    {
        int resId;
        resId = R.layout.hoteladdress;
        return resId;
    }
    public int showHotelContact()
    {
        int resId;
        resId = R.layout.hotelcontact;
        return resId;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK) {
            RESID = data.getIntExtra("SelectedBook", resultCode);
        }
    }
   }

I need id of showMap layout and i am trying to return it to my PageAdapter but it's showing an exception. And here is the code of ShowMap activity.

  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hotelmap);

               int  resId = R.layout.hotelmap;
           Intent returnIntent = new Intent();
           returnIntent.putExtra("SelectedBook",resId);
           setResult(RESULT_OK,returnIntent);        
           finish();

        MapView mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);
        mapView.setStreetView(true);
        MapController mc = mapView.getController();
        double lat = Double.parseDouble("48.85827758964043"); // latitude
        double lon = Double.parseDouble("2.294543981552124"); // longitude
        GeoPoint geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon * 1E6));
        mc.animateTo(geoPoint);
        mc.setZoom(15);
        mapView.invalidate();
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);

   }

Here is my Logcat.

 12-31 13:14:26.740: E/AndroidRuntime(31140): android.content.res.Resources$NotFoundException: Resource ID #0x0
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.content.res.Resources.getValue(Resources.java:1104)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2342)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.content.res.Resources.getLayout(Resources.java:943)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at com..HotelMap$MyPagerAdapter.instantiateItem(HotelMap.java:52)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:801)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.support.v4.view.ViewPager.populate(ViewPager.java:930)
    12-31 13:14:26.740: E/AndroidRuntime(31140):    at android.support.v4.view.ViewPager.populate(ViewPager.java:881)  

解决方案

startActivityForResult(bookIntent,RESID);

I guess this is an Async Call. Program will not wait until the activity the starting activity finishes and returns the result, rather it will just execute this line and move on to the next line. So that is why RESID returned by the method showHotelMap() is 0.

这篇关于与滑动活动: - 资源未发现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆