Autore Topic: W/dalvikvm(337): threadid=1: thread exiting with uncaught exception  (Letto 904 volte)

Offline johnnydest

  • Nuovo arrivato
  • *
  • Post: 3
  • Respect: 0
    • Mostra profilo
W/dalvikvm(337): threadid=1: thread exiting with uncaught exception
« il: 04 Settembre 2013, 20:42:41 CEST »
0
Ciao ragazzi sono alle prime armi con Android, sto facendo una piccola applicazione che utilizza le API di Facebook. Seguendo il tutorial di Facebook developer sto cercando di realizzare una applicazione banale che realizza il login e il logout.
Ho seguito di pari passo il tutorial e non riesco a capire quale possa essere il problema, provo a postarvi il log:
09-04 17:13:45.707: D/AndroidRuntime(337): Shutting down VM
09-04 17:13:45.707: W/dalvikvm(337): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-04 17:13:45.717: E/AndroidRuntime(337): FATAL EXCEPTION: main
09-04 17:13:45.717: E/AndroidRuntime(337): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.unisannio.examplemio/it.unisannio.examplemio.MainActivity}: java.lang.NullPointerException
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.os.Looper.loop(Looper.java:123)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.ActivityThread.main(ActivityThread.java:3683)
09-04 17:13:45.717: E/AndroidRuntime(337):    at java.lang.reflect.Method.invokeNative(Native Method)
09-04 17:13:45.717: E/AndroidRuntime(337):    at java.lang.reflect.Method.invoke(Method.java:507)
09-04 17:13:45.717: E/AndroidRuntime(337):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-04 17:13:45.717: E/AndroidRuntime(337):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-04 17:13:45.717: E/AndroidRuntime(337):    at dalvik.system.NativeStart.main(Native Method)
09-04 17:13:45.717: E/AndroidRuntime(337): Caused by: java.lang.NullPointerException
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:609)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.Activity.performStart(Activity.java:3791)
09-04 17:13:45.717: E/AndroidRuntime(337):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1620)
09-04 17:13:45.717: E/AndroidRuntime(337):    ... 11 more

Vi ringrazio anticipatamente

Offline vincenzoc

  • Utente junior
  • **
  • Post: 148
  • Respect: +47
    • Google+
    • cerminarav
    • Mostra profilo
    • Mie applicazioni sul Play Store
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Vincenzo Cerminara
  • Sistema operativo:
    Arch Linux
Re:W/dalvikvm(337): threadid=1: thread exiting with uncaught exception
« Risposta #1 il: 04 Settembre 2013, 20:44:51 CEST »
0
Se posti anche il codice che ti genera l'eccezione possiamo aiutarti, altrimenti diventa molto difficile  :-)
Ringrazia chi ti aiuta sul forum con l'apposito pulsante :P
Scarica Yazzy

Offline johnnydest

  • Nuovo arrivato
  • *
  • Post: 3
  • Respect: 0
    • Mostra profilo
Re:W/dalvikvm(337): threadid=1: thread exiting with uncaught exception
« Risposta #2 il: 04 Settembre 2013, 21:08:13 CEST »
0
pardon, hai ragione:
Classe main:
Codice (Java): [Seleziona]
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {
        private static final int SETTINGS = 2;
       
        private static final int SPLASH = 0;
        private static final int SELECTION = 1;
        private static final int FRAGMENT_COUNT = SETTINGS +1;

        private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
       
       
        private boolean isResumed = false;
        private MenuItem settings;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
           
            uiHelper = new UiLifecycleHelper(this, callback);
            uiHelper.onCreate(savedInstanceState);

            FragmentManager fm = getSupportFragmentManager();
            fragments[SELECTION]=fm.findFragmentById(R.id.selectionFragment);
            fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
            fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);

            FragmentTransaction transaction = fm.beginTransaction();
            for(int i = 0; i < fragments.length; i++) {
                transaction.hide(fragments[i]);
            }
            transaction.commit();
        }

        private void showFragment(int fragmentIndex, boolean addToBackStack) {
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction transaction = fm.beginTransaction();
            for (int i = 0; i < fragments.length; i++) {
                if (i == fragmentIndex) {
                    transaction.show(fragments[i]);
                } else {
                    transaction.hide(fragments[i]);
                }
            }
            if (addToBackStack) {
                transaction.addToBackStack(null);
            }
            transaction.commit();
        }
       
       
       
        @Override
        public void onResume() {
            super.onResume();
            uiHelper.onResume();
            isResumed = true;
        }

        @Override
        public void onPause() {
            super.onPause();
            uiHelper.onPause();
            isResumed = false;
        }

       
        private void onSessionStateChange(Session session, SessionState state, Exception exception) {
            // Only make changes if the activity is visible
            if (isResumed) {
                FragmentManager manager = getSupportFragmentManager();
                // Get the number of entries in the back stack
                int backStackSize = manager.getBackStackEntryCount();
                // Clear the back stack
                for (int i = 0; i < backStackSize; i++) {
                    manager.popBackStack();
                }
                if (state.isOpened()) {
                    // If the session state is open:
                    // Show the authenticated fragment
                    showFragment(SELECTION, false);
                } else if (state.isClosed()) {
                    // If the session state is closed:
                    // Show the login fragment
                    showFragment(SPLASH, false);
                }
            }
        }
       
        @Override
        protected void onResumeFragments() {
            super.onResumeFragments();
            Session session = Session.getActiveSession();

            if (session != null && session.isOpened()) {
                // if the session is already open,
                // try to show the selection fragment
                showFragment(SELECTION, false);
            } else {
                // otherwise present the splash screen
                // and ask the person to login.
                showFragment(SPLASH, false);
            }
        }
       
        private UiLifecycleHelper uiHelper;
        private Session.StatusCallback callback =
            new Session.StatusCallback() {
            @Override
            public void call(Session session,
                    SessionState state, Exception exception) {
                onSessionStateChange(session, state, exception);
            }
        };
       
        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            uiHelper.onActivityResult(requestCode, resultCode, data);
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            uiHelper.onDestroy();
        }

        @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            uiHelper.onSaveInstanceState(outState);
        }
       
        @Override
        public boolean onPrepareOptionsMenu(Menu menu) {
            if (fragments[SELECTION].isVisible()) {
                if (menu.size() == 0) {
                    settings = menu.add(R.string.settings);
                }
                return true;
            } else {
                menu.clear();
                settings = null;
            }
            return false;
        }
       
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            if (item.equals(settings)) {
                showFragment(SETTINGS, true);
                return true;
            }
            return false;
        }
}

Classe fragments che rappresenta una nonauthenticated UI:
Codice (Java): [Seleziona]
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



public class SplashFragment extends Fragment {

        @Override
        public View onCreateView(LayoutInflater inflater,
                ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.splash,
                    container, false);
            return view;
        }
       
}

Classe fragments che rappresenta una authenticated UI:
Codice (Java): [Seleziona]
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



public class SelectionFragment extends Fragment{
        @Override
        public View onCreateView(LayoutInflater inflater,
                ViewGroup container, Bundle savedInstanceState) {
            super.onCreateView(inflater, container, savedInstanceState);
            View view = inflater.inflate(R.layout.selection,
                    container, false);
            return view;
        }
       
        private static final String TAG = "SelectionFragment";

}

Activity.xml:
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">

    <fragment android:name="it.unisannio.examplemio.SelectionFragment"
         android:id="@+id/selectionFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
    <fragment android:name="it.unisannio.examplemio.SplashFragment"
         android:id="@+id/splashFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
   
        <fragment android:name="com.facebook.widget.UserSettingsFragment"
         android:id="@+id/userSettingsFragment"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
</LinearLayout>

Selection.xml:

Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >
   
    <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginLeft="10dp"
   android:layout_gravity="center"
   android:textColor="#333"
   android:textSize="18sp"
   android:text="Welcome, you are now logged in."  />
   

</LinearLayout>

Splash.xml

Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:orientation="vertical"
             android:background="#303040" >

    <LinearLayout
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_marginTop="30dp"
           android:gravity="center_horizontal"
           android:orientation="horizontal" >
        <ImageView
               android:id="@+id/splash_icon"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="center"
               android:layout_marginLeft="10dp"
               android:gravity="center"
               android:src="@drawable/icon" />
        <TextView
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="center"
               android:gravity="center"
               android:textColor="#AFDEFE"
               android:textSize="28sp"
               android:typeface="serif"
               android:textStyle="italic"
               android:text="@string/app_name" />
    </LinearLayout>


    <TextView
           android:id="@+id/profile_name"
           android:layout_width="174dp"
           android:layout_height="wrap_content"
           android:layout_marginTop="35dp"
           android:lines="2"
           android:textSize="17sp"
           android:text="@string/get_started"
           android:layout_gravity="center_horizontal"
           android:gravity="center_horizontal"/>

    <com.facebook.widget.LoginButton
           android:id="@+id/login_button"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_horizontal"
           android:layout_marginTop="30dp"
           android:layout_marginBottom="30dp" />

</LinearLayout>

Offline vincenzoc

  • Utente junior
  • **
  • Post: 148
  • Respect: +47
    • Google+
    • cerminarav
    • Mostra profilo
    • Mie applicazioni sul Play Store
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Vincenzo Cerminara
  • Sistema operativo:
    Arch Linux
Re:W/dalvikvm(337): threadid=1: thread exiting with uncaught exception
« Risposta #3 il: 05 Settembre 2013, 11:50:30 CEST »
0
Questo dovrebbe aiutarti
Ringrazia chi ti aiuta sul forum con l'apposito pulsante :P
Scarica Yazzy

Offline johnnydest

  • Nuovo arrivato
  • *
  • Post: 3
  • Respect: 0
    • Mostra profilo
Re:W/dalvikvm(337): threadid=1: thread exiting with uncaught exception
« Risposta #4 il: 05 Settembre 2013, 12:48:55 CEST »
0
ti ringrazio, ho risolto. Praticamente richiamavo due volte lo stesso metodo in maniera uguale  >:( :

Codice (Java): [Seleziona]
 fragments[SELECTION]=fm.findFragmentById(R.id.selectionFragment);
            fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
            fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);