java - ClassCast Expcetion in Bar char using MPAndroidChart jar -


i new in website worked on chart technology when deploy code , run give class cast exception . there not error on code . please 1 me . find below main activity classand main.xml.

public class mainactivity extends activity { private linearlayout mainlayout; private piechart mchart; // we're going display pie chart smartphones martket shares private float[] ydata = { 5, 10, 15, 30, 40 }; private string[] xdata = { "sony", "huawei", "lg", "apple", "samsung" };   @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mainlayout = (linearlayout) findviewbyid(r.id.mainlayout); mchart = new piechart(this); // add pie chart main layout mainlayout.addview(mchart); mainlayout.setbackgroundcolor(color.parsecolor("#55656c"));  // configure pie chart mchart.setusepercentvalues(true); mchart.setdescription("smartphones market share");  // enable hole , configure mchart.setdrawholeenabled(true); mchart.setholecolortransparent(true); mchart.setholeradius(7); mchart.settransparentcircleradius(10);  // enable rotation of chart touch mchart.setrotationangle(0); mchart.setrotationenabled(true);  // set chart value selected listener mchart.setonchartvalueselectedlistener(new onchartvalueselectedlistener() {    @override   public void onvalueselected(entry e, int datasetindex, highlight h) {     // display msg when value selected     if (e == null)       return;      toast.maketext(mainactivity.this,       xdata[e.getxindex()] + " = " + e.getval() + "%", toast.length_short).show();   }    @override   public void onnothingselected() {    } });  // add data adddata();  // customize legends legend l = mchart.getlegend(); l.setposition(legendposition.right_of_chart); l.setxentryspace(7); l.setyentryspace(5); }  private void adddata() { arraylist<entry> yvals1 = new arraylist<entry>();  (int = 0; < ydata.length; i++)   yvals1.add(new entry(ydata[i], i));  arraylist<string> xvals = new arraylist<string>();  (int = 0; < xdata.length; i++)   xvals.add(xdata[i]);  // create pie data set piedataset dataset = new piedataset(yvals1, "market share"); dataset.setslicespace(3); dataset.setselectionshift(5);  // add many colors arraylist<integer> colors = new arraylist<integer>();  (int c : colortemplate.vordiplom_colors)   colors.add(c);  (int c : colortemplate.joyful_colors)   colors.add(c);  (int c : colortemplate.colorful_colors)   colors.add(c);  (int c : colortemplate.liberty_colors)   colors.add(c);  (int c : colortemplate.pastel_colors)   colors.add(c);  colors.add(colortemplate.getholoblue()); dataset.setcolors(colors);  // instantiate pie data object piedata data = new piedata(xvals, dataset); data.setvalueformatter(new percentformatter()); data.setvaluetextsize(11f); data.setvaluetextcolor(color.gray);  mchart.setdata(data);  // undo highlights mchart.highlightvalues(null);  // update pie chart mchart.invalidate(); }  } 

and activity_main.xml

 <linearlayout   xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="vertical"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:id="@+id/mainlayout"> </linearlayout> 

but chart size small dont no why ? how can set chart size bigger . in advance

you casting linearlayout (xml) relativelayout (in activity). of couse cannot , result in exception described.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -