Autore Topic: Crash nel passaggioda una activity a un'altra  (Letto 1078 volte)

Offline gbon

  • Nuovo arrivato
  • *
  • Post: 15
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Wildfire
Crash nel passaggioda una activity a un'altra
« il: 01 Febbraio 2011, 00:28:56 CET »
0
Probabilmente l'errore e' solo frutto della mia inesperienza, ma non ne vengo fuori.

Il problema è questo: ho due activity: la principale (TS2011) richiama la secondaria (choose_wine)

La principale mostra una lista di regioni, da cui scegiere, con questo codice

Codice (Java): [Seleziona]
package COM.HANDERGY.TS2011;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class TS2011 extends ListActivity {
    /** Called when the activity is first created. */
        Intent intent;
/**     intent = new Intent(getApplicationContext(), Activity2.class); */
       
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
/**       setTitle ("Scegli la regione settitle"); */
/**       setBackgroundColor ("#012345"); */
          intent=new Intent(getApplicationContext(), choose_wine.class);

          setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

          ListView lv = getListView();
          lv.setTextFilterEnabled(true);

          lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
              // When clicked, show a toast with the TextView text
              Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                  Toast.LENGTH_SHORT).show();
              startActivity(intent);
            }
          });
        }
   
    static final String[] COUNTRIES = new String[] {
        "Piemonte", "Valle d'Aosta", "Lombardia", "Veneto", "Trentino Alto-Adige", "Sicilia"
      };
   
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.pref:     Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
            intent=new Intent(getApplicationContext(), show_info.class);                    
            break;
            case R.id.info:     Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
                                break;

        }
        return true;
    }
}

Sulla secondaria al momento chiedo solo di visualizzare un layout

Codice (Java): [Seleziona]
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.TextView;

public class choose_wine extends ListActivity {
       
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.choose_wine);
               
               
               TextView tv = new TextView(this);
               tv.setText("Hello, Android");
               setContentView(tv);
        }

}

Non funziona. Ecco anche il risultato di LogCat:

Codice (XML): [Seleziona]
02-01 00:10:11.623: ERROR/AndroidRuntime(609):     at android.app.Activity.setContentView(Activity.java:1668)
02-01 00:10:11.623: ERROR/AndroidRuntime(609):     at COM.HANDERGY.TS2011.choose_wine.onCreate(choose_wine.java:14)
02-01 00:10:11.623: ERROR/AndroidRuntime(609):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-01 00:10:11.623: ERROR/AndroidRuntime(609):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
02-01 00:10:11.623: ERROR/AndroidRuntime(609):     ... 11 more
02-01 00:10:11.703: WARN/ActivityManager(61):   Force finishing activity COM.HANDERGY.TS2011/.choose_wine
02-01 00:10:11.735: WARN/ActivityManager(61):   Force finishing activity COM.HANDERGY.TS2011/.TS2011
02-01 00:10:11.954: DEBUG/dalvikvm(61): GC_CONCURRENT freed 1018K, 46% free 4336K/8007K, external 2444K/2833K, paused 8ms+9ms
02-01 00:10:12.244: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{407a6318 COM.HANDERGY.TS2011/.choose_wine}

Grazie,

Gbon
« Ultima modifica: 01 Febbraio 2011, 09:53:28 CET da Nicola_D, Reason: Il codice Java va nel tag JAVA (il tasto con la tazzina)!!! »

Offline Giovanni D'Addabbo

  • Utente normale
  • ***
  • Post: 163
  • Respect: +8
    • Google+
    • giovannid
    • giovanni.daddabbo
    • magoscuro
    • Mostra profilo
    • Rhubbit.it - Sviluppo app Android/iOs
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Rhubbit srl
  • Sistema operativo:
    Windows/Mac/Linux
Re:Crash nel passaggioda una activity a un'altra
« Risposta #1 il: 01 Febbraio 2011, 09:06:46 CET »
0
uhm...hai inserito la nuova activity nel manifest? (capita spesso di scordarsi di fare questo passaggio obbligato)

Offline blackgin

  • Moderatore globale
  • Utente storico
  • *****
  • Post: 1387
  • Respect: +164
    • Google+
    • blackgins
    • blackginsoft
    • Mostra profilo
  • Dispositivo Android:
    Galaxy Nexus
  • Sistema operativo:
    Mac OSX 10.8
Re:Crash nel passaggioda una activity a un'altra
« Risposta #2 il: 01 Febbraio 2011, 09:24:35 CET »
0
Cominque il logcat é troncato.. Posts quello completo se il problems non é quello doors accennato

PS. Usa il tag Java quando post codice Java. Hai usato il tag XML ;)
« Ultima modifica: 01 Febbraio 2011, 09:26:09 CET da blackgin »
Postate il LogCat LogCat LogCat LogCat LogCat

Offline Qlimax

  • Moderatore globale
  • Utente senior
  • *****
  • Post: 757
  • Respect: +202
    • Google+
    • _Qlimax
    • Mostra profilo
    • www.egsolutions.ch
  • Dispositivo Android:
    Galaxy Nexus - Nexus One - Wildfire - Magic
  • Play Store ID:
    egsolutions.ch
  • Sistema operativo:
    Ubuntu 12.04, Windows 7
Re:Crash nel passaggioda una activity a un'altra
« Risposta #3 il: 01 Febbraio 2011, 09:48:21 CET »
0
L'errore potrebbe essere causato dal fatto che chiami setContentView  2 volte all'interno di onCreate nella seconda Activity.
In ogni caso, posta il logcat dell'errore completo.
« Ultima modifica: 01 Febbraio 2011, 09:50:26 CET da Qlimax »

Offline gbon

  • Nuovo arrivato
  • *
  • Post: 15
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Wildfire
Re:Crash nel passaggioda una activity a un'altra
« Risposta #4 il: 01 Febbraio 2011, 23:12:25 CET »
0
Metto il logcat completo:

Codice: [Seleziona]
02-01 23:10:09.584: VERBOSE/BackupManagerService(61): Backup requested but nothing pending
02-01 23:10:24.214: DEBUG/AndroidRuntime(472): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-01 23:10:24.224: DEBUG/AndroidRuntime(472): CheckJNI is ON
02-01 23:10:25.065: DEBUG/AndroidRuntime(472): Calling main entry com.android.commands.pm.Pm
02-01 23:10:25.115: DEBUG/AndroidRuntime(472): Shutting down VM
02-01 23:10:25.135: INFO/AndroidRuntime(472): NOTE: attach of thread 'Binder Thread #3' failed
02-01 23:10:25.135: DEBUG/dalvikvm(472): GC_CONCURRENT freed 101K, 71% free 297K/1024K, external 0K/0K, paused 2ms+2ms
02-01 23:10:25.144: DEBUG/dalvikvm(472): Debugger has detached; object registry had 1 entries
02-01 23:10:25.765: DEBUG/AndroidRuntime(482): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-01 23:10:25.765: DEBUG/AndroidRuntime(482): CheckJNI is ON
02-01 23:10:26.745: DEBUG/AndroidRuntime(482): Calling main entry com.android.commands.am.Am
02-01 23:10:26.795: INFO/ActivityManager(61): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=COM.HANDERGY.TS2011/.TS2011 } from pid 482
02-01 23:10:26.875: INFO/ActivityManager(61): Start proc COM.HANDERGY.TS2011 for activity COM.HANDERGY.TS2011/.TS2011: pid=491 uid=10046 gids={1015}
02-01 23:10:26.925: DEBUG/AndroidRuntime(482): Shutting down VM
02-01 23:10:26.985: INFO/AndroidRuntime(482): NOTE: attach of thread 'Binder Thread #3' failed
02-01 23:10:27.015: DEBUG/dalvikvm(482): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 2ms+39ms
02-01 23:10:27.015: DEBUG/jdwp(482): Got wake-up signal, bailing out of select
02-01 23:10:27.015: DEBUG/dalvikvm(482): Debugger has detached; object registry had 1 entries
02-01 23:10:28.995: INFO/ActivityManager(61): Displayed COM.HANDERGY.TS2011/.TS2011: +2s138ms (total +39m14s713ms)
02-01 23:10:29.635: DEBUG/dalvikvm(61): GC_CONCURRENT freed 847K, 46% free 4199K/7751K, external 2036K/2377K, paused 8ms+9ms
02-01 23:10:31.034: INFO/ActivityManager(61): Starting: Intent { cmp=COM.HANDERGY.TS2011/.choose_wine } from pid 491
02-01 23:10:31.184: DEBUG/AndroidRuntime(491): Shutting down VM
02-01 23:10:31.184: WARN/dalvikvm(491): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-01 23:10:31.214: ERROR/AndroidRuntime(491): FATAL EXCEPTION: main
02-01 23:10:31.214: ERROR/AndroidRuntime(491): java.lang.RuntimeException: Unable to start activity ComponentInfo{COM.HANDERGY.TS2011/COM.HANDERGY.TS2011.choose_wine}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.os.Looper.loop(Looper.java:123)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ActivityThread.main(ActivityThread.java:3647)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at java.lang.reflect.Method.invokeNative(Native Method)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at java.lang.reflect.Method.invoke(Method.java:507)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at dalvik.system.NativeStart.main(Native Method)
02-01 23:10:31.214: ERROR/AndroidRuntime(491): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ListActivity.onContentChanged(ListActivity.java:243)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:229)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.Activity.setContentView(Activity.java:1668)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at COM.HANDERGY.TS2011.choose_wine.onCreate(choose_wine.java:14)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
02-01 23:10:31.214: ERROR/AndroidRuntime(491):     ... 11 more
02-01 23:10:31.244: WARN/ActivityManager(61):   Force finishing activity COM.HANDERGY.TS2011/.choose_wine
02-01 23:10:31.254: WARN/ActivityManager(61):   Force finishing activity COM.HANDERGY.TS2011/.TS2011
02-01 23:10:31.765: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{4066cb98 COM.HANDERGY.TS2011/.choose_wine}
02-01 23:10:33.214: INFO/Process(491): Sending signal. PID: 491 SIG: 9
02-01 23:10:33.224: INFO/ActivityManager(61): Process COM.HANDERGY.TS2011 (pid 491) has died.
02-01 23:10:33.234: INFO/WindowManager(61): WIN DEATH: Window{406e3f38 COM.HANDERGY.TS2011/COM.HANDERGY.TS2011.TS2011 paused=true}
02-01 23:10:33.245: ERROR/InputDispatcher(61): channel '40673568 Toast (server)' ~ Consumer closed input channel or an error occurred.  events=0x8
02-01 23:10:33.245: ERROR/InputDispatcher(61): channel '40673568 Toast (server)' ~ Channel is unrecoverably broken and will be disposed!
02-01 23:10:33.315: INFO/WindowManager(61): WIN DEATH: Window{40673568 Toast paused=false}
02-01 23:10:33.555: WARN/InputManagerService(61): Got RemoteException sending setActive(false) notification to pid 491 uid 10046

La seconda SetContentView è commentata, non è attiva.

Gbon

Offline Qlimax

  • Moderatore globale
  • Utente senior
  • *****
  • Post: 757
  • Respect: +202
    • Google+
    • _Qlimax
    • Mostra profilo
    • www.egsolutions.ch
  • Dispositivo Android:
    Galaxy Nexus - Nexus One - Wildfire - Magic
  • Play Store ID:
    egsolutions.ch
  • Sistema operativo:
    Ubuntu 12.04, Windows 7
Re:Crash nel passaggioda una activity a un'altra
« Risposta #5 il: 01 Febbraio 2011, 23:37:35 CET »
+2
02-01 23:10:31.214: ERROR/AndroidRuntime(491): java.lang.RuntimeException: Unable to start activity ComponentInfo{COM.HANDERGY.TS2011/COM.HANDERGY.TS2011.choose_wine}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

quindi o

cambi da
public class choose_wine extends ListActivity
a
public class choose_wine extends Activity


oppure metti nell xml una listview con quell'id

Offline gbon

  • Nuovo arrivato
  • *
  • Post: 15
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Wildfire
Re:Crash nel passaggioda una activity a un'altra
« Risposta #6 il: 01 Febbraio 2011, 23:46:35 CET »
0
Risolto.

Grazie mille,

Gbon

Offline Qlimax

  • Moderatore globale
  • Utente senior
  • *****
  • Post: 757
  • Respect: +202
    • Google+
    • _Qlimax
    • Mostra profilo
    • www.egsolutions.ch
  • Dispositivo Android:
    Galaxy Nexus - Nexus One - Wildfire - Magic
  • Play Store ID:
    egsolutions.ch
  • Sistema operativo:
    Ubuntu 12.04, Windows 7
Re:Crash nel passaggioda una activity a un'altra
« Risposta #7 il: 02 Febbraio 2011, 00:23:48 CET »
0
(: bene
posso sapere cosa non ti era chiaro in quel logcat?