EmptyStackException in Android Layout Editor

Under very specific (and obscure) circumstances, the Android Layout Editor throws an EmptyStackException when the ‘graphical layout’ tab is selected.

The conditions are unlikely to occur, but I did run into this problem yesterday:

subclass TextView to create a custom widget
– create a style for that widget
– specify the text item in the style; not in the widget definition

This may be specific to Android SDK 15; I updated to that release shortly before the problem occurred.

I posted a complete explanation on Stack Overflow at http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds/7943310#7943310 – some of it is repeated below.

I also submitted a bug report to Google’s bug database at http://code.google.com/p/android/issues/detail?id=21375.  I attached a test program to that report; it may be downloaded from the bottom of that page.

The gist of the bug is:

res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical">

     <com.ajw.DemoCrashInADT.AutoResizeTextView
         android:id="@+id/resizingText"
         style="@style/myTextStyle"/>

</LinearLayout>

res/values/myStyles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

     <stylename="myTextStyle"parent="@android:style/Widget.TextView">
         <item name="android:layout_height">wrap_content</item>
         <item name="android:layout_width">fill_parent</item>
         <item name="android:text">some message</item>
     </style>

</resources>

With these, open main.xml and select the graphical layout tab.  The exception appears at the bottom of the graphical layout.

 

Advertisements

getting AdMob ads in the Android emulator

The emulator uses the first NIC it finds, whether that one actually has access to the Internet or not.
(NIC = Network Interface Controller – aka network adapter)

If it doesn’t, the emulator won’t be able to access the Internet.  This made testing AdMob adverting in my app rather difficult.

My develoment machine (actually, virtual machine, but that’s beside the point) has two NICs; the emulator locks onto the wrong one.

My workaround is to disable all the NICs except for the one the emulator should use, then start the emulator.  The emulator will use the only enabled NIC, and will be able to access the Internet, and be able to show AdMob advertising.

It’s safe to re-enable any other NICs until the emulator is closed.  When you restart the emulator you’ll have to disable the other NICs again.

If anyone knows of settings to force the emulator to use a specific NIC, please let me know.  (I don’t use a proxy, btw.)

All the best,
Alan

excursions into Android development

I’ve started doing some Android development on my own apps.  It’s been interesting – some genuinely and some in the “oh, God! oh, God! We’re all gonna die!” interesting.

I’ll post more about it soon – especially some of the tips I’ve discovered  (or, more accurately, stumbled across…   :)

%d bloggers like this: