Tuesday, July 24, 2012

Launch Error: Failed to connect to remote VM in Android

When I tried to launch the application on my device I kept getting this error,

Launch Error: Failed to connect to remote VM. Connection timed out

The normal searches for this will yield results, that ask the user to either restart eclipse or kill all the adp processes.

A more simple solution for this is to change the connection port. So what I did is that I went to eclipse Window > Preferences > Android > DDMS and change the port number. I changed it to 8601 and its working without a hitch.

Hope this helps.

Monday, July 23, 2012

Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder

I have just ventured into mobile development. So, surely I ran into some issues. When I wanted to run the application in eclipse it said that there was not emulator. I got around to add a new AVD, but got the error "Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder".

Turns out that I had not installed the "ARM EABI v7a System Image".

So all you have to do is navigate to Eclipse > Window > Android SDK Manager
Under the Android version you have installed you'll find "ARM EABI v7a System Image". 

Check this and  install it. Once done you'll have to restart eclipse and you're all set.

Friday, July 20, 2012

Flash Builder - Not creating HTML file

Sometime back I had this issue when I was not able to run the project I synced from my version control system. As soon I ran it, it gave me an error saying "Launch Failed - .html file not found. Unable to create html file."

Even after cleaning the project, the issue remains. Turns out that the solution is quite simple.

Just rebuild the project with "Generate HTML wrapper file" option in the Flex Compiler Settings, unchecked

And again build it with the option checked. And lo and behold, the files are created.


Thursday, July 19, 2012

Getting XML Output from SQL Query - Part 2

In Part 1 of this series we discusses the syntax that drives the query. In this post let us dig a bit deeper and actually write some queries that work. We will start off with a simple one and let the intricacies unfold.
I am assuming that you have  database table say "Students" as below,
studentId studentName age class parentId
1 Ankur 8 4 3
2 Akshay 7 2 1
3 Deepak 8 3 3
4 Esha 6 1 4
5 Pankaj 7 2 2
6 Raj 9 4 1
7 Rahul 8 3 5
8 Sahana 7 2 5
9 Samir 9 4 2
10 Triveni 8 3 3

and a parents table as below

parentId fathersName mothersName fathersOccupation mothersOccupation
1 Father1 Mother1 Occupation11 Occupation21
2 Father2 Mother2 Occupation12 Occupation22
3 Father3 Mother3 Occupation13 Occupation23
4 Father4 Mother4 Occupation14 Occupation24
5 Father5 Mother5 Occupation15 Occupation25

Let the fun start. What we will do first is just create an XML that lists all the students in XML format and then start into churning a more meaningful XML.
Select * From students Where studentId = 1
For XML Auto

<students studentId="1" studentName="Ankur" age="8" class="3" parentId="4" />

Select * From students Where studentId = 1
FOR XML RAW('Student');

<Student studentId="1" studentName="Ankur" age="8" class="3" parentId="4" />

Select * From students Where studentId = 1
FOR XML RAW('Student'), Root('Students');

   < Student studentId="1" studentName="Ankur" age="8" class="3" parentId="4" />

Select * From students Where studentId = 1
FOR XML PATH('Student'), Root('Students');

     <age>8 </age>
     <class>3 </class>

TextArea - moving focus on Return key press

If you have a TextArea in Flex with single line height and are using the Enter key to move the mouse focus to some other element, do prepare yourself to be amazed. What will happen when you click on Enter is that the mouse focus moves to the other element, but you won't be able to see any text in the TextArea.

What causes this is that TextArea is generally intended for multi-line input and so, internally it listens for the Enter key event and moves the cursor to the next line.Thus, when your text area has a single line height the text shifts upwards and out of sight.

The immediate resolution to this problem can be to use the TextInput (if you expect only single line input) or to override the textArea event handler and write your own implementation for the same.


Tuesday, July 17, 2012

Getting XML output from SQL Query - Part 1

With SQL Server 2005, SQL has added an interesting and useful element "FOR XML". FOR XML returns the output of a sql query in the XML format. In the following 2 part series, I will try to explain the basics of using the FOR XML and some nuances attached with it.

The syntax for FOR XML as per the msdn site is as below,
[ FOR { BROWSE |  } ]
      { RAW [ ('ElementName') ] | AUTO } 
           [ , { XMLDATA | XMLSCHEMA [ ('TargetNameSpaceURI') ]} ] 
           [ , ELEMENTS [ XSINIL | ABSENT ] 
      | EXPLICIT 
           [ , XMLDATA ] 
      | PATH [ ('ElementName') ] 
           [ , ELEMENTS [ XSINIL | ABSENT ] ]
   [ , BINARY BASE64 ]
   [ , TYPE ]
   [ , ROOT [ ('RootName') ] ]
While going through each element is beyond the scope of this post, very quickly I will explain the elements. Note that in the above syntax, the elements separated by "|" follow an OR relationship and cannot be used   together.
RAW: If the "ElementName" is unspecified, then the result set has a generic identifier "row"
AUTO: In this mode, the data is formatted based on the table and the columns selected in the SELECT query.
EXPLICIT: With this directive, one can shape the XML to their requirements, but great care is needed and, it is not as simple as it looks. You can also use CDATA with the EXPLICIT directive.
PATH: A simpler mode of creating additional nesting for representing complex properties. By default the    "row" element is used as the parent identifier but this can be changed as required
XMLDATA: With this the schema/document structure can be added to the resulting XML
XMLSCHEMA: With this the XSD schema is added to the resulting XML
ELEMENTS: When specified the columns are returned as subelements. In absence of this, the columns areappended to the parent as attributes
XSINIL:Specifying this allows the data to be returned as xsi:nil="true" in case the column value is null 
ABSENT: This indicates that the columns with null values will not be added to the resulting XML
BINARY BASE64: Returns the specified data in a binary base64 encoded format
TYPE: Indicates that the query should return data as an xml type
ROOT: Specifies the top level element for the resulting XML. By default it is "root", but one can specify thename for the root node.

File I/O with Java

I have started dabbling a bit in Java recently and well you can call it a silly mistake but this problem did ruffle my feathers. I was trying to append the contents of my query data to a file and all of my code as seen below seemed proper.

 File csvFile = new File("D:\\Work\\myFolder\\myFile.csv");
 FileWriter fstream = new FileWriter(csvFile.getName(), true);
 BufferedWriter out = new BufferedWriter(fstream);
catch (Exception e)
 System.err.println("Error: " + e.getMessage());

But essentially it did not work. The file was created but nothing was written in it. A little while and some research I figured out the problem. 
So basically one needs to either supply the "file" or the complete "filePath" as the parameter to the FileWriter class. Just the name doesn't do it, except if the file resides in the root folder. So we can use either one of the two.
 FileWriter fstream = new FileWriter(csvFile, true);


 FileWriter fstream = new FileWriter(csvFile.getPath(), true);