I have tried putting a spinner in an app, both from books and several
online tutorials, and it keeps locking up.  It seems like my emulator
doesn't like when I set the adapter the the array list.  I even made a
test project just to try the spinner itself, but to no avail.  I'm
doing the same code that others say work, but it doesn't for me.  Any
ideas?

Here's the main XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
        android:id="@+id/test_result"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<Spinner android:id="@+id/spin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
/>
</LinearLayout>


...the code:


import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class SpinTest extends Activity {

        TextView testResult;

        private List<String> allUnits;
        Spinner spin;
        ArrayAdapter <String> adapter;

        private String[] units = { "Carrier", "Battle ship", "Cruiser",
"Destroyer", "Frigate", "Submarine", "Boomer" };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        testResult = (TextView)findViewById(R.id.test_result);
        Log.d("onCreate", "testResult id found");

        spin =(Spinner)findViewById(R.id.spin);
                Log.d("onCreate", "spinner id found");

                allUnits = new ArrayList<String>();
                for(String s: units ){
                        allUnits.add(s);
                }
                Log.d("onCreate", "arraylist created");

                adapter = new ArrayAdapter <String> (this,
                                android.R.layout.simple_spinner_item, allUnits);
                Log.d("onCreate","new adapter made");

                adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
                Log.d("onCreate", "adapter layout set");

                spin.setAdapter(adapter);
                Log.d("onCreate", "spinner adapter set");

        setContentView(R.layout.main);
    }
}


...and finally, the last portion of the log:


01-09 12:17:15.376: WARN/ActivityThread(176): Application
com.mylib.SpinTest is waiting for the debugger on port 8100...
01-09 12:17:15.384: INFO/System.out(176): Sending WAIT chunk
01-09 12:17:15.427: INFO/dalvikvm(176): Debugger is active
01-09 12:17:15.585: INFO/System.out(176): Debugger has connected
01-09 12:17:15.605: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:15.804: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:16.004: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:16.237: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:16.454: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:16.495: DEBUG/dalvikvm(52): GC freed 3217 objects / 211888
bytes in 537ms
01-09 12:17:16.654: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:16.864: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:17.065: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:17.125: INFO/ActivityManager(52): Start proc
com.android.alarmclock for broadcast
com.android.alarmclock/.AlarmInitReceiver: pid=186 uid=10000 gids={}
01-09 12:17:17.184: INFO/ActivityManager(52): processNextBroadcast:
waiting for ProcessRecord{4348b1b8 186:com.android.alarmclock/10000}
01-09 12:17:17.284: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:17.335: INFO/jdwp(186): received file descriptor 10 from
ADB
01-09 12:17:17.424: DEBUG/PhoneApp(91): [CallNotifier] onMwiChanged():
false
01-09 12:17:17.444: DEBUG/PhoneApp(91): [CallNotifier] onCfiChanged():
false
01-09 12:17:17.485: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:17.684: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:17.704: WARN/StkAppInstaller(91): Could not change STK app
state
01-09 12:17:17.754: INFO/ARMAssembler(52): generated
scanline__00000077:03515104_00000000_00000000 [ 27 ipp] (41 ins) at
[0x227f48:0x227fec] in 3006597 ns
01-09 12:17:17.764: DEBUG/TelephonyProvider(91): Setting numeric
'310260' to be the current operator
01-09 12:17:17.894: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:17.974: INFO/ActivityThread(186): Publishing provider
com.android.alarmclock: com.android.alarmclock.AlarmProvider
01-09 12:17:18.094: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:18.295: DEBUG/MobileDataStateTracker(52): CONNECTED event
did not supply interface name.
01-09 12:17:18.295: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:18.304: DEBUG/MobileDataStateTracker(52): DNS server
addresses are not known.
01-09 12:17:18.345: ERROR/NetworkStateTracker(52): Can't set tcp
buffer sizes:java.io.FileNotFoundException: /sys/kernel/ipv4/
tcp_rmem_min
01-09 12:17:18.454: DEBUG/GpsLocationProvider(52): updateNetworkState
available
01-09 12:17:18.475: DEBUG/GpsLocationProvider(52): NetworkThread out
of wake loop
01-09 12:17:18.475: DEBUG/GpsLocationProvider(52): Requesting time
from NTP server pool.ntp.org
01-09 12:17:18.506: INFO/System.out(176): waiting for debugger to
settle...
01-09 12:17:18.675: DEBUG/SntpClient(52): round trip: 56 ms
01-09 12:17:18.715: INFO/System.out(176): debugger has settled (1392)
01-09 12:17:18.734: DEBUG/SntpClient(52): clock offset: 25526 ms
01-09 12:17:18.734: DEBUG/GpsLocationProvider(52): calling
native_inject_time: 1231478264148 reference: 41807 certainty: 28
01-09 12:17:18.814: DEBUG/GpsLocationProvider(52): NetworkThread wait
for 14400000ms
01-09 12:17:19.015: INFO/CheckinService(52): Checkin triggered: Intent
{ action=android.server.checkin.CHECKIN flags=0x4 (has extras) }
01-09 12:17:19.015: INFO/CheckinService(52): Checkin disabled by
system property
01-09 12:17:19.234: INFO/ActivityManager(52): Start proc
android.process.media for broadcast
com.android.providers.downloads/.DownloadReceiver: pid=194 uid=10003
gids={1006, 3003, 2001}
01-09 12:17:19.345: INFO/jdwp(194): received file descriptor 10 from
ADB

