Autore Topic: Simple Adapter Personalizzato  (Letto 643 volte)

Offline tanuccio85

  • Nuovo arrivato
  • *
  • Post: 34
  • Respect: 0
    • Mostra profilo
Simple Adapter Personalizzato
« il: 25 Maggio 2011, 12:27:56 CEST »
0
Salve ragazzi sto cercando di implementare un SimpleAdapter che prenda dei dati di un Content Provider e aggiunga una foto ad ogni riga,ho provato ad implementare ma mi da un errore strano .....potete aiutarmi?? Grazie

Codice Java:
Codice (Java): [Seleziona]
public class SimpleAdapterActivity extends Activity {
    /** Called when the activity is first created. */
       
        /*variabili di istanza*/
        private SimpleAdapter adapter;
        private Cursor c;
        private final static Uri PARK_TEAM_URI = Uri.parse("content://com.simpleprovider.SimpleProvider/park");
        private String[] FROMS = new String[] { "image",ParkMetaData.NAME,ParkMetaData.INDIRIZZO,ParkMetaData.POSTI,ParkMetaData.POSTI_LIBERI,ParkMetaData.COSTO};
        private int[] TOS = new int[] {R.id.parkImage, R.id.parkName,R.id.parkInd,R.id.parkPosti,R.id.parkPostiLiberi,R.id.parkCosto };
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listpark);
        ListView list=(ListView)findViewById(R.id.parkList);
        Drawable StartImg = getResources().getDrawable(R.drawable.cerchio_verde);
       
        c = getContentResolver().query(PARK_TEAM_URI,null,null,null,null);
        //Park [] parkss;
     
        ArrayList<HashMap<String, Object>> data=new ArrayList<HashMap<String,Object>>();
        while(c.moveToNext()){
                HashMap<String,Object> parkMap=new HashMap<String, Object>();
                parkMap.put("image", StartImg);
                parkMap.put(ParkMetaData.NAME, c.getString(1));
                parkMap.put(ParkMetaData.INDIRIZZO, c.getString(2));
                parkMap.put(ParkMetaData.POSTI, c.getInt(3));
                parkMap.put(ParkMetaData.POSTI_LIBERI, c.getInt(4));
                parkMap.put(ParkMetaData.COSTO, c.getDouble(5));
                data.add(parkMap);
               
               
        }
        adapter = new SimpleAdapter(this, data, R.layout.row_layout,
                                FROMS, TOS);
               
               
    }
}


LogCat:


