UPDATE:
So I tried the AssetManager way and ended up with this:
...
...
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xrp = factory.newPullParser();
AssetManager assmgr = context.getAssets();
xrp.setInput(assmgr.open("levels/level_1.xml"), null);
//Object attributes
String type = null;
int x = 0;
int y = 0;
double angleRads = 0;
int eventType = xrp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
} else if (eventType == XmlPullParser.START_TAG) {
if (xrp.getName().equals("Position")) {
while (!xrp.getName().equals("X")) { <----NULLPOINTER EXCEPTION HERE
eventType = xrp.next();
}
...
...
Now this code used to work fine when xrp was a XmlResourceParser but now I get this error message:
06-01 05:13:56.797: ERROR/AndroidRuntime(946): Caused by: java.lang.NullPointerException
06-01 05:13:56.797: ERROR/AndroidRuntime(946): at com.stickfigs.blockball.BlockBallView$BlockBallThread.initLevel(BlockBallView.java:342)
I don't understand why this isn't working anymore, I marked the line where the nullpointerexception is happening in the code above with an arrow.
=== vvvOLDvvv ===
In my res/xml/ folder I have a bunch of files called level_#.xml (ex: level_1.xml, level_2.xml, level_21.xml) and I have a spinner widget that I want to populate with the id names of all of the .xml files in this folder that follow the naming convention level_#.xml and only those.
I think I figured out how to set up the widget:
Spinner lsSpinner = (Spinner) findViewById(R.id.levelselect_spinner);
String levels[] = {"level_1","level_2","level_55"};
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, levels);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
lsSpinner.setAdapter(spinnerArrayAdapter);
Now I just need to generate levels[] dynamically like I explained before...
How do I go about doing this?
The straightforward answer is
String[] levels = new String[LEVELS];
for (int i=0; i< LEVELS; i++) {
int j = i+1;
levels[i] = new String ("level_"+j);
}
But I have the feeling that that's not what you want.
If you want a reference to the actual ID of each level_XX.xml, then you will need to do it manually, since each R.layout.levelXX is an actual int and there is no possible way to secure consecutive numbering for them (even if the names you use are consecutive).
Since the previous question has been solved, I think it is better to create another question to let folks help you. But in the name of convenience please allow me to answer you here.
What do you think if xrp.getName() will never equal to "X"? Will xrp goto next until null? I suggest you make a breakpoint here and have a check.
By the way, I saw you are struggling in xml in android, I may suggest you use some ext library which may let life easier. Like this: http://brainflush.wordpress.com/2009/05/19/the-force-unleashed-xmlxpath-on-android-using-dom4j-and-jaxen/
Hope this may help.
Have a look at AssetManager: http://developer.android.com/reference/android/content/res/AssetManager.html#list(java.lang.String)
And then you can new a file and getName()
Link: http://developer.android.com/reference/java/io/File.html#getName()
Hope this helps.
Related
Can anyone give me advice on how to read the general ledger using SuiteTalk, the SOAP API from NetSuite?
For example, if you look at an account or a transaction on the NetSuite UI, there is an option to select "GL Impact". This produces a list of relevant general ledger entries.
However, I couldn't figure out a way to get the same list using SuiteTalk. One initially promising SOAP operation I tried calling was getPostingTransactionSummary(), but that is just a summary and lacks detail such as transaction dates. Another way is to call search() passing a TransactionSearchBasic object. That returns too many types of transaction and I'm not sure which of those actually have an impact on the general ledger.
I'm using Java and Axis toolkit for the SOAP operations, but examples in any language whatsoever (or raw SOAP XML) would be appreciated.
you are on the right track with your transaction search.
You are looking for posting is true and where the line has an account.
However I'd set this up in the saved search editor at least until you've figured out how you are going to filter to manageable numbers of lines. Then use TransactionSearchAdvanced with savedSearchId to pull that info via SuiteTalk
I am able to search GL transaction with below code, this could help you.
public void GetTransactionData()
{
DataTable dtData = new DataTable();
string errorMsg = "";
LoginToService(ref errorMsg);
TransactionSearch objTransSearch = new TransactionSearch();
TransactionSearchBasic objTransSearchBasic = new TransactionSearchBasic();
SearchEnumMultiSelectField semsf = new SearchEnumMultiSelectField();
semsf.#operator = SearchEnumMultiSelectFieldOperator.anyOf;
semsf.operatorSpecified = true;
semsf.searchValue = new string[] { "Journal" };
objTransSearchBasic.type = semsf;
objTransSearchBasic.postingPeriod = new RecordRef() { internalId = "43" };
objTransSearch.basic = objTransSearchBasic;
//Set Search Preferences
SearchPreferences _searchPreferences = new SearchPreferences();
Preferences _prefs = new Preferences();
_serviceInstance.preferences = _prefs;
_serviceInstance.searchPreferences = _searchPreferences;
_searchPreferences.pageSize = 1000;
_searchPreferences.pageSizeSpecified = true;
_searchPreferences.bodyFieldsOnly = false;
//Set Search Preferences
try
{
SearchResult result = _serviceInstance.search(objTransSearch);
List<JournalEntry> lstJEntry = new List<JournalEntry>();
List<JournalEntryLine> lstLineItems = new List<JournalEntryLine>();
if (result.status.isSuccess)
{
for (int i = 0; i <= result.recordList.Length - 1; i += 1)
{
JournalEntry JEntry = (JournalEntry)result.recordList[i];
lstJEntry.Add((JournalEntry)result.recordList[i]);
if (JEntry.lineList != null)
{
foreach (JournalEntryLine line in JEntry.lineList.line)
{
lstLineItems.Add(line);
}
}
}
}
try
{
_serviceInstance.logout();
}
catch (Exception ex)
{
}
}
catch (Exception ex)
{
throw ex;
}
}
I'm trying to replace a xml rootnode with a string, but it doesn't allow me.
I was trying to give it as
String str = "SOAP-ENV:Body'.'ns1:creditCardResponse";
I should not repeat SOAP-ENV:Body'.'ns1:creditCardResponse in all these lines.
def rootnode = new XmlParser().parseText(responseXml);
status = rootnode.'SOAP-ENV:Body'.'ns1:creditCardResponse'.return.Status.text();
errorCode = rootnode.'SOAP-ENV:Body'.'ns1:creditCardResponse'.return.Errorcode.text();
errorInfo = rootnode.'SOAP-ENV:Body'.'ns1:creditCardResponse'.return.Errorinfo.text();
referenceCode = rootnode.'SOAP-ENV:Body'.'ns1:creditCardResponse'.return.ReferenceCode.text();
requestIp = rootnode.'SOAP-ENV:Body'.'ns1:creditCardResponse'.return.RequestIP.text()
Any ideas would be greatly appreciated.
Thanks.
Remember that these "paths" are just a series of normal groovy property accesses, so you can store any intermediate point in the path as a variable and continue navigating from there:
deg rtn = rootnode.'SOAP-ENV:Body'.'ns1:creditCardResponse'.return
status = rtn.Status.text()
errorCode = rtn.Errorcode.text()
// etc.
I am working with Weka 3.6.11 and I am having an error which I can't figure out what is causing it.
I have followed pages 202-204 in the Weka manual and have constructed my data like they say. Still when I try t classify the data I get an error.
weka.core.UnassignedDatasetException: Instance doesn't have access to a dataset!
Here is the code I have so far:
public static void classifyTest()
{
try
{
Classifier classifier = (Classifier)weka.core.SerializationHelper.read("iris120.model");
System.Console.WriteLine("----------------------------");
weka.core.Attribute sepallength = new weka.core.Attribute("sepallength");
weka.core.Attribute sepalwidth = new weka.core.Attribute("sepalwidth");
weka.core.Attribute petallength = new weka.core.Attribute("petallength");
weka.core.Attribute petalwidth = new weka.core.Attribute("petalwidth");
FastVector labels = new FastVector();
labels.addElement("Iris-setosa");
labels.addElement("Iris-versicolor");
labels.addElement("Iris-virginica");
weka.core.Attribute cls = new weka.core.Attribute("class", labels);
FastVector attributes = new FastVector();
attributes.addElement(sepallength);
attributes.addElement(sepalwidth);
attributes.addElement(petallength);
attributes.addElement(petalwidth);
attributes.addElement(cls);
Instances dataset = new Instances("TestInstances", attributes, 0);
double[] values = new double[dataset.numAttributes()];
values[0] = 5.0;
values[1] = 3.5;
values[2] = 1.3;
values[3] = 0.3;
Instance inst = new Instance(1,values);
dataset.add(inst);
// Here I try to classify the data that I have constructed.
try
{
double predictedClass = classifier.classifyInstance(inst);
System.Console.WriteLine("Class1: (irisSetosa): " + predictedClass);
}
catch (java.lang.Exception ex)
{
ex.printStackTrace();
}
System.Console.ReadLine();
}
catch (java.lang.Exception ex)
{
ex.printStackTrace();
System.Console.ReadLine();
}
}
From the error message I take it that I need to assign my dataset something but I do not know what or how.
Can someone point out my mistake?
Thanks.
I have found the solution to my own question and thus I am providing the information here so that it might help someone else.
My original problem was that I was getting an "UnsignedDataSetException". To solve that I added a method call to setDataSet like so:
....previous code omitted, can be seen in the question...
Instance inst = new Instance(1.0,values);
dataset.add(inst);
inst.setDataset(dataset);
....following code omitted, can be seen in the question...
After that I got another exception called UnassignedClassException. That means that you have not explicitly set the attribute which is to be used as the outcome of the prediction. Usually it is the last attribute so we add a method called setClassIndex like so:
Instances dataset = new Instances("TestInstances", attributes, 0);
// Assign the prediction attribute to the dataset. This attribute will
// be used to make a prediction.
dataset.setClassIndex(dataset.numAttributes() - 1);
Now it works. It predicts the correct iris (at least for the one I have tried). If something else pops up I will edit this question/answer.
Cheers!
Hopefully someone can help me here. I have a project that I'm doing, yes it is homework so I hope that doesn't hurt my chances of an answer here. I'm supposed to write an app that collects data from bbyopen api. Best Buys web api, it delivers details about stores in your area. Any way I've gotten a response from the server that I'm certain contains the correct information as I've displayed it in logcat using System.out.println(). However, what I would like to do is turn this string into an xml document, parse out the name of the store, it's address and then display it in a text view in a new activity.
Here is the code I'm using to parse the string and put the proper data into an array which is passed to a new activity. I'm certain that nothing is actually passed to the new activity and I'm unsure whether or not the array is even being built. Any help would be greatly appreciated.
public void callback(String serviceResult){
System.out.println(serviceResult);
try {
XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();
parserCreator.setNamespaceAware(true);
XmlPullParser parser = parserCreator.newPullParser();
parser.setInput(new StringReader(serviceResult));
int eventType = parser.getEventType();
while (eventType != parser.END_DOCUMENT){
String name = "";
String address = "";
if ((eventType == XmlPullParser.START_TAG)&& (parser.getName().equals("longName"))){
name = parser.getName();
}
if ((eventType == XmlPullParser.START_TAG)&& (parser.getName().equals("address"))){
address = parser.getName();
Store store = new Store(name, address);
arrStore.add(store);
System.out.println(arrStore);
}
else
parser.nextTag();
}
} catch (Exception e) {
}
Intent intent = new Intent(getApplicationContext(),StoreList.class);
intent.getStringArrayListExtra(arrStore.toString(), "key");
startActivity(intent);
}
I then receive the intent in the new activity like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_store_list);
getIntent();
ArrayList<String> store = getIntent().getStringArrayListExtra("key");
}
However trying to do a print line on the ArrayList store, in the new activity results in a null pointer error. I suspect that is because the array is empty..?
If it helps here is what the XML that I am receiving looks like and it is being sent as a string the parser.
<stores warnings="Distances are in terms of miles (default)" currentPage="1" totalPages="1" from="1" to="4" total="4" queryTime="0.006" totalTime="0.011" >
<store>
<longName>Best Buy - Toledo II</longName>
<address>1405 Spring Meadows Dr</address>
</store>
<store>
<longName>Best Buy - Perrysburg</longName>
<address>10017 Fremont Pike</address>
</store>
<store>
<longName>Best Buy - Toledo</longName>
<address>4505 Monroe St</address>
</store>
<store>
<longName>Best Buy Mobile - Franklin Park</longName>
<address>5001 Monroe Street</address>
</store>
</stores>
The error is here:
Intent intent = new Intent(getApplicationContext(),StoreList.class);
intent.getStringArrayListExtra(arrStore.toString(), "key");
startActivity(intent);
Try: putStringArrayListExtra().
I don't have soap ui pro. I am testing the web service. The actual implementation is i need pass one error code on the request, and the corresponding error description should be displayed on the response. I need to add this assertion. Every time the description in the response varies.
Here is the thing i want exactly...
Every time i need to run the same request but the error code (which is input) only should be changed on each time and the description varies on the response. How to validate this? Is there any way to do this without data source.
Regards,
Chandra
This is the way i have created.. is there any way to improve the code to do better way;
import java.io.File;
File file = new File('c:/customers.csv');
InputStream inputFile = new FileInputStream(file);
String[] lines = inputFile.text.split('\n');
List<String[]> rows = lines.collect {it.split(',')}
log.info('There are ' + rows.size() + ' customers to be inserted');
for(int i = 0; i < rows.size(); i++) {
String[] row = rows.get(i);
String errorcode = row[0];
// log.info(errorcode)
String errorDescription = row[1];
//log.info(errorDescription)
testRunner.testCase.testSuite.project.setPropertyValue('errorcode', errorcode);
testRunner.testCase.testSuite.project.setPropertyValue('errorDescription', errorDescription);
testRunner.runTestStepByName("createCard-1");
log.info(errorcode +"Finsihed")
}