Recent Notes

Displaying keyword search results 11 - 20
Created by magnum on September 25, 2011 21:51:23    Last update: September 26, 2011 20:49:22
A simple socket client in C. #include <stdio.h> #include <stdlib.h> #incl...
Created by freyo on September 07, 2011 16:46:14    Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...
Created by voodoo on August 14, 2011 15:42:43    Last update: August 14, 2011 15:42:43
When I ran this code snippet with strace : f = fopen("TZ", "rb"); fseek(f, 0, SEEK_END); ... I saw ENOTTY error with uClibc : open("TZ", O_RDONLY|O_LARGEFILE) = 3 ioc... With the normal gnu libc , there's no such error: open("TZ", O_RDONLY) = 3 fstat64... There was no error running the program. But for some reason, uClibc did a ioctl call when it opened a file, and handled it appropriately.
Created by Dr. Xi on July 11, 2011 12:24:10    Last update: July 11, 2011 12:25:44
This code snippet import java.util.*; public class UncheckedCast ... fails with a compilation error and a warning: $ javac -Xlint:unchecked UncheckedCast.java Unc... Because List<String> is not a reifiable type, the Java Runtime does not have enough information to verify the type or do the type casting. This is fixed by changing List<String> to List<?> (or to the raw type List ): public static void main(String[] args) { Ob...
Created by freyo on June 30, 2011 11:15:48    Last update: June 30, 2011 11:15:48
Install APK with adb : $ platform-tools/adb install out/target/product/ge... Error message in logcat: D/PackageParser( 60): Scanning package: /data/ap... The error was created by android.content.pm.PackageParser , which compares the android:minSdkVersion and android:targetSdkVersion attributes of the uses-sdk element of AndroidManifest.xml in the APK file against the SDK version of the device or emulator. The SDK version on the device has to be greater than that required by android:minSdkVersion . In my case, since I built the package with AOSP, the target emulator has to be AOSP also. This is the relavant section in AndroidManifest.xml : <uses-sdk android:minSdkVersion="AOSP" ... And the relevant section in android.content.pm.PackageParser : if (minCode != null) { if (!minCode.equals(...
Created by freyo on May 17, 2011 11:13:17    Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with: tools/android create project --package com.android... Create assets directory and add an XML file ( assets/demo.xml ): <? xml version="1.0" encoding="UTF-8"?> <people... Edit the layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Edit src/com/android/cptest/Dummy.java : package com.android.cptest; import java.io.... Add content provider ( src/com/android/cptest/XmlResource.java ): package com.android.cptest; import java.io.... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Add this section to the end of build.xml : <target name="-package-resources"> <ech... Build and install: ant install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by freyo on May 17, 2011 08:46:50    Last update: May 17, 2011 08:47:35
When I used AssetManager to open an XML file in a ContentProvider : getContext().getAssets().openFd("demo.xml"); it failed with this exception: java.io.FileNotFoundException: This file can not b... It turned out that openFd only works for asset files that are not compressed. It works on media files such as .mp3 , .jpg , .wmv etc., which are not compressed during packaging. XML files are compressed by dedault, causing openFd to fail. An Android ticket was opened on this issue. Till that is fixed, the workaround is to add an exclusion in build.xml : <?xml version="1.0" encoding="UTF-8"?> <pro...
Created by jinx on May 16, 2011 20:55:53    Last update: May 16, 2011 20:55:53
The PHP break statement takes an optional level parameter, which indicates how many levels of loop structure to break out. Example code: <?php for ($i = 0; $i < 5; $i++) { for (... It's a fatal error if the level parameter exceeds the maximum number of enclosing loop structures. For example, " break 3; " in above code.
Created by jinx on May 03, 2011 08:56:55    Last update: May 03, 2011 08:57:54
These error level constants are defined in PHP : Constant Value Description E_ERROR 1 Fatal run-time errors. Execution of the script is halted. E_WARNING 2 (1<<1) Run-time warnings (non-fatal errors). Execution of the script is not halted. E_PARSE 4 (1<<2) Compile-time parse errors. Parse errors should only be generated by the parser. E_NOTICE 8 (1<<3) Notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. E_CORE_ERROR 16 (1<<4) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. E_CORE_WARNING 32 (1<<5) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated...
Created by jinx on April 25, 2011 12:43:40    Last update: April 25, 2011 12:43:40
Use the PHP function method_exists to check if the class or object has a certain method. It returns TRUE if the method exists (even when the value of the property is NULL), FALSE if the method does not exist. Example: <?php class A { var $p = 'A property'; ... Outputs: Class A has method f1: bool(true) Object $a has... Also note that C++-like method overloading does not exist in PHP. Thus there's no ambiguity about which version of the method exists, i.e., with no argument, with one argument... etc. The following code generates Fatal error: <?php class A { var $p = 'A property'; ...
Previous  1 2 3 4 Next