Adding A String header to beginning of XML
I need to add the following header to an XML file.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE mm24Hour SYSTEM 'XMLnotepad.dtd'>
The XML comes in as email and then I run an agent that copies the Email Body to a field on another document. From this document I run a JavaXML Parser (Non-Validating)that works really good.
What I want to do is validate the XML before it is Parsed. From all that I have read i have to have a header at the beginning of the XML file.
My question is How do I add that header to the beginning of the XML file???? Each XML file is different but the DTD works on all of them when the header is present. (I have tested this manually)
Here is a copy of the XML:
[<mm24Hour>
<machinemonitorv1r0_status>
<serialn>Dual041973</serialn>
<trntime>07:30:50</trntime>
<trndate>2003/8/20</trndate>
<intsoftversion> VERSION 00.15 </intsoftversion>
<modsoftversion>$Version: eDsoft-101_V4.7.7 $</modsoftversion>
<intconfigversion>DUAL Config 041973RA</intconfigversion>
<connectduration>49</connectduration>
<phonenumbout>5411105</phonenumbout>
<opsoftversion> BrewWISE 01.15 </opsoftversion>
</machinemonitorv1r0_status>
</mm24Hour>]
Here is the Java agent that parses it. (Note if I change the line
[ org.w3c.dom.Document xDoc = it.parseXML(false);] to true it will try to validate.
[import lotus.domino.*;
import org.w3c.dom.*;
import java.util.*;
public class ParseEvents extends AgentBase {
String machine ;
String transTime;
String rootTag;
public void NotesMain() {
try {
Session ns = getSession();
AgentContext ac = ns.getAgentContext();
Database db = ac.getCurrentDatabase();
View nv = db.getView("RawXML");
Vector v = new Vector();
v.addElement("XMLTest Import From File");
v.addElement("ParseXML Sample");
DocumentCollection dc = nv.getAllDocumentsByKey(v,true);
if (dc.getCount() >= 1){
lotus.domino.Document doc = dc.getFirstDocument();
while (doc != null) {
Item it = doc.getFirstItem("XMLBody");
org.w3c.dom.Document xDoc = it.parseXML(false);
Element el = xDoc.getDocumentElement();
rootTag = el.getTagName();
processTree(el ,xDoc);
//doc.replaceItemValue("Status","Processed");
doc.save(true,true);
doc = dc.getNextDocument(doc);
} //end while
} // end if
} catch(Exception e) {
e.printStackTrace();
} //end try - catch
} // end NotesMain()
public void processTree(Element e, org.w3c.dom.Document x) throws
Exception {
NodeList nl = x.getElementsByTagName(e.getTagName());
//Attr attr = getAttributeNode(name);
Node n = nl.item(0);
nl = n.getChildNodes();
for (int i = 0 ; i < nl.getLength() ; i++) {
n = nl.item(i);
if (n.getNodeType() == n.ELEMENT_NODE) {
processNode(n);
} //end if
} //end for
} // end processTree()
public void processNode(Node n) throws Exception {
Session ns = getSession();
AgentContext ac = ns.getAgentContext();
Database db = ac.getCurrentDatabase();
if (n.getNodeType() == n.ELEMENT_NODE) {
if ((n.getNodeName()) .equals("machinemonitorv1r0_status | machinemonitorv1r0_CWT | machinemonitorv1r0_CDS | machinemonitorv1r0_DB | machinemonitorv1r0_DBW | machinemonitorv1r0_FCD | machinemonitorv1r0_FMD | machinemonitorv1r0_G9" +
" | machinemonitorv1r0_G9BW | machinemonitorv1r0_HC | machinemonitorv1r0_TEA | machinemonitorv1r0_ULTRA"
n = n.getFirstChild();
machine = n.getNodeValue();
//else if ((n.getNodeName()).equals("machinemonitorv1r0_CWT")) {
//n = n.getFirstChild();
//machine = n.getNodeValue();
else if (n.hasChildNodes()) {
processChildNodes(n , db) ;
} // end if-elseif
} // end if
} //end processNode()
public void processChildNodes(Node n, Database db) throws Exception {
lotus.domino.Document rDoc = db.createDocument();
rDoc.appendItemValue("Form", "XMLEvent");
rDoc.appendItemValue("machine" , n.getNodeName() );
rDoc.appendItemValue("rootTag" , rootTag );
//rDoc.appendItemValue("trntime" , transTime);
NodeList nl = n.getChildNodes();
for (int y = 0 ; y < nl.getLength() ; y++) {
n = nl.item(y);
if (n.getNodeType() == n.ELEMENT_NODE) {
Node cn = n.getFirstChild();
rDoc.appendItemValue(n.getNodeName(),
cn.getNodeValue());
} // end if
} //end for
rDoc.save(true,true);
} // end processChildNodes
} //end ParseExRates]
Thanks for any help.
sorry this is easier to read
import lotus.domino.*;
import org.w3c.dom.*;
import java.util.*;
public class ParseEvents extends AgentBase {
String machine ;
String transTime;
String rootTag;
public void NotesMain() {
try {
Session ns = getSession();
AgentContext ac = ns.getAgentContext();
Database db = ac.getCurrentDatabase();
View nv = db.getView("RawXML");
Vector v = new Vector();
v.addElement("XMLTest Import From File");
v.addElement("ParseXML Sample");
DocumentCollection dc = nv.getAllDocumentsByKey(v,true);
if (dc.getCount() >= 1){
lotus.domino.Document doc = dc.getFirstDocument();
while (doc != null) {
Item it = doc.getFirstItem("XMLBody");
org.w3c.dom.Document xDoc = it.parseXML(false);
Element el = xDoc.getDocumentElement();
rootTag = el.getTagName();
processTree(el ,xDoc);
//doc.replaceItemValue("Status","Processed");
doc.save(true,true);
doc = dc.getNextDocument(doc);
} //end while
} // end if
} catch(Exception e) {
e.printStackTrace();
} //end try - catch
} // end NotesMain()
public void processTree(Element e, org.w3c.dom.Document x) throws
Exception {
NodeList nl = x.getElementsByTagName(e.getTagName());
//Attr attr = getAttributeNode(name);
Node n = nl.item(0);
nl = n.getChildNodes();
for (int i = 0 ; i < nl.getLength() ; i++) {
n = nl.item(i);
if (n.getNodeType() == n.ELEMENT_NODE) {
processNode(n);
} //end if
} //end for
} // end processTree()
public void processNode(Node n) throws Exception {
Session ns = getSession();
AgentContext ac = ns.getAgentContext();
Database db = ac.getCurrentDatabase();
if (n.getNodeType() == n.ELEMENT_NODE) {
if ((n.getNodeName()) .equals("machinemonitorv1r0_status | machinemonitorv1r0_CWT | machinemonitorv1r0_CDS | machinemonitorv1r0_DB | machinemonitorv1r0_DBW | machinemonitorv1r0_FCD | machinemonitorv1r0_FMD | machinemonitorv1r0_G9" +
" | machinemonitorv1r0_G9BW | machinemonitorv1r0_HC | machinemonitorv1r0_TEA | machinemonitorv1r0_ULTRA"
n = n.getFirstChild();
machine = n.getNodeValue();
//else if ((n.getNodeName()).equals("machinemonitorv1r0_CWT")) {
//n = n.getFirstChild();
//machine = n.getNodeValue();
else if (n.hasChildNodes()) {
processChildNodes(n , db) ;
} // end if-elseif
} // end if
} //end processNode()
public void processChildNodes(Node n, Database db) throws Exception {
lotus.domino.Document rDoc = db.createDocument();
rDoc.appendItemValue("Form", "XMLEvent");
rDoc.appendItemValue("machine" , n.getNodeName() );
rDoc.appendItemValue("rootTag" , rootTag );
//rDoc.appendItemValue("trntime" , transTime);
NodeList nl = n.getChildNodes();
for (int y = 0 ; y < nl.getLength() ; y++) {
n = nl.item(y);
if (n.getNodeType() == n.ELEMENT_NODE) {
Node cn = n.getFirstChild();
rDoc.appendItemValue(n.getNodeName(),
cn.getNodeValue());
} // end if
} //end for
rDoc.save(true,true);
} // end processChildNodes
} //end ParseExRates
Similar Messages
-
When i convert any file to pdf, date is automatically added in the header in pdf file. How to change that?*
heres a screenshot
heres a screenshot of how i convert them -
Write a string at each beginning record
I save data in a file .txt with spreadsheet ....I record a cycle each hour.I have temperature ,pressure, time and date...I want to write a string at each beginning record......(e.g. A 125 256 ....the number of the process I save ) and the last record will be A 125 256.
Thank you for your help.You have to use write to spreadsheet in the string form, there used to be instructions on modifying it inside write to spreadsheet, but basically consists in changing input numeric arrays into string arrays. This way you can use string arrays with any stamp in the first column, but your data has to be a string too.
Hope this helps -
Not automatically adding pages in header.
Is it possible to make pages under an iWeb site that are not automatically added in the header links? Thanks.
Yes, it's possible — see this video tutorial:
-
Adding multiple same-name nodes from one xml into another
Hi,
Following on from my question the other day (Adding multiple different nodes from one xmltype into another), I now have a slightly more complex requirement that I cannot work out where to start, assuming that it's something that can reuse some/all of yesterday's work (thanks again, odie_63!). ETA: I'm on 11.2.0.3
So, here's the (slightly amended) xml along with yesterday's solution:
with sample_data as (select xmltype('<root>
<xmlnode>
<subnode1>val1</subnode1>
<subnode2>val2</subnode2>
</xmlnode>
<xmlnode>
<subnode1>val3</subnode1>
<subnode2>val4</subnode2>
</xmlnode>
</root>') xml_to_update,
xmltype('<a>
<b>valb</b>
<c>valc</c>
<d>
<d1>vald1</d1>
<d2>vald2</d2>
</d>
<e>vale</e>
<f>valf</f>
<g>
<g1>valg1</g1>
<g2>valg2</g2>
</g>
<h>
<h1>valh1</h1>
<h2>valh2</h2>
</h>
<multinode>
<name>fred</name>
<type>book</type>
<head>1</head>
</multinode>
<multinode>
<name>bob</name>
<type>car</type>
<head>0</head>
</multinode>
</a>') xml_to_extract_from
from dual)
select xmlserialize(document
xmlquery(
'copy $d := $old
modify (
insert node element extrainfo {
$new/a/b
, $new/a/d
, $new/a/f
, $new/a/h
} as first into $d/root
return $d'
passing sd.xml_to_update as "old"
, sd.xml_to_extract_from as "new"
returning content
indent
from sample_data sd;
That gives me:
<root>
<extrainfo>
<b>valb</b>
<d>
<d1>vald1</d1>
<d2>vald2</d2>
</d>
<f>valf</f>
<h>
<h1>valh1</h1>
<h2>valh2</h2>
</h>
</extrainfo>
<xmlnode>
<subnode1>val1</subnode1>
<subnode2>val2</subnode2>
</xmlnode>
<xmlnode>
<subnode1>val3</subnode1>
<subnode2>val4</subnode2>
</xmlnode>
</root>
However, I now need to add in a set of new nodes based on information from the <multinode> nodes, something like:
<root>
<extrainfo>
<b>valb</b>
<d>
<d1>vald1</d1>
<d2>vald2</d2>
</d>
<f>valf</f>
<h>
<h1>valh1</h1>
<h2>valh2</h2>
</h>
<newnode>
<name>fred</name>
<type>book</type>
</newnode>
<newnode>
<name>bob</name>
<type>car</type>
</newnode>
</extrainfo>
<xmlnode>
<subnode1>val1</subnode1>
<subnode2>val2</subnode2>
<type>book</type>
</xmlnode>
<xmlnode>
<subnode1>val3</subnode1>
<subnode2>val4</subnode2>
<type>car</type>
</xmlnode>
</root>
If it's easier, I *think* we would be ok with something like:
<newnode>
<type name="fred">book</type>
<type name="bob">car</type>
</newnode>
The closest I've come is:
with sample_data as (select xmltype('<root>
<xmlnode>
<subnode1>val1</subnode1>
<subnode2>val2</subnode2>
</xmlnode>
<xmlnode>
<subnode1>val3</subnode1>
<subnode2>val4</subnode2>
</xmlnode>
</root>') xml_to_update,
xmltype('<a>
<b>valb</b>
<c>valc</c>
<d>
<d1>vald1</d1>
<d2>vald2</d2>
</d>
<e>vale</e>
<f>valf</f>
<g>
<g1>valg1</g1>
<g2>valg2</g2>
</g>
<h>
<h1>valh1</h1>
<h2>valh2</h2>
</h>
<multinode>
<name>fred</name>
<type>book</type>
<head>1</head>
</multinode>
<multinode>
<name>bob</name>
<type>car</type>
<head>0</head>
</multinode>
</a>') xml_to_extract_from
from dual)
select xmlserialize(document
xmlquery(
'copy $d := $old
modify (
insert node element extrainfo {
$new/a/b
, $new/a/d
, $new/a/f
, $new/a/h
, element newnode {
$new/a/multinode/name
,$new/a/multinode/type
} as first into $d/root
return $d'
passing sd.xml_to_update as "old"
, sd.xml_to_extract_from as "new"
returning content
indent
) fred
from sample_data sd;
Which produces:
<newnode>
<name>fred</name>
<name>bob</name>
<type>book</type>
<type>car</type>
</newnode>
- obviously not right!
Can anyone provide any hints? I've tried searching for similar examples, but I mustn't be putting in the right search terms or something!odie_63 wrote:
or, similarly, to get the alternate output :
copy $d := $old
modify (
insert node element extrainfo {
$new/a/b
, $new/a/d
, $new/a/f
, $new/a/h
, element newnode {
for $i in $new/a/multinode
return element type {
attribute name {data($i/name)}
, data($i/type)
} as first into $d/root
return $d
So we're going with the second method, but I've discovered that the "$i/name" node is not always present. When that happens, I would like to use a default value (for example, "george"). I promise I've searched and searched, but I'm completely failing to turn up anything that sounds remotely like what I'm after (seriously, I can't believe my google-fu sucks this badly!).
Is there a simple way of doing it? The only thing that I've found that looks vaguely relevant is "declare default namespace...." but I'm not sure that that's the correct thing to use, or if it is, how I'm supposed to reference it when populating the attribute value. -
Getting garbage characters at the begining of xml
Hi Experts,
I am using file adapter to pick XML file. Using TEXT mode & encoding "ISO-8859-1" as it has some special characters.
But when file is picked by PI in moni XML payload contain some garbage characters at the begining of the XML declaration.
This characters is making file as invalid.
But if I open the origional file then it is not showing the characters.
Could u please help me how to remove this garbage characters frm XML file beginning.
Thanks in advance.I am using file adapter to pick XML file. Using TEXT mode & encoding "ISO-8859-1" as it has some special characters.
This characters is making file as invalid.
Check this SAP Note: https://service.sap.com/sap/support/notes/821267
From the above SAP Note:
16. File Encoding
XML Files
Important: Even if you configure a File Encoding in the File Adapter channel, the File Adapter will not
-write the XML header to reflect the changed encoding, so you will probably see an XML parsing error later
during the processing of the message if you specify an encoding.
Regards,
Abhishek. -
Get string out of CDATA in xml
I have xml file with another xml file embedded in it inside CDATA. Will someone help me with the code to get that xml as string.I am using xml beans
The xml i have looks like this.
<SPFormatOrderXml><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSPY v5 rel. 4 U (http://www.xmlspy.com)-->
<DataCommunication xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\rghanta.SISCO\Desktop\NextAceProductDelivery.xsd">
<Header>
<Portal>
<ClientID>100</ClientID>
<UserID>121</UserID>
<OrderID>100</OrderID>
<EventID>43</EventID>
<EventName>ServiceProviderDispatch Error</EventName>
<DateTime>2001-12-17T09:30:47-05:00</DateTime>
<customerEmail>[email protected]</customerEmail>
<customerName>Client 100</customerName>
</Portal>
<Partner>
<PartnerOrderID>NextAceOrderID100</PartnerOrderID>
<PartnerName>NextAce</PartnerName>
<PartnerID>1</PartnerID>
<EventID>43</EventID>
<EventName>ServiceProviderDispatch Error</EventName>
<DateTime>2001-12-17T09:30:47-05:00</DateTime>
</Partner>
</Header>
<Transaction>
<Error>
<ErrorCode/>
<ErrorMessage/>
<ErrorContact/>
</Error>
<Comment>
<Private>An Internal Error has been thrown</Private>
<Public>Order has failed</Public>
<Information/>
</Comment>
</Transaction>
</DataCommunication>
]]></SPFormatOrderXml>here is a good start -> [http://www.oracle.com/technology/oramag/oracle/03-may/o33xml.html|http://www.oracle.com/technology/oramag/oracle/03-may/o33xml.html]
-
6575722.994: ADDITIONAL BLANK TABLE CELLS ADDED IN RTF HEADER
HI all,
XML:5.6.3
APPS:11.5.10.2
Please advice,
RTF template associated with PO Output for Communication (tempalte uploaded). When previewed,
data displays correctly.
When output is viewed from Application, additional blank table cells are added in header area.
These blank table cells are unwanted.
Also :
If I have multiple pages of output, the application is losing the header and footer after the
first page.
If I preview the template from Microsoft Word with the same output, the header and footer shows on
all pages.
Customer said:
'not looking for help designing the template - I have a template that gives
different output when output is viewed in the template builder and compared against the output from the application.
I am looking for assistance on which output is incorrect, and what cna be done to ensure both outputs are consistent'
thxs!check if you have any carriage return,or extra space in your tag
or if you are using 'IF' condition try using @inlines.
these are the general situations were extra space is created in your output -
Static information to be added in message header of the XI message in JMS
Hi Friends ,
Is it possible to add some customer specific internal information to message header of the XI message in PI 7.1 level.. If so how ?
customer wants to add some info and to verify whether it would be handled in PI itself or not..
Business case : SAP -
> PI7.1 -
> IBM MQ
All inputs will be appreciated .
Thanks.,
V.RangarajanHi preetak ,
Thanks for your info .Since i have not worked on JMS adapter
As per the Link it says as follows
If you want to set additional JMS message attributes, select Specify Additional JMS Message Properties (10 Maximum).
· In the table, enter the Name and Java Type of the JMS message properties whose values are to be included in the message header of the XI message.
Under Java Type, you define the JMS Java message type for the attribute in the created JMS message. The following are possible entries:
boolean , init , String etc.,
Question
1. How to pass the value to this parameter will it be XML file with parameter name and value ?
2. Any other blogs to refer ?
Thanks .,
V.Rangarajan -
Adding C# Soap Header to a client that calls BT2010 Orchestration published as a WCF Web Service
I've added code from this reference to my orchestration (that is published as a WCF webservice):
Accessing SOAP Headers in Orchestrations.
I have a C# client that I was previously using before I was using any of the SOAP Headers. I've been looking at dozens of blogs, and find the answers to anything related to SOAP Headers most confusing (and often specific to unique cases).
I'm using BT2010. How can I add username, password, and a custom header called "ApplicationID" to my existing C# program and pass it to the orchestration/web service?
Thanks,
NealNeal,
The BizTalk WCF Service Publishing Wizard does not include custom SOAP header definitions in the generated metadata. To publish metadata for WCF services using custom SOAP headers, you should manually create a Web Services Description Language (WSDL) file.
You can use the externalMetadataLocation attribute of the
<serviceMetadata> element in the Web.config file that the wizard generates to specify the location of the WSDL file. The WSDL file is returned to the user in response to WSDL and metadata exchange (MEX) requests instead of the auto-generated WSDL.
The following XML data shows an example of a part of the WSDL file defining custom SOAP headers:
<wsdl:operation name="Request">
<soap12:operation soapAction="http://Microsoft.Samples.BizTalk.NetTcpAdapter/OrderProcess/IOrderProcess/Request" style="document" />
<wsdl:input name="Order">
<soap12:header message="i0:Order_Headers" part="SalesAgent" use="literal" />
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output name="OrderConfirmation">
<soap12:header message="i0:OrderConfirmation_Headers" part="PaymentAgent" use="literal" />
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
Refer:
SOAP Headers with Published WCF Services
Rachit
Please mark as answer or vote as helpful if my reply does -
Need help in creating header node at reciver XML file?
Hello All,
Iam creating proxy to file scenario.....at receiver side iam creating XML file like below.
<?xml version="1.0" encoding="UTF-8" ?>
<OrderTransaction>
<TransactionInformation Version="2.0.0">
<DocId>0180000186</DocId>
<Sender>........
</OrderTransaction>
bit now client require one header node like below
<!DOCTYPE OrderTransaction PUBLIC "Order" "Order.dtd">
now th recevier xml need to look like
<?xml version="1.0" encoding="UTF-8" ?>
<OrderTransaction>
<!DOCTYPE OrderTransaction PUBLIC "Order" "Order.dtd">
<TransactionInformation Version="2.0.0">
<DocId>0180000186</DocId>
<Sender>........
</OrderTransaction>
how to add that node........... i cant add it as node element............ Please help me out.
Thanks and Regards,
Chinna
Edited by: chinnasapxi on Mar 16, 2010 8:11 PMHi Chinna,
Probably writing a script and calling in receiver file adapter after message processing and in the script just add the line in the 3rd line and then put the rest.
Regards,
---Satish -
How to remove the header tag in the XML data ?
Hi All,
I am sending an XML data from SFTP to Proxy, in that I want to remove the header tag (first tag) from the xml, while loading the data. how to do that ?Hi,
It is not about the thing that, whether your source is XML or flat file. If you dont want some thing in your source file , dont consider it and dont map it with your target structure. think that, your not getting the header in your source. What is the header here.
<Emp_details>
<Emp_Id> Employee No </Emp_Id>
<Emp_Name> Employee Name </Emp_Name>
</Emp_details>
<Emp_details>
<Emp_Id> 1234 </Emp_Id>
<Emp_Name> xxxx </Emp_Name>
</Emp_details>
<Emp_details>
<Emp_Id> 5678 </Emp_Id>
<Emp_Name> yyy </Emp_Name>
</Emp_details>
you have two fields under node Emp_details. What do u want to avoid here?
Regards,
Reyaz -
Adding query string to files already within shared documents
Am a Sharepoint newbie, so hopefully this is an easy one. Am trying to add a query string to some hyperlinks (of PDF files) that are already published in a Shared Documents web part. What's the best way to accomplish this? Can't seem to find an easy
way to edit the raw HTML anchor tag, which would be so simple. Is the anchor tag HTML exposed someplace where I can edit?
Thanks in advance.You could potentially modify the rendering of a specific Shared Documents by modifying the XSL of your view in SharePoint Designer. However, this will not affect all libraries and not all views of the library, just the specific page.
The jQuery method is actually very easy and can be deployed site-wide by adding a reference to your MasterPage, or to a specific view / page by using the Content Editor Web Part. The actual jQuery would look something like:
$(document).ready(function() {
$("a[href$='.pdf']").attr('href', function(i, v) {
return v + '#YourCustomQueryString';
Dimitri Ayrapetov (MCSE: SharePoint) -
I have a script where the prompt directory is a parameter exposed on the "Application Management" web page.
The way the script is structured is that it expects the directory name to have a backslash at the end of it. Example
In the script the full prompt path is created such as: (all variables are string)
FullPromptFile = DirectoryName\ + Filename.wav
In all the past versions of UCCX that I've worked with (4,7,8,8.5,9.x) I could edit the directory path name, as a parameter, on the AppAdmin web page including the trailing backslash and it would save and work properly.
In UCCX 10.5 when I save it, the backslash is simply removed. The save appears to work correctly but going back to the webpage the backslash at the end of the string (inside the quotes) is simply gone.
Tested in multiple browsers (IE 10 and FF 30) and multiple workstations
See screen captures below.
After the SaveI opened a TAC case on this issue.
Turns out this change was made in UCCX 10.0 and forward.
Prior to 10.0, the backslash was accepted in the web interface for an application parameter.
The fix is to use a forward slash in all file and URL paths.
The interesting part, the script "engine" still works fine with file and directory paths using a backslash in 10.5. Its only the web interface change, under app admin, that is causing the issue.
I agree with TAC's recommendation that all file and URL paths use the forward slash instead of the backslash on the Linux platform. This is the case of using scripts previously developed and that used to work but should have been changed to use the new Linux method.
There was nothing in the release notes about this.
Heads up to all. -
Converting int to string, adding to string then pointing to an url
So I'm getting a null pointer exception here's a snippet of my code (theres plus signs on both sides of the a in my code):
private Image[] tiles;
public Map() {
for(int a=0; a<9; a++){
ImageIcon aa = new ImageIcon(this.getClass().getResource("mapsquares"+a+".png"));
tiles[a] = aa.getImage();
I've also tried:
private Image[] tiles;
public Map() {
for(int a=0; a<9; a++){
ImageIcon aa = new ImageIcon(this.getClass().getResource("mapsquares$s.png", String.valueOf(a)));
tiles[a] = aa.getImage();
whats wrong with either of these?
Edited by: Wub on Feb 28, 2013 3:17 PM1.) You should use code tags when posting code.
2.) You should read the stacktrace closely to find out which exact line number in your code threw the exception.
My guess is that it's the line tiles[a] = aa.getImage(); because you didn't initialize the array tiles using the new operator. This is just a guess since you didn't post the full stacktrace. Also, NullpointerExceptions are one of the easiest to debug. Just adding print out lines at strategic values can show you which variables are initialized and which ones are not.
Maybe you are looking for
-
IPod is not recognized by updates
I have Version 1.3 and updated my ITunes and my iPod and each time I try to update it says please connect the iPod..welll I am connected. Even trying to put songs in from my ITunes it says no iPod recognized. Also the Apple logo stopped appearing a l
-
Itunes Apple ID account help.
I changed my apple ID username and password from previous account and now I cannot play music purchased under previous account username/password. Please help.
-
Creative Zen Vision M out of stock in Cana
Hello guys, Just wondering whether there is any place where there is Creative Zen Vision M MP3 players, I have ordered with Dell and they have promised me that it is coming "soon" several times . Futureshop is out of stock, so as BestBuy. What happen
-
Application runs only in one user account
Hello, While trying to install a Canon LiDE 200 scanner, I am experiencing this very odd problem: The "Setup" app on the install CD will only run in one of the two user accounts installed on my macbook (both are admins). In the other, the application
-
Need help adding scanner to my computer
I am having trouble getting my scanner to load onto my laptop. I have an HP LaserJet 6500 all in one printer. The printer is recognized but not the scanner. We recently moved and the scanner worked fine before that. Any ideas? Thanks.