**** showing the logs here:****

01-09 12:17:19.495: DEBUG/onCreate(176): testResult id found
01-09 12:17:19.495: DEBUG/onCreate(176): spinner id found
01-09 12:17:19.495: DEBUG/onCreate(176): arraylist created
01-09 12:17:19.514: DEBUG/onCreate(176): new adapter made
01-09 12:17:19.536: DEBUG/onCreate(176): adapter layout set

**** never makes it past spin.setAdapter(adapter); for some strange
reason ****

01-09 12:17:19.795: INFO/ActivityThread(194): Publishing provider
downloads: com.android.providers.downloads.DownloadProvider
01-09 12:17:20.045: INFO/ActivityThread(194): Publishing provider drm:
com.android.providers.drm.DrmProvider
01-09 12:17:20.155: INFO/ActivityThread(194): Publishing provider
media: com.android.providers.media.MediaProvider
01-09 12:17:20.365: VERBOSE/MediaProvider(194): Attached volume:
internal
01-09 12:17:20.915: DEBUG/MediaScannerService(194): start scanning
volume internal
01-09 12:17:21.515: WARN/WindowManager(52): App freeze timeout
expired.
01-09 12:17:21.515: WARN/WindowManager(52): Force clearing freeze:
AppWindowToken{43487998 token=HistoryRecord{4348b3e8
{com.ninjadice.SpinTest/com.ninjadice.SpinTest.SpinTest}}}
01-09 12:17:21.805: INFO/ActivityManager(52): Stopping service:
com.android.providers.downloads/.DownloadService
01-09 12:17:21.975: DEBUG/dalvikvm(52): GREF has increased to 201
01-09 12:17:22.045: DEBUG/MediaScanner(194):  prescan time: 673ms
01-09 12:17:22.045: DEBUG/MediaScanner(194):     scan time: 254ms
01-09 12:17:22.125: DEBUG/MediaScanner(194): postscan time: 90ms
01-09 12:17:22.125: DEBUG/MediaScanner(194):    total time: 1017ms
01-09 12:17:22.245: DEBUG/MediaScannerService(194): done scanning
volume internal
01-09 12:17:22.288: INFO/ActivityManager(52): Stopping service:
com.android.providers.media/.MediaScannerService
01-09 12:17:22.325: INFO/ActivityManager(52): Stopping service:
com.android.mms/.transaction.TransactionService
01-09 12:17:22.495: INFO/ActivityManager(52): Stopping service:
com.android.providers.downloads/.DownloadService
01-09 12:17:22.546: INFO/ActivityManager(52): Stopping service:
com.android.mms/.transaction.SmsReceiverService
01-09 12:17:23.635: DEBUG/dalvikvm(52): GC freed 4323 objects / 177376
bytes in 121ms
01-09 12:17:24.725: WARN/ActivityManager(52): Launch timeout has
expired, giving up wake lock!
01-09 12:17:25.281: WARN/ActivityManager(52): Activity idle timeout
for HistoryRecord{4348b3e8 {com.ninjadice.SpinTest/
com.ninjadice.SpinTest.SpinTest}}
01-09 12:17:30.375: DEBUG/dalvikvm(91): GC freed 3589 objects / 187184
bytes in 91ms
01-09 12:17:35.384: DEBUG/dalvikvm(97): GC freed 2043 objects / 98304
bytes in 87ms
01-09 12:17:40.415: DEBUG/dalvikvm(125): GC freed 2335 objects /
129376 bytes in 100ms
01-09 12:18:31.065: DEBUG/KeyguardViewMediator(52): pokeWakelock(5000)
01-09 12:18:41.175: WARN/WindowManager(52): Key dispatching timed out
sending to <null>
01-09 12:18:41.175: WARN/WindowManager(52): Continuing to wait for key
to be dispatched


Any thoughts on what might be wrong would be appreciated!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to