Trying to convert kml to geojson and getting ArrayIndexOutOfBoundsException with geotools - geojson
I am trying to convert a kml to geojson with geotools 20.5 and i am getting ArrayIndexOutOfBoundsException.
The file i am trying to convert can be converted on other frameworks correctly but on geotools i had this error.
I am using geotools 20.5 and java 8.
Can someone help me?
My code:
try {
reader = new FileInputStream("file.kml");
PullParser parser = new PullParser(new KMLConfiguration(), reader,
SimpleFeature.class);
FeatureJSON fjson = new FeatureJSON();
FileWriter tmp = new FileWriter("file.geojson");
BufferedWriter writer = new BufferedWriter(tmp);
ArrayList<SimpleFeature> features = new ArrayList<>();
SimpleFeature simpleFeature = (SimpleFeature) parser.parse();
while (simpleFeature != null) {
features.add(simpleFeature);
simpleFeature = (SimpleFeature) parser.parse();
}
SimpleFeatureCollection fc = DataUtilities.collection(features);
fjson.writeFeatureCollection(fc, writer);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
The Error:
nov 05, 2019 10:34:58 AM org.geotools.feature.DefaultFeatureCollection add
ADVERTÊNCIA: Feature Collection contains a heterogeneous mix of features
nov 05, 2019 10:34:58 AM org.geotools.feature.DefaultFeatureCollection add
ADVERTÊNCIA: Feature Collection contains a heterogeneous mix of features
java.lang.ArrayIndexOutOfBoundsException: 12
at org.geotools.feature.simple.SimpleFeatureImpl.getAttribute(SimpleFeatureImpl.java:179)
at org.geotools.geojson.feature.FeatureJSON$FeatureEncoder.toJSONString(FeatureJSON.java:603)
at org.geotools.geojson.feature.FeatureJSON$FeatureCollectionEncoder.writeJSONString(FeatureJSON.java:663)
at org.json.simple.JSONValue.writeJSONString(Unknown Source)
at org.json.simple.JSONObject.writeJSONString(Unknown Source)
at org.geotools.geojson.GeoJSONUtil.encode(GeoJSONUtil.java:276)
at org.geotools.geojson.feature.FeatureJSON.writeFeatureCollection(FeatureJSON.java:311)
at br.gov.serpro.dnit.sgpd.managedbean.util.KmlUtil.main(KmlUtil.java:65)
my file:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="FILEP" id="FILEP">
<SimpleField name="descriptio" type="string"></SimpleField>
<SimpleField name="timestamp" type="string"></SimpleField>
<SimpleField name="begin" type="string"></SimpleField>
<SimpleField name="end" type="string"></SimpleField>
<SimpleField name="altitudeMo" type="string"></SimpleField>
<SimpleField name="tessellate" type="string"></SimpleField>
<SimpleField name="extrude" type="string"></SimpleField>
<SimpleField name="visibility" type="string"></SimpleField>
<SimpleField name="drawOrder" type="string"></SimpleField>
<SimpleField name="icon" type="string"></SimpleField>
<SimpleField name="Vertice" type="float"></SimpleField>
<SimpleField name="N" type="float"></SimpleField>
<SimpleField name="E" type="float"></SimpleField>
<SimpleField name="Name_2" type="string"></SimpleField>
<SimpleField name="descript_2" type="string"></SimpleField>
<SimpleField name="timestam_2" type="string"></SimpleField>
<SimpleField name="begin_2" type="string"></SimpleField>
<SimpleField name="end_2" type="string"></SimpleField>
<SimpleField name="altitude_2" type="string"></SimpleField>
<SimpleField name="tessella_2" type="string"></SimpleField>
<SimpleField name="extrude_2" type="string"></SimpleField>
<SimpleField name="visibili_2" type="string"></SimpleField>
<SimpleField name="drawOrde_2" type="string"></SimpleField>
<SimpleField name="icon_2" type="string"></SimpleField>
<SimpleField name="Vertice_2" type="float"></SimpleField>
<SimpleField name="N_2" type="float"></SimpleField>
<SimpleField name="E_2" type="float"></SimpleField>
</Schema>
<Folder><name>FILEP</name>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#FILEP">
<SimpleData name="tessellate">-1</SimpleData>
<SimpleData name="extrude">0</SimpleData>
<SimpleData name="visibility">-1</SimpleData>
<SimpleData name="Vertice">99.000000000000000</SimpleData>
<SimpleData name="N">8183148.594999999700000</SimpleData>
<SimpleData name="E">745077.081499999970000</SimpleData>
<SimpleData name="tessella_2">-1</SimpleData>
<SimpleData name="extrude_2">0</SimpleData>
<SimpleData name="visibili_2">-1</SimpleData>
<SimpleData name="Vertice_2">191.000000000000000</SimpleData>
<SimpleData name="N_2">8210502.734000000200000</SimpleData>
<SimpleData name="E_2">736058.699299999980000</SimpleData>
</SchemaData></ExtendedData>
<Polygon><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><altitudeMode>relativeToGround</altitudeMode><coordinates>-54.7917363536269,-16.1742594701822 -54.7895814786832,-16.1734821399515 -54.7895800001009,-16.1734859993162 -54.7917363536269,-16.1742594701822</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<name>Lote 1.1</name>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#FILEP">
<SimpleData name="tessellate">-1</SimpleData>
<SimpleData name="extrude">0</SimpleData>
<SimpleData name="visibility">-1</SimpleData>
<SimpleData name="Vertice">99.000000000000000</SimpleData>
<SimpleData name="N">8183148.594999999700000</SimpleData>
<SimpleData name="E">745077.081499999970000</SimpleData>
</SchemaData></ExtendedData>
<Polygon><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><altitudeMode>relativeToGround</altitudeMode><coordinates>-54.7029330000828,-16.418827003687 -54.7050349995717,-16.4206240055189 -54.7066909997516,-16.4186669998587 -54.7097899998139,-16.4152840050737 -54.711284000096,-16.4137840012491 -54.7155259996671,-16.4091309999561 -54.7159569996756,-16.4085860056906 -54.7164260000864,-16.4078180037582 -54.7167560002403,-16.4070890068105 -54.7170000000898,-16.4063140036972 -54.71716799977,-16.4053310064691 -54.7171859996123,-16.4043040003729 -54.7142569996992,-16.3849039995536 -54.714219000075,-16.3831400057174 -54.7143560002966,-16.3824300040174 -54.7146070001402,-16.3817500050653 -54.71507299986,-16.3809680075699 -54.7166420002163,-16.3791200011844 -54.7294440001037,-16.3653540023959 -54.7303290003941,-16.3640530055761 -54.735744,-16.354199003456 -54.7362829999685,-16.3533360017841 -54.7370200002648,-16.3524110008306 -54.7434739998639,-16.345426002351 -54.7443780000589,-16.3442420020091 -54.7452380003799,-16.3428140000797 -54.7458840000393,-16.3414490038868 -54.7474169999057,-16.3376550078664 -54.7585620001911,-16.3081250034321 -54.7593819998013,-16.3057130032081 -54.7608040000599,-16.3021880024424 -54.7683409995231,-16.2821870054936 -54.7697669996656,-16.2788180019092 -54.7760910000798,-16.2658120055877 -54.777188000237,-16.2633620029799 -54.779149000021,-16.2595250017392 -54.7795659996092,-16.2585190004681 -54.7799890001377,-16.2568250072184 -54.7834109998234,-16.2351520022125 -54.7835120001112,-16.2338919997834 -54.7834749995869,-16.2329900000154 -54.7833099997024,-16.2319180067533 -54.7808520003183,-16.2222720071977 -54.7798469999294,-16.2187010033988 -54.7796859996364,-16.2177010019671 -54.7796989996353,-16.2169960072611 -54.7812380003992,-16.2104790041366 -54.7817089997954,-16.207916001936 -54.7855579997548,-16.1919780052685 -54.7859999995245,-16.1905900033254 -54.7921979998959,-16.1744260003105 -54.7917363536269,-16.1742594701822 -54.7895800001009,-16.1734859993162 -54.7895814786832,-16.1734821399515 -54.7895699999615,-16.1734779992206 -54.783170000137,-16.1901650015924 -54.7826590000205,-16.191985000899 -54.7795909999637,-16.2046900069761 -54.7788599999872,-16.2078260046823 -54.7784839999407,-16.2099620009427 -54.7769399996402,-16.2164780005795 -54.7768780002604,-16.2177400055293 -54.7770959995268,-16.2192370022489 -54.7780970002354,-16.2227990005203 -54.7805239996236,-16.2323020024959 -54.7807069998312,-16.2337339998721 -54.7806530003063,-16.2346350009768 -54.7796580001503,-16.2410680053836 -54.7772139998481,-16.2564260020182 -54.7769069997749,-16.2576530053378 -54.7759169995376,-16.2597970009449 -54.7743950003939,-16.2627320054949 -54.7735329996322,-16.2646990079405 -54.7672499999347,-16.277618002331 -54.7658179997151,-16.2809599995937 -54.758144000203,-16.3013210010215 -54.7571670001441,-16.303667006542 -54.7559009997175,-16.3072620028212 -54.7447920002151,-16.3366950055191 -54.7432859997169,-16.3404240038616 -54.742708999522,-16.3416370066335 -54.7420549997786,-16.3427210051719 -54.7412709997459,-16.3437460057347 -54.7349009995287,-16.3506340073675 -54.7339589999036,-16.3518160028645 -54.733309000119,-16.3528480065132 -54.7279190004019,-16.3626599997099 -54.7272100000687,-16.3637130028044 -54.7145129997873,-16.3773530021394 -54.7128520003898,-16.3793080023477 -54.7123450001003,-16.3800669997029 -54.7120129994799,-16.3807140075095 -54.7116419998058,-16.3817360064993 -54.7114329998469,-16.3828000045365 -54.7113769994761,-16.3836630077601 -54.7114639999648,-16.385185999841 -54.7143010000668,-16.4039050008073 -54.7143900001083,-16.4047160012712 -54.714286000192,-16.4056130011044 -54.7139429998633,-16.4065520004201 -54.713322000095,-16.4074510052629 -54.7045899997694,-16.4168690051387 -54.7029330000828,-16.418827003687</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<name>Lote 1.2</name>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#FILEP">
<SimpleData name="tessella_2">-1</SimpleData>
<SimpleData name="extrude_2">0</SimpleData>
<SimpleData name="visibili_2">-1</SimpleData>
<SimpleData name="Vertice_2">191.000000000000000</SimpleData>
<SimpleData name="N_2">8210502.734000000200000</SimpleData>
<SimpleData name="E_2">736058.699299999980000</SimpleData>
</SchemaData></ExtendedData>
<Polygon><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><altitudeMode>relativeToGround</altitudeMode><coordinates>-54.7917363536269,-16.1742594701822 -54.7922089999336,-16.1744290055315 -54.7938209996617,-16.1701900053446 -54.7940470003131,-16.1693140075326 -54.7941340003908,-16.1685960014647 -54.7941199996626,-16.1676940072815 -54.7939350003224,-16.1666630066868 -54.7925110002514,-16.1622500063043 -54.7925040003942,-16.1617810034919 -54.7925990000144,-16.1614320074617 -54.7930269994926,-16.1608480052903 -54.7937059998702,-16.1604610002311 -54.7973809996163,-16.1589220019762 -54.7982700001723,-16.158481002857 -54.8022849996873,-16.1558349992484 -54.8035560001701,-16.1550730046464 -54.8332190002705,-16.1352210001957 -54.8363979998726,-16.1329980068579 -54.8380640000272,-16.1319970063641 -54.8464969996475,-16.1263600076539 -54.8484350002558,-16.1254090021821 -54.8492340003468,-16.1249420055654 -54.8570829999307,-16.1197110008907 -54.8580929996083,-16.1189100034289 -54.8589340002961,-16.1179430043422 -54.85972399999,-16.1165230014504 -54.8662159998127,-16.1006880035181 -54.8666899998138,-16.0992420076199 -54.867387999647,-16.0974970010668 -54.8689899996549,-16.0938380071676 -54.8717319996195,-16.0869240066956 -54.873719999521,-16.0822280066624 -54.8747899998844,-16.079422005047 -54.8753869997046,-16.0774110066516 -54.8757060002378,-16.0759370074174 -54.8759,-16.0741260051309 -54.8759159998384,-16.0723200021113 -54.8757810003674,-16.0707000042784 -54.8755039994578,-16.0690960071385 -54.8750910001775,-16.0675200054315 -54.8731150001449,-16.0622580058197 -54.8730270000878,-16.0611799999066 -54.8731909998119,-16.0602930048823 -54.8733900000749,-16.0597860010721 -54.873757000174,-16.0591580055416 -54.8814580000444,-16.0483999998769 -54.8821729998501,-16.0472170015211 -54.8827150000317,-16.0457300025457 -54.8842359996216,-16.0385130012909 -54.8845860000154,-16.0375840038308 -54.8885070001226,-16.0318600014585 -54.8889900001126,-16.0313100078803 -54.8899300003221,-16.0307230027508 -54.8978859999417,-16.0264379999814 -54.8991510001851,-16.0255870077106 -54.9026539997779,-16.0223329993815 -54.9040479997293,-16.0211300014127 -54.9116059999491,-16.0140509997868 -54.9147340001337,-16.0110170020562 -54.9153340002629,-16.0103260001817 -54.9158880003838,-16.0093850036588 -54.9161809995596,-16.0085290061173 -54.9177380003519,-16.0010910002096 -54.9181470001722,-16.0000830001473 -54.9187279997894,-15.9991700001243 -54.92523499991,-15.992183000068 -54.9270239998885,-15.9898680010555 -54.9284549998288,-15.9882140031562 -54.9329190002499,-15.9826310042419 -54.9338029999333,-15.9813890003924 -54.9353190001611,-15.9794860026873 -54.9370679997235,-15.9775199990725 -54.9414250003811,-15.9720110062388 -54.9419960001669,-15.970875001874 -54.9422859996544,-15.9696560010253 -54.9430359996107,-15.9693570053339 -54.9436990002224,-15.9692150069177 -54.9461180000472,-15.9692400070883 -54.9461319997248,-15.9689280011463 -54.9446259998902,-15.9688420064682 -54.9441319996873,-15.96868100092 -54.9435749996239,-15.9683400021668 -54.9430159999523,-15.9678280049986 -54.9429949998482,-15.967699003753 -54.9431099998527,-15.9675130056331 -54.9430280001149,-15.9670160032897 -54.9427140002326,-15.9664270069603 -54.9424819996609,-15.966486004333 -54.9422089999057,-15.966202002875 -54.9421579997093,-15.9629520022339 -54.9423149994915,-15.9626270066505 -54.942588999661,-15.9623849995062 -54.9429989996229,-15.9622560060469 -54.943641000118,-15.9622500052059 -54.9436739997101,-15.9595390016343 -54.9426650000815,-15.9595640042039 -54.9417190001236,-15.9597900018166 -54.9408989995735,-15.9602180041673 -54.9400980002731,-15.9609700064163 -54.9396289999933,-15.9617480063748 -54.9393789995464,-15.9625820068765 -54.9393249998396,-15.9632910075316 -54.9393810001848,-15.9649400067881 -54.9390790002001,-15.9649940024099 -54.9385820000376,-15.9649260038096 -54.9373350001855,-15.9642440069293 -54.937143000049,-15.9645160038586 -54.9382380003222,-15.9653269996369 -54.9383609999695,-15.9655400047613 -54.9385350002078,-15.9662660066783 -54.9394800002914,-15.9676930069366 -54.9394820003079,-15.9694900043374 -54.9392689997784,-15.9701800071804 -54.938962999916,-15.9706970026846 -54.9347969996021,-15.9759280032372 -54.9330899998383,-15.9778430069674 -54.9315250003736,-15.9798089996532 -54.9306500002115,-15.9810389997913 -54.926256999649,-15.9865330033011 -54.9247730003493,-15.9882520078848 -54.9231989996791,-15.9903090003603 -54.9198549998185,-15.993961007981 -54.9171739998167,-15.9967350012632 -54.9165219995898,-15.997497006295 -54.9159489997194,-15.9983230042391 -54.9153659999944,-15.9994540072115 -54.9150069997949,-16.0004720001409 -54.9134840002342,-16.007782005397 -54.9132590002368,-16.0084260045417 -54.9129520000097,-16.0088780014516 -54.909653000019,-16.0121070070789 -54.9020910003464,-16.0191900042551 -54.9007810002864,-16.0203160004128 -54.89727700017,-16.0235679996742 -54.8963449995521,-16.0241689999587 -54.8881849999514,-16.0285670064647 -54.8871169995592,-16.0292930051009 -54.8861510000528,-16.0303910038224 -54.8821339996596,-16.0362700022902 -54.8818149994902,-16.0369230074527 -54.8815420001116,-16.037747004198 -54.8800190003427,-16.0449770035663 -54.8796360003403,-16.0460650055883 -54.879100999669,-16.0469310002938 -54.8714400002761,-16.0576320029156 -54.8709329997891,-16.0584710067496 -54.8705179999957,-16.0594770060334 -54.8703050001203,-16.0603560022655 -54.8702259996582,-16.0610740077299 -54.8702410001438,-16.0619770010153 -54.870345000364,-16.0626920023187 -54.8706159995148,-16.063652005651 -54.8724080001386,-16.0683060045964 -54.8727719999225,-16.0697070012208 -54.873010999579,-16.071134004702 -54.8731199996537,-16.072575003067 -54.8730979999925,-16.0740200025374 -54.8729550000146,-16.0753989993192 -54.8726819996942,-16.0766960017518 -54.8721819997228,-16.0784169998499 -54.8710159999692,-16.0814700047165 -54.8692869995768,-16.0855260031509 -54.8663839996935,-16.0928380032664 -54.8648179995951,-16.0964090072594 -54.8640360000779,-16.0983650067959 -54.863602999897,-16.0997060030276 -54.857052000037,-16.1156579997902 -54.8566540002702,-16.1163640040636 -54.856183000342,-16.1169240013657 -54.8554629995512,-16.1174990048953 -54.8482029996459,-16.1223420035287 -54.8471339997851,-16.1230080035295 -54.8450510002112,-16.1240360023776 -54.8365010003375,-16.1297450005548 -54.8349329995611,-16.1306830007023 -54.831599999663,-16.1330080016845 -54.8020919996387,-16.1527580010607 -54.8005209996253,-16.1537150011526 -54.7972820003853,-16.1558800050084 -54.7963080003236,-16.1564160056591 -54.7922299995441,-16.1581400046299 -54.7911179997587,-16.1588620057383 -54.7904979996332,-16.159536001425 -54.7900399999569,-16.1603210036527 -54.7897649997954,-16.1611829996721 -54.7896849997155,-16.1620810077988 -54.7898909999428,-16.1633270059747 -54.7912170002848,-16.1673310000546 -54.7913320002567,-16.1679950049167 -54.7913269997345,-16.1685360055641 -54.7910729997534,-16.1695890027316 -54.7895814786832,-16.1734821399515 -54.7917363536269,-16.1742594701822</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
</Folder>
</Document></kml>
my pom:
<properties>
<geotools.version>20.5</geotools.version>
</properties>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-main</artifactId>
<version>${geotools.version}</version>
<exclusions>
<exclusion>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.geotools.xsd</groupId>
<artifactId>gt-xsd-core</artifactId>
<version>${geotools.version}</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geojson</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools.xsd</groupId>
<artifactId>gt-xsd-kml</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-xml</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-api</artifactId>
<version>${geotools.version}</version>
</dependency>
The clue is in the error message "Feature Collection contains a heterogeneous mix of features". The GeoJSON writer creates the schema based on the first feature and assumes that the rest are the same.
you need to use setFeatureType to tell it what the "real" schema looks like.
I had to attach some parts manually to geojson.
this way worked for me:
private static StringWriter kmlToGeojson(InputStream input) throws XMLStreamException, IOException, SAXException {
PullParser parser = new PullParser(new KMLConfiguration(), input, SimpleFeature.class);
FeatureJSON fjson = new FeatureJSON();
StringWriter sw = new StringWriter();
ArrayList<SimpleFeature> features = new ArrayList<>();
SimpleFeature simpleFeature = (SimpleFeature) parser.parse();
sw.append("{ \"type\": \"FeatureCollection\", \"features\": [");
while (simpleFeature != null) {
SimpleFeatureType featureType = simpleFeature.getFeatureType();
fjson.setFeatureType(featureType);
fjson.writeFeature(simpleFeature, sw);
simpleFeature = (SimpleFeature) parser.parse();
if (simpleFeature != null) {
sw.append(",");
}
}
sw.append("]}");
sw.close();
return sw;
}
Related
Create a facturX with Mustang from XML String
I'm trying to build a facturx using Mustang library in an API. I have a (valid) XML string as entry #PostMapping public FxResponse createFacturX(#RequestBody XmlRequest request) throws IOException { if(request.getVersion() == null) { request.setVersion(2); } ByteArrayOutputStream output = new ByteArrayOutputStream(); log.debug("Converting to PDF/A-3u"); if ((request.getVersion() < 1) || (request.getVersion() > 2)) { throw new IllegalArgumentException("invalid version"); } PDFAConformanceLevel pdfaConformanceLevel; switch (request.getConformanceLevel()) { case "BASIC": pdfaConformanceLevel = PDFAConformanceLevel.BASIC; break; case "ACCESSIBLE": pdfaConformanceLevel = PDFAConformanceLevel.ACCESSIBLE; break; case "UNICODE": pdfaConformanceLevel = PDFAConformanceLevel.UNICODE; break; default: throw new IllegalArgumentException("invalid level"); } System.out.println(Arrays.toString(request.getPdf().getBytes(StandardCharsets.UTF_8))); byte[] xmlData = request.getXml().getBytes(StandardCharsets.UTF_8); byte[] pdfData = Base64.getDecoder().decode(request.getPdf().getBytes(StandardCharsets.UTF_8)); ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1() .setProducer("Mustang API") .setCreator("Creator ME") .setZUGFeRDVersion(request.getVersion()) .setConformanceLevel(pdfaConformanceLevel) .load(pdfData); ze.attachFile("factur-x.xml", xmlData, "text/xml", "Data"); ze.setXML(xmlData); log.debug("Attaching ZUGFeRD-Data"); ze.disableAutoClose(true); ze.export(output); byte[] bytes = output.toByteArray(); InputStream inputStream = new ByteArrayInputStream(bytes); byte[] pdfBytes = IOUtils.toByteArray(inputStream); try { Utils.facturxValidator(request.getXml()); } catch (Exception e) { e.printStackTrace(); } String encoded = Base64.getEncoder().encodeToString(pdfBytes); return new FxResponse("OK", encoded); } I do retrieve a PDF as output but i have errors while validating the PDF. On the other hand, my XML is fully valid I tried to check if pdf was compliant or not to and I also tried mustang cli to check the ouput. I do have the following failures: <xml> <info> <version>2</version> <profile>urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic</profile> <validator version="2.4.0"/> <rules> <fired>466</fired> <failed>3</failed> </rules> <duration unit="ms">5242</duration> </info> <messages> <notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ExchangedDocumentContext[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]" criterion="ram:GuidelineSpecifiedDocumentContextParameter/ram:ID = $XR-CIUS-ID">[BR-DE-21] Das Element "Specification identifier" (BT-24) soll syntaktisch der Kennung des Standards XRechnung entsprechen. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice> <notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeAgreement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SellerTradeParty[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]" criterion="ram:DefinedTradeContact">[BR-DE-2] Die Gruppe "SELLER CONTACT" (BG-6) muss übermittelt werden. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice> <notice type="27" location="/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeSettlement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SpecifiedTradeSettlementPaymentMeans[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]" criterion="not(ram:ApplicableTradeSettlementFinancialCard) and not(/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradePaymentTerms/ram:DirectDebitMandateID or /rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:CreditorReferenceID or ram:PayerPartyDebtorFinancialAccount/ram:IBANID)">[BR-DE-23-b] Wenn BT-81 "Payment means type code" einen Schlüssel für Überweisungen enthält (30, 58), dürfen BG-18 und BG-19 nicht übermittelt werden. (From /xslt/XR_21/XRechnung-CII-validation.xslt)</notice> </messages> <summary status="valid"/> </xml> My questions are the following : How can I solve those failure Are those errors have impact on my facturX ? I do validated them on a test site, It's not on production
I noticed that i forgot to set facturx profile, for example, EXTENDED: ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1() .setProducer("Mustang API") .setCreator("Creator ME") .setProfile("EXTENDED"); .setZUGFeRDVersion(request.getVersion()) .setConformanceLevel(pdfaConformanceLevel) .load(pdfData); ze.attachFile("factur-x.xml", xmlData, "text/xml", "Data"); ze.setXML(xmlData) Available values are the following: {"MINIMUM", new Profile("MINIMUM", "urn:factur-x.eu:1p0:minimum")}, {"BASICWL", new Profile("BASICWL", "urn:factur-x.eu:1p0:basicwl")}, {"BASIC", new Profile("BASIC", "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic")}, {"EN16931", new Profile("EN16931", "urn:cen.eu:en16931:2017")}, {"EXTENDED", new Profile("EXTENDED", "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended")}, {"XRECHNUNG", new Profile("XRECHNUNG", "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.1")} It works fine now !
Ionic3 in iOS can't stream coordinates to my API when the app is in the background
I'm using Ionic 3 and this cordova plugin mauron85/cordova-plugin-background-geolocation but the app doesn't stream coordinates when it's in the background in iOS. It works in Android, iOS emulator but not in a real iPhone. Also, the url option stops streaming after 1s My code so far: /** * * #param {boolean} status * #param {number} stepOn */ private registerCoords(status: boolean, stepOn?: number): void { let step: number = stepOn ? stepOn : 1; if (!STATIC.GEO_INTERVAL && status) { STATIC.GEO_INTERVAL = setInterval((() => { this.currentCoords = this.geolocationService.getCoords(); if (!this.isNetWork) { this.functions.f_alertToast('Network connection lost', 0); return this.registerCoords(false); } if (!this.currentCoords && !this.isProcessPicture) { this.geoLocationEvent = false; this.isGeoLocation = false; console.warn('[HomePage] registerCoords() -> setInterval() [GPS connection lost!!]'); } else if (this.currentCoords) { this.geoLocationEvent = true; this.isGeoLocation = true; } this.saveCoords(this.currentCoords, step); step = 1; }).bind(this), STATIC.GEO_TIMEOUT); this.finishLoad(); } if (status === false) { clearInterval(STATIC.GEO_INTERVAL); STATIC.GEO_INTERVAL = null; this.checkGeolocation(); } } config.xml <plugin name="cordova-plugin-mauron85-background-geolocation" spec="2.3.5"> <variable name="ICON" value="#mipmap/icon" /> <variable name="SMALL_ICON" value="#mipmap/icon" /> <variable name="ACCOUNT_NAME" value="#string/app_name" /> <variable name="ACCOUNT_LABEL" value="#string/app_name" /> <variable name="ACCOUNT_TYPE" value="$PACKAGE_NAME.account" /> <variable name="CONTENT_AUTHORITY" value="$PACKAGE_NAME" /> <variable name="GOOGLE_PLAY_SERVICES_VERSION" value="11+" /> <variable name="ANDROID_SUPPORT_LIBRARY_VERSION" value="23+" /> </plugin> <plugin name="cordova-plugin-geolocation" spec="2.4.3"> <variable name="GEOLOCATION_USAGE_DESCRIPTION" value="..." /> </plugin> package.json "#ionic-native/geolocation": "4.9.0", "cordova-plugin-geolocation": "2.4.3", "cordova-plugin-mauron85-background-geolocation": "2.3.5",
Android thing: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager;
Android thing run time exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager; Manifest file: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.androidthings.simplepio"> <application android:allowBackup="true" android:icon="#android:drawable/sym_def_app_icon" android:name="android.support.multidex.MultiDexApplication" android:label="#string/app_name"> <uses-library android:name="com.google.android.things"/> <activity android:name=".BlinkActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- Launch activity automatically on boot --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.IOT_LAUNCHER"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application> </manifest> Error logcat: 01-01 00:00:53.293 1326-1326/com.example.androidthings.simplepio E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.androidthings.simplepio, PID: 1326 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager; at com.example.androidthings.simplepio.BlinkActivity.onCreate(BlinkActivity.java:51) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Activity.performCreate(Activity.java:6991) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.things.pio.PeripheralManager" on path: DexPathList[[zip file "/system/framework/com.google.android.things.jar", zip file "/data/app/com.example.androidthings.simplepio-y-kMOBHPpOQbWFdWf4QeXw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.androidthings.simplepio-y-kMOBHPpOQbWFdWf4QeXw==/lib/arm, /system/lib, /vendor/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at com.example.androidthings.simplepio.BlinkActivity.onCreate(BlinkActivity.java:51) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Activity.performCreate(Activity.java:6991) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteIncode,807) 01-01 00:00:53.446 1326-1326/com.example.androidthings.simplepio I/Process: Sending signal. PID: 1326 SIG: 9 This is my code, I got this from this Link, I just clone it nothing changed. public class BlinkActivity extends Activity { private static final String TAG = BlinkActivity.class.getSimpleName(); private static final int INTERVAL_BETWEEN_BLINKS_MS = 1000; private Handler mHandler = new Handler(); private Gpio mLedGpio; private boolean mLedState = false; #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "Starting BlinkActivity"); try { String pinName = BoardDefaults.getGPIOForLED(); mLedGpio = PeripheralManager.getInstance().openGpio(pinName); mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW); Log.i(TAG, "Start blinking LED GPIO pin"); // Post a Runnable that continuously switch the state of the GPIO, blinking the // corresponding LED mHandler.post(mBlinkRunnable); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); } } #Override protected void onDestroy() { super.onDestroy(); // Remove pending blink Runnable from the handler. mHandler.removeCallbacks(mBlinkRunnable); // Close the Gpio pin. Log.i(TAG, "Closing LED GPIO pin"); try { mLedGpio.close(); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); } finally { mLedGpio = null; } } private Runnable mBlinkRunnable = new Runnable() { #Override public void run() { // Exit Runnable if the GPIO is already closed if (mLedGpio == null) { return; } try { // Toggle the GPIO state mLedState = !mLedState; mLedGpio.setValue(mLedState); Log.d(TAG, "State set to " + mLedState); // Reschedule the same runnable in {#INTERVAL_BETWEEN_BLINKS_MS} milliseconds mHandler.postDelayed(mBlinkRunnable, INTERVAL_BETWEEN_BLINKS_MS); } catch (IOException e) { Log.e(TAG, "Error on PeripheralIO API", e); } } }; } If any solve this problem, Please help me.
I solved this issue by updating my Android Things. I used the new setup utility tool to flash my Android Things: https://partner.android.com/things/console/u/1/#/tools
I don't know if this may help, but i resolved it by founding out that in my build.gradle com.google.android.things:androidthings:+ was only set as a dependency to compile (compileOnly) and not to be redistributed. I fixed it by changing it in implementation 'com.google.android.things:androidthings:+'.
DOM parsing error in RSS FEED
I need to parse the this xml file and need to display in the list view but I got the problem while running this code. Any one please help me over come this problem Thank you in advance This is XML file from the source http://purl.org/dc/elements/1.1/" version="2.0" <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title>MobileNations</title> <description> Mobile Nations brings to you the very best of Android Central, CrackBerry.com, PreCentral.net, TiPb.com, and WPCentral </description> <link>http://www.mobilenations.com/</link> <language>en-us</language> <lastBuildDate>Wed, 07 Aug 2013 06:15:01 -0400</lastBuildDate> <pubDate>Wed, 07 Aug 2013 06:15:01 -0400</pubDate> <item> <title> AT&T activates new 4G LTE markets, expands coverage in others </title> <description> <p class="rtecenter"><img alt="AT&T" class="lightbox2 imagecache-w680h550 aligncenter" src="http://cdn.androidcentral.com/sites/androidcentral.com/files/imagecache/w680h550/postimages/108579/att-store-2.jpg" /></p> <h3> Six new markets, expanded coverage in Washington, D.C. and San Francisco areas</h3> <p>AT&T sends word that it's switched on 4G LTE service in six new markets, while expanding coverage in two major cities.</p> <p>From today, AT&T LTE should be available in —</p> <p>read more</p> </description> <link> http://www.androidcentral.com/att-activates-new-4g-lte-markets-expands-coverage-others </link> <pubDate>Wed, 07 Aug 2013 09:48:24 +0000</pubDate> <category domain="http://www.androidcentral.com/articles/news">News</category> <category domain="http://www.androidcentral.com/tags/4g">4g</category> <category domain="http://www.androidcentral.com/tags/att-0">at&t</category> <category domain="http://www.androidcentral.com/tags/lte">lte</category> <guid isPermaLink="false">32622 at http://www.androidcentral.com</guid> <comments> http://www.androidcentral.com/att-activates-new-4g-lte-markets-expands-coverage-others#comments </comments> <dc:creator>Alex Dobie</dc:creator> </item> My DOM parser code is package com.wfwf.everestnewsapp.parser; import java.net.MalformedURLException; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.jsoup.Jsoup; import org.jsoup.select.Elements; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import android.util.Log; public class DOMParser { private RSSFeed _feed = new RSSFeed(); public RSSFeed parseXml(String xml) { URL url = null; try { url = new URL(xml); } catch (MalformedURLException e1) { e1.printStackTrace(); } try { // Create required instances DocumentBuilderFactory dbf; dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); // Parse the xml Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); // Get all <item> tags. NodeList nl = doc.getElementsByTagName("item"); int length = nl.getLength(); Log.i("this is the test message"+length, xml); for (int i = 0; i < length; i++) { Node currentNode = nl.item(i); RSSItem _item = new RSSItem(); NodeList nchild = currentNode.getChildNodes(); int clength = nchild.getLength(); Log.i("this is the test message total child nodes"+clength, xml); // Get the required elements from each Item // Ishwor changed the code j=0 and j= j+1 for (int j = 0; j < clength; j = j + 1) { Log.i("first child node name is"+nchild.item(j).getNodeName(), xml); Node thisNode = nchild.item(j); String theString = null; //ishwor changed as if (thisNode != null && thisNode.getFirstChild() != null) { theString = thisNode.getFirstChild().getNodeValue(); } if (theString != null) { String nodeName = thisNode.getNodeName(); /* String nodeName = thisNode.getNodeName(); //theString = nchild.item(j).getFirstChild().getNodeValue(); if(nchild.item(j).getFirstChild().getNodeValue()!=null){ //if (theString != null) { //String nodeName = thisNode.getNodeName(); */ if ("title".equals(nodeName)) { // Node name is equals to 'title' so set the Node // value to the Title in the RSSItem. _item.setTitle(theString); Log.i("this is the test message"+theString, xml); } else if ("description".equals(nodeName)) { _item.setDescription(theString); Log.i("this is the test message"+theString, xml); // Parse the html description to get the image url String html = theString; org.jsoup.nodes.Document docHtml = Jsoup.parse(html); Elements imgEle = docHtml.select("img"); _item.setImage(imgEle.attr("src")); } else if ("pubDate".equals(nodeName)) { // We replace the plus and zero's in the date with // empty string String formatedDate = theString.replace(" +0000", ""); _item.setDate(formatedDate); } } } // add item to the list _feed.addItem(_item); } } catch (Exception e) { } // Return the final feed once all the Items are added to the RSSFeed // Object(_feed). return _feed; } } MY log cat Error is 08-08 12:52:55.059: W/dalvikvm(3484): threadid=11: thread exiting with uncaught exception (group=0x41a692a0) 08-08 12:52:55.064: E/AndroidRuntime(3484): FATAL EXCEPTION: AsyncTask #1 08-08 12:52:55.064: E/AndroidRuntime(3484): java.lang.RuntimeException: An error occured while executing doInBackground() 08-08 12:52:55.064: E/AndroidRuntime(3484): at android.os.AsyncTask$3.done(AsyncTask.java:299) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 08-08 12:52:55.064: E/AndroidRuntime(3484): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.lang.Thread.run(Thread.java:856) 08-08 12:52:55.064: E/AndroidRuntime(3484): Caused by: java.lang.NoClassDefFoundError: org.jsoup.Jsoup 08-08 12:52:55.064: E/AndroidRuntime(3484): at com.wfwf.everestnewsapp.parser.DOMParser.parseXml(DOMParser.java:102) 08-08 12:52:55.064: E/AndroidRuntime(3484): at com.wfwf.everestnewsapp.Splash$AsyncLoadXMLFeed.doInBackground(Splash.java:131) 08-08 12:52:55.064: E/AndroidRuntime(3484): at com.wfwf.everestnewsapp.Splash$AsyncLoadXMLFeed.doInBackground(Splash.java:1) 08-08 12:52:55.064: E/AndroidRuntime(3484): at android.os.AsyncTask$2.call(AsyncTask.java:287) 08-08 12:52:55.064: E/AndroidRuntime(3484): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 08-08 12:52:55.064: E/AndroidRuntime(3484): ... 5 more
Try This Example... import java.net.URL; import java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.text.Html; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class XMLParsingDOMExample extends Activity { ArrayList<String> title; ArrayList<String> description; ArrayList<String> pubDate; ItemAdapter adapter1; #Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView list = (ListView) findViewById(R.id.list); title = new ArrayList<String>(); description = new ArrayList<String>(); pubDate = new ArrayList<String>(); try { URL url = new URL( "Your URL"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName("item"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); Element fstElmnt = (Element) node; NodeList nameList = fstElmnt.getElementsByTagName("title"); Element nameElement = (Element) nameList.item(0); nameList = nameElement.getChildNodes(); Log.v("title--", ""+ ((Node) nameList.item(0)).getNodeValue()); title.add(""+ ((Node) nameList.item(0)).getNodeValue()); NodeList websiteList = fstElmnt.getElementsByTagName("description"); Element websiteElement = (Element) websiteList.item(0); websiteList = websiteElement.getChildNodes(); Log.v("description--", ""+ ((Node) websiteList.item(0)).getNodeValue()); description.add(""+ ((Node) websiteList.item(0)).getNodeValue()); NodeList websiteList1 = fstElmnt.getElementsByTagName("pubDate"); Element websiteElement1 = (Element) websiteList1.item(0); websiteList1 = websiteElement1.getChildNodes(); pubDate.add(""+ ((Node) websiteList1.item(0)).getNodeValue()); } } catch (Exception e) { System.out.println("XML Pasing Excpetion = " + e); } adapter1 = new ItemAdapter(this); list.setAdapter(adapter1); } class ItemAdapter extends BaseAdapter { final LayoutInflater mInflater; private class ViewHolder { public TextView title_text; public TextView des_text; public TextView date_text; } public ItemAdapter(Context context) { // TODO Auto-generated constructor stub super(); mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } //#Override public int getCount() { return title.size(); } //#Override public Object getItem(int position) { return position; } //#Override public long getItemId(int position) { return position; } //#Override public View getView(final int position, View convertView, ViewGroup parent) { View view = convertView; final ViewHolder holder; if (convertView == null) { view = mInflater.inflate(R.layout.mainpage_listitem_activity, parent, false); holder = new ViewHolder(); holder.title_text = (TextView) view.findViewById(R.id.title_text); holder.des_text = (TextView) view.findViewById(R.id.des_text); holder.date_text = (TextView) view.findViewById(R.id.date_text); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } holder.title_text.setText(""+title.get(position)); holder.des_text.setText(""+Html.fromHtml(description.get(position))); holder.date_text.setText(""+pubDate.get(position)); return view; } } }
attach a custom value with asp.net chart
I have made a asp.net chart with some data from DB on x-axis and y-axis like this. and now i want to attach a custom value of Current Day with the month of DEC like this Please any one tell me how can i acheive this . Plz Help ! Here is My chart code <asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource11" Compression="5" BackImageAlignment="Top" Palette="None" Width="400px" Height="250px"> <Series> <asp:Series Name="2011-12" XValueMember="MON" YValueMembers="CRSH_11_12" ChartType="Spline" YValuesPerPoint="2" IsXValueIndexed="True" MarkerSize="7" MarkerStyle="Square" ChartArea="ChartArea1" LabelFormat="#,###,###" Color="Black" YValueType="Double" Legend="Legend1" LegendToolTip="#TOTAL{#,###,###,###}"> <EmptyPointStyle LabelFormat="#,###,###" /> </asp:Series> <asp:Series Name="2012-13" XValueMember="MON" YValueMembers="CRSH_12_13" ChartType="Spline" YValuesPerPoint="2" IsXValueIndexed="True" MarkerSize="7" MarkerStyle="Diamond" ChartArea="ChartArea1" LabelFormat="#,###,###" Color="0, 192, 0" YValueType="Double" Legend="Legend1" LegendToolTip="#TOTAL{#,###,###,###}"> <EmptyPointStyle LabelFormat="#,###,###" /> </asp:Series> <asp:Series Name="Target" XValueMember="MON" YValueMembers="CAN_TRG" ChartType="Spline" YValuesPerPoint="2" IsXValueIndexed="True" MarkerSize="7" MarkerStyle="Triangle" ChartArea="ChartArea1" LabelFormat="#,###,###" Color="Blue" YValueType="Double" Legend="Legend1" LegendToolTip="#TOTAL{#,###,###,###}"> <EmptyPointStyle LabelFormat="#,###,###" /> </asp:Series> <asp:Series Name="Todate" XValueMember="MON" YValueMembers="YTD_CRSH" ChartType="Spline" BorderWidth="1" YValuesPerPoint="2" IsXValueIndexed="True" MarkerStyle="None" ChartArea="ChartArea1" Color="Red" YValueType="Double" Legend="Legend1" > </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1" AlignmentOrientation="All"> <AxisY Title="Crushing (MT)" TitleForeColor="3, 91, 172" TitleFont="Arial, 8.25pt"> <MajorGrid LineColor="217, 239, 253" /> <LabelStyle Format="#,###,###" /> </AxisY> <AxisX LineColor="Maroon" TitleFont="Tahoma, 8pt" Title="Month" TitleForeColor="3, 91, 172"> <MajorGrid LineColor="217, 239, 253" /> </AxisX> </asp:ChartArea> </ChartAreas> <Legends> <asp:Legend Alignment="Far" Docking="Bottom" Name="Legend1"> </asp:Legend> </Legends> <Titles> <asp:Title Font="Microsoft Sans Serif, 10pt, style=Bold" ForeColor="3, 91, 172" Name="Title1" Text="Crushing"> </asp:Title> </Titles> </asp:Chart>
Handle the Customize event of Chart control. private void chart1_Customize(object sender, EventArgs e) { foreach (var xAxisLabel in chart1.ChartAreas[0].AxisX.CustomLabels) { if (// xAxisLabel is Dec) label.Text = xAxisLabel + /*custom day*/; } }