错误:错误:字符串[ResourceType]类型的预期资源

时间:2016-03-29 19:24:26

标签: java android-studio

当我生成签名的apk时,我遇到了这个问题:

  

C:\用户\ amjah \桌面\ AndroidNewsApp \应用\ SRC \主\的java \ COM \ solodroid \ androidnewsapp \ News_Detail.java   错误:错误:字符串[ResourceType]

类型的预期资源
int position;
String[] allArraynews,allArraynewsCatName;
String[] allArrayNewsCId,allArrayNewsCatId,allArrayNewsCatImage,allArrayNewsCatName,allArrayNewsHeading,allArrayNewsImage,allArrayNewsDes,allArrayNewsDate;
ImageView vp_imageview;
ViewPager viewpager;
public ImageLoader imageLoader; 
int TOTAL_IMAGE;
public DatabaseHandler db;
private Menu menu;
private AdView mAdView;
String newscid,newscat_id,newscatimage,newscatname,newsheading,newsimage,newsdes,newsdate;
private Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    StartAppAd.init(this, getString(R.string.startapp_dev_id), getString(R.string.startapp_app_id));
    setContentView(R.layout.newsdetail);
    StartAppAd.showSlider(this);
    mAdView = (AdView) findViewById(R.id.adView);
    mAdView.loadAd(new AdRequest.Builder().build());

    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");

    db = new DatabaseHandler(this);
    //setTitle(Constant.CATEGORY_TITLE);
    Intent i=getIntent();

    position=i.getIntExtra("POSITION", 0);
    allArrayNewsCId=i.getStringArrayExtra("CATEGORY_ITEM_CID");
    allArrayNewsCatName=i.getStringArrayExtra("CATEGORY_ITEM_NAME");
    allArrayNewsCatImage=i.getStringArrayExtra("CATEGORY_ITEM_IMAGE");
    allArrayNewsCatId=i.getStringArrayExtra("CATEGORY_ITEM_CAT_ID");
    allArrayNewsImage=i.getStringArrayExtra("CATEGORY_ITEM_NEWSIMAGE");
    allArrayNewsHeading=i.getStringArrayExtra("CATEGORY_ITEM_NEWSHEADING");
    allArrayNewsDes=i.getStringArrayExtra("CATEGORY_ITEM_NEWSDESCRI");
    allArrayNewsDate=i.getStringArrayExtra("CATEGORY_ITEM_NEWSDATE");


    //TOTAL_IMAGE=allArraynews.length-1;
    viewpager=(ViewPager)findViewById(R.id.news_slider);
    imageLoader=new ImageLoader(getApplicationContext());

    ImagePagerAdapter adapter = new ImagePagerAdapter();
    viewpager.setAdapter(adapter);

    boolean found = false;
    int j1=0;
    for(int i1=0;i1<allArrayNewsCatId.length;i1++)
    {
        if(allArrayNewsCatId[i1].contains(String.valueOf(position)))
        {
            found=true;
            j1=i1;
            break; 
        }
    }
    if(found)
    {
        viewpager.setCurrentItem(j1);
    }

    viewpager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // TODO Auto-generated method stub

            position=viewpager.getCurrentItem();
            newscat_id=allArrayNewsCatId[position];

            List<Pojo> pojolist=db.getFavRow(newscat_id);
            if(pojolist.size()==0)
            {
                menu.getItem(2).setIcon(getResources().getDrawable(R.drawable.ic_star_outline_white_48dp));
            }
            else
            {   
                if(pojolist.get(0).getCatId().equals(newscat_id))
                {
                    menu.getItem(2).setIcon(getResources().getDrawable(R.drawable.ic_star_white_48dp));
                }
            }
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int position) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPageScrollStateChanged(int position) {
            // TODO Auto-generated method stub

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.news_menu, menu);
    this.menu = menu;
    FirstFav();
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem)
{       
    switch (menuItem.getItemId()) 
    {
    case android.R.id.home: 
        onBackPressed();
        return true;

    case R.id.menu_back:
        position=viewpager.getCurrentItem();
        position--;
        if (position < 0) {
            position = 0;
        }
        viewpager.setCurrentItem(position);
        return true;  

    case R.id.menu_next:

        position=viewpager.getCurrentItem();
        position++;
        if (position == TOTAL_IMAGE) {
            position = TOTAL_IMAGE;
        }
        viewpager.setCurrentItem(position);
        return true;

    case R.id.menu_fav:

        position=viewpager.getCurrentItem();
        newscat_id=allArrayNewsCatId[position];

        List<Pojo> pojolist=db.getFavRow(newscat_id);
        if(pojolist.size()==0)
        {
            AddtoFav(position);//if size is zero i.e means that record not in database show add to favorite 
        }
        else
        {   
            if(pojolist.get(0).getCatId().equals(newscat_id))
            {
                RemoveFav(position);
            }
        }
        return true;

    case R.id.menu_share:

        position=viewpager.getCurrentItem();
        newsheading=allArrayNewsHeading[position];
        newsdes=allArrayNewsDes[position];
        String formattedString=android.text.Html.fromHtml(newsdes).toString();
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, newsheading+"\n"+formattedString+"\n"+" I Would like to share this with you. Here You Can Download This Application from PlayStore "+"https://play.google.com/store/apps/details?id="+getPackageName());
        sendIntent.setType("text/plain");
        startActivity(sendIntent); 

        return true;

    default:
        return super.onOptionsItemSelected(menuItem);
    }

}
public  String RemoveTag(String html){

    html=html.replaceAll("<br/>","");

    return html;
}
public void AddtoFav(int position)
{
    newscat_id=allArrayNewsCatId[position];
    newscid=allArrayNewsCId[position];
    newscatname=allArrayNewsCatName[position];
    //newscatimage=allArrayNewsCatImage[position];
    newsheading=allArrayNewsHeading[position];
    newsimage=allArrayNewsImage[position];
    newsdes=allArrayNewsDes[position];
    newsdate=allArrayNewsDate[position];

    db.AddtoFavorite(new Pojo(newscat_id,newscid,newscatname,newsheading,newsimage,newsdes,newsdate));
    Toast.makeText(getApplicationContext(), "Added to Favorite", Toast.LENGTH_SHORT).show();
    menu.getItem(2).setIcon(getResources().getDrawable(R.drawable.ic_star_white_48dp));
}

//remove from favorite
public void RemoveFav(int position)
{
    newscat_id=allArrayNewsCatId[position];
    db.RemoveFav(new Pojo(newscat_id));
    Toast.makeText(getApplicationContext(), "Removed from Favorite", Toast.LENGTH_SHORT).show();
    menu.getItem(2).setIcon(getResources().getDrawable(R.drawable.ic_star_outline_white_48dp));

}

public void FirstFav()
{
    int first=viewpager.getCurrentItem();
    String Image_id=allArrayNewsCatId[first];

    List<Pojo> pojolist=db.getFavRow(Image_id);
    if(pojolist.size()==0)
    {
        menu.getItem(2).setIcon(getResources().getDrawable(R.drawable.ic_star_outline_white_48dp));

    }
    else
    {   
        if(pojolist.get(0).getCatId().equals(Image_id))
        {
            menu.getItem(2).setIcon(getResources().getDrawable(R.drawable.ic_star_white_48dp));

        }

    }
}

private class ImagePagerAdapter extends PagerAdapter {

    private LayoutInflater inflater;

    public ImagePagerAdapter() {
        // TODO Auto-generated constructor stub

        inflater = getLayoutInflater();
    }

    @Override
    public int getCount() {
        return allArrayNewsCatId.length;

    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        View imageLayout = inflater.inflate(R.layout.newpager_item, container, false);
        assert imageLayout != null;

        ImageView news_imageview=(ImageView)imageLayout.findViewById(R.id.image_news);
        TextView txt_newstitle=(TextView)imageLayout.findViewById(R.id.text_newstitle);
        TextView txt_newsdate=(TextView)imageLayout.findViewById(R.id.text_newsdate);
        //TextView txt_newsdes=(TextView)imageLayout.findViewById(R.id.text_newsdes);
        WebView webnewsdes=(WebView)imageLayout.findViewById(R.id.webView_newsdes);

        imageLoader.DisplayImage(Constant.SERVER_IMAGE_NEWSLISTDETAILS+allArrayNewsImage[position], news_imageview);

        txt_newstitle.setText(allArrayNewsHeading[position]);
        txt_newsdate.setText(allArrayNewsDate[position]);
        //txt_newsdes.setText(allArrayNewsDes[position]);
        webnewsdes.setBackgroundColor(Color.parseColor(getString(R.color.background_color)));
        webnewsdes.setFocusableInTouchMode(false);
        webnewsdes.setFocusable(false);
        webnewsdes.getSettings().setDefaultTextEncodingName("UTF-8");

        String mimeType = "text/html; charset=UTF-8";
        String encoding = "utf-8";
        String htmlText = allArrayNewsDes[position];

        String text = "<html><head>"
                + "<style type=\"text/css\">body{color: #525252;}"
                + "</style></head>"
                + "<body>"                          
                +  htmlText
                + "</body></html>";

        webnewsdes.loadData(text, mimeType, encoding);

        container.addView(imageLayout, 0);
        return imageLayout;

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }
}
@Override
protected void onPause() {
    //mAdView.pause();
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();
    //mAdView.resume();
}

@Override
protected void onDestroy() {
    //mAdView.destroy();
    super.onDestroy();
}
}

0 个答案:

没有答案