Codice: [Seleziona]
05-25 10:24:54.992: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
05-25 10:24:54.992: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
05-25 10:24:54.992: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
05-25 10:24:54.992: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
05-25 10:25:11.892: ERROR/BatteryService(59): usbOnlinePath not found
05-25 10:25:11.901: ERROR/BatteryService(59): batteryVoltagePath not found
05-25 10:25:11.901: ERROR/BatteryService(59): batteryTemperaturePath not found
05-25 10:25:11.952: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
05-25 10:25:19.312: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
05-25 10:25:19.312: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
05-25 10:25:19.702: ERROR/System(59): Failure starting core service
05-25 10:25:19.702: ERROR/System(59): java.lang.SecurityException
05-25 10:25:19.702: ERROR/System(59):     at android.os.BinderProxy.transact(Native Method)
05-25 10:25:19.702: ERROR/System(59):     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
05-25 10:25:19.702: ERROR/System(59):     at android.os.ServiceManager.addService(ServiceManager.java:72)
05-25 10:25:19.702: ERROR/System(59):     at com.android.server.ServerThread.run(SystemServer.java:176)
05-25 10:25:19.712: ERROR/AndroidRuntime(59): Crash logging skipped, no checkin service
05-25 10:25:31.492: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)
05-25 10:25:32.252: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound
05-25 10:25:32.292: ERROR/MediaPlayer(59): Unable to to create media player
05-25 10:25:41.452: ERROR/AndroidRuntime(147): ERROR: thread attach failed
05-25 10:25:48.812: ERROR/ActivityThread(59): Failed to find provider info for com.google.settings
05-25 10:25:48.832: ERROR/ActivityThread(59): Failed to find provider info for com.google.settings
05-25 10:25:49.372: ERROR/AndroidRuntime(188): ERROR: thread attach failed
05-25 10:25:50.352: ERROR/AndroidRuntime(226): Uncaught handler: thread main exiting due to uncaught exception
05-25 10:25:50.382: ERROR/AndroidRuntime(226): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simpleAdapter/com.simpleAdapter.SimpleAdapterActivity}: java.lang.ClassCastException: android.widget.ImageView
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.os.Looper.loop(Looper.java:123)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at java.lang.reflect.Method.invokeNative(Native Method)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at java.lang.reflect.Method.invoke(Method.java:521)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at dalvik.system.NativeStart.main(Native Method)
05-25 10:25:50.382: ERROR/AndroidRuntime(226): Caused by: java.lang.ClassCastException: android.widget.ImageView
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at com.simpleAdapter.SimpleAdapterActivity.onCreate(SimpleAdapterActivity.java:33)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     ... 11 more
05-25 10:26:02.702: ERROR/gralloc(59): [unregister] handle 0x48bdb0 still locked (state=40000001)
05-25 10:53:07.232: ERROR/AndroidRuntime(239): ERROR: thread attach failed
05-25 10:53:09.372: ERROR/AndroidRuntime(247): ERROR: thread attach failed
05-25 10:53:10.472: ERROR/AndroidRuntime(254): Uncaught handler: thread main exiting due to uncaught exception
05-25 10:53:10.502: ERROR/AndroidRuntime(254): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simpleAdapter/com.simpleAdapter.SimpleAdapterActivity}: java.lang.ClassCastException: android.widget.ImageView
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.os.Looper.loop(Looper.java:123)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at java.lang.reflect.Method.invokeNative(Native Method)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at java.lang.reflect.Method.invoke(Method.java:521)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at dalvik.system.NativeStart.main(Native Method)
05-25 10:53:10.502: ERROR/AndroidRuntime(254): Caused by: java.lang.ClassCastException: android.widget.ImageView
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at com.simpleAdapter.SimpleAdapterActivity.onCreate(SimpleAdapterActivity.java:33)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-25 10:53:10.502: ERROR/AndroidRuntime(254):     ... 11 more
05-25 11:13:12.502: ERROR/AndroidRuntime(262): ERROR: thread attach failed
05-25 11:13:16.352: ERROR/AndroidRuntime(273): ERROR: thread attach failed
05-25 11:13:17.552: ERROR/AndroidRuntime(279): Uncaught handler: thread main exiting due to uncaught exception
05-25 11:13:17.572: ERROR/AndroidRuntime(279): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simpleAdapter/com.simpleAdapter.SimpleAdapterActivity}: java.lang.ClassCastException: android.widget.ImageView
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.os.Looper.loop(Looper.java:123)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at java.lang.reflect.Method.invokeNative(Native Method)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at java.lang.reflect.Method.invoke(Method.java:521)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at dalvik.system.NativeStart.main(Native Method)
05-25 11:13:17.572: ERROR/AndroidRuntime(279): Caused by: java.lang.ClassCastException: android.widget.ImageView
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at com.simpleAdapter.SimpleAdapterActivity.onCreate(SimpleAdapterActivity.java:33)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-25 11:13:17.572: ERROR/AndroidRuntime(279):     ... 11 more

Codice (XML): [Seleziona]
<?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">
       
        <ListView
               android:id="@+id/parkList"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent">
        </ListView>






</LinearLayout>
Grazie per l'attenzione se volete altre informazioni non esitate a chiedermele
« Ultima modifica: 25 Maggio 2011, 14:14:58 CEST da Ricky` »

Offline MarcoDuff

  • Moderatore globale
  • Utente storico
  • *****
  • Post: 1073
  • Respect: +202
    • Google+
    • marcoduff
    • Mostra profilo
    • MarcoDuff's Blog
  • Dispositivo Android:
    Samsung Galaxy Nexus
  • Play Store ID:
    MarcoDuff
  • Sistema operativo:
    Windows 7
Re:Simple Adapter Personalizzato
« Risposta #1 il: 25 Maggio 2011, 14:13:00 CEST »
0
Il logcat sembra chiaro sulla causa dell'errore:

Codice: [Seleziona]
05-25 10:25:50.382: ERROR/AndroidRuntime(226): Caused by: java.lang.ClassCastException: android.widget.ImageView
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at com.simpleAdapter.SimpleAdapterActivity.onCreate(SimpleAdapterActivity.java:33)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-25 10:25:50.382: ERROR/AndroidRuntime(226):     ... 11 more

cosa non riesci a sistemare?

Offline tanuccio85

  • Nuovo arrivato
  • *
  • Post: 34
  • Respect: 0
    • Mostra profilo
Re:Simple Adapter Personalizzato
« Risposta #2 il: 25 Maggio 2011, 14:57:13 CEST »
0
beh l'errore del log cat l'ho risolto (avevo mancato una cosa nel Manifest)solo che non riesco ad inserire la foto nel SimpleAdapter


RISOLTO tutto ok
« Ultima modifica: 25 Maggio 2011, 15:09:22 CEST da tanuccio85 »