Monday, 16 August 2010

Capturing logs from Android application

Install by Log Collector Xtralogic Inc

in your code

import android.util.Log;

Log.e("", "failed because " + e);

Run your application on your device

Force the error to happen.

Click on the log collector application - this will prompt you to choose the format you want ( like email to googlemail)

The email will arrive containing your log and your error can be easily seen an interpreted below:


08-16 18:23:46.625 E/JavaBinder( 1104): at dalvik.system.NativeStart.run(Native Method)
08-16 18:23:46.625 W/dalvikvm(10190): threadid=3: thread exiting with uncaught exception (group=0x2aadda10)
08-16 18:23:46.635 E/AndroidRuntime(10190): Uncaught handler: thread main exiting due to uncaught exception
08-16 18:23:46.645 E/AndroidRuntime(10190): java.lang.NullPointerException
08-16 18:23:46.645 E/AndroidRuntime(10190): at com.sampleapp.MainActivity.loadContacts(MainActivity.java:582)
08-16 18:23:46.645 E/AndroidRuntime(10190): at com.sampleapp.MainActivity.getSwitchNumber(MainActivity.java:362)
08-16 18:23:46.645 E/AndroidRuntime(10190): at com.sampleapp.MainActivity.settingsPage(MainActivity.java:271)
08-16 18:23:46.645 E/AndroidRuntime(10190): at com.sampleapp.MainActivity.access$5(MainActivity.java:266)

Tuesday, 10 August 2010

maven debugging

So I know there is a -e switch for debug but if you really want debug, try this

mvn -X compile

Tuesday, 3 August 2010

Android 1.6 Reading Contacts name and phone numbers

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(People.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
NAMES = new String[cur.getCount()];
int j =0;
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(People._ID));
String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
NAMES[j] = name;
j++;
Cursor pCur = cr.query(
Contacts.Phones.CONTENT_URI,
null,
Contacts.Phones.PERSON_ID +" = ?",
new String[]{id}, null);
int i=0;
int pCount = pCur.getCount();
String[] phoneNum = new String[pCount];
String[] phoneType = new String[pCount];
while (pCur.moveToNext()) {
phoneNum[i] = pCur.getString(
pCur.getColumnIndex(Contacts.Phones.NUMBER));
phoneType[i] = pCur.getString(
pCur.getColumnIndex(Contacts.Phones.TYPE));
i++;
}
}




}

Monday, 2 August 2010

Android textview bottom right hand corner

To align your text inside a text view to the bottom right hand corner add this to your TextView tag in the xml file.

android:gravity="right|bottom"

More options available here in the api:

http://developer.android.com/reference/android/R.styleable.html#TextView_gravity

Adding html code snippet to your eblogger blog

Enter the code here

http://www.blogcrowds.com/resources/parse_html.php

copy the output into your new post

Android 2 ways to hide the title bar

In the code:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
}


In the AndroidManifest.xml

<activity android:name=".YourClassNameHere"
android:theme="@android:style/Theme.NoTitleBar">
</activity>

Friday, 30 July 2010

Forwarded to me from a friend

class fun {

public static void main(String[] args)
{

Integer a=10; Integer b=10; Integer c=1000; Integer d=1000;

System.out.println(a==b);//true
System.out.println(c==d);//false }

};

http://www.owasp.org/index.php/Java_gotchas#Immutable_Objects_.2F_Wrapper_Class_Caching

http://tech.puredanger.com/2007/02/01/valueof/