在移动设备上测试应用程序崩溃 - Android

时间:2015-01-13 06:14:35

标签: java android facebook

我为Android编写了一个简单的Facebook登录应用程序。当我在移动设备上测试它时,应用程序崩溃了。我调试了它并添加了断点,并且这样说:

this    FragmentManagerImpl  (id=830029495424)  
    mActive null    
    mActivity   MainActivity  (id=830029490984) 
    mAdded  null    
    mAvailBackStackIndices  null    
    mAvailIndices   null    
    mBackStack  null    
    mBackStackChangeListeners   null    
    mBackStackIndices   null    
    mContainer  null    
    mCreatedMenus   null    
    mCurState   0   
    mDestroyed  false   
    mExecCommit FragmentManagerImpl$1  (id=830029496320)    
    mExecutingActions   false   
    mHavePendingDeferredStart   false   
    mNeedMenuInvalidate false   
    mNoTransactionsBecause  null    
    mParent null    
    mPendingActions null    
    mStateArray null    
    mStateBundle    null    
    mStateSaved false   
    mTmpActions null    
activity    MainActivity  (id=830029490984) 
    mActionBar  null    
    mActivityInfo   ActivityInfo  (id=830029434912) 
        applicationInfo ApplicationInfo  (id=830029435240)  
        configChanges   0   
        descriptionRes  0   
        enabled true    
        exported    true    
        flags   512 
        icon    0   
        labelRes    2131361837  
        launchMode  0   
        logo    0   
        metaData    null    
        name    "com.cheerz.citizengage.MainActivity" (id=830029435016) 
        nonLocalizedLabel   null    
        packageName "com.cheerz.citizengage" (id=830029435144)  
        parentActivityName  null    
        permission  null    
        processName "com.cheerz.citizengage" (id=830029436288)  
        screenOrientation   -1  
        softInputMode   0   
        targetActivity  null    
        taskAffinity    "com.cheerz.citizengage" (id=830029436384)  
        theme   0   
        uiOptions   0   
    mainFragment    null    
    mAllLoaderManagers  null    
    mAllLoaderManagers  null    
    mApplication    Application  (id=830029459888)  
    mBase   ContextImpl  (id=830029497760)  
    mBase   ContextImpl  (id=830029497760)  
    mByPassTouchEvent   false   
    mCalled false   
    mChangingConfigurations false   
    mCheckedForLoaderManager    false   
    mCheckedForLoaderManager    false   
    mComponent  ComponentName  (id=830029434400)    
    mConfigChangeFlags  0   
    mContainer  Activity$1  (id=830029491400)   
    mContainer  FragmentActivity$2  (id=830029497744)   
    mCreated    false   
    mCurrentConfig  Configuration  (id=830029500008)    
    mDecor  null    
    mDefaultKeyMode 0   
    mDefaultKeySsb  null    
    mDestroyed  false   
    mEmbeddedID null    
    mEnableDefaultActionBarUp   false   
    mFinished   false   
    mFragments  FragmentManagerImpl  (id=830029491280)  
    mFragments  FragmentManagerImpl  (id=830029495424)  
    mHandler    Handler  (id=830029491568)  
    mHandler    FragmentActivity$1  (id=830029492456)   
    mIdent  1103684784  
    mInflater   PhoneLayoutInflater  (id=830029501560)  
    mInstanceTracker    StrictMode$InstanceTracker  (id=830029491440)   
    mInstrumentation    Instrumentation  (id=830029455328)  
    mIntent Intent  (id=830029434136)   
    mLastNonConfigurationInstances  null    
    mLoaderManager  null    
    mLoaderManager  null    
    mLoadersStarted false   
    mLoadersStarted false   
    mMainThread ActivityThread  (id=830029429096)   
    mManagedCursors ArrayList  (id=830029491416)    
    mManagedDialogs null    
    mMenuInflater   null    
    mOptionsMenuInvalidated false   
    mOverrideConfiguration  null    
    mParent null    
    mReallyStopped  false   
    mResources  Resources  (id=830029448856)    
    mResultCode 0   
    mResultData null    
    mResumed    false   
    mResumed    false   
    mRetaining  false   
    mSearchManager  null    
    mStartedActivity    false   
    mStopped    false   
    mStopped    false   
    mTemporaryPause false   
    mTheme  Resources$Theme  (id=830029503880)  
    mThemeResource  2131427567  
    mTitle  "Citizengage" (id=830029499824) 
    mTitleColor 0   
    mTitleReady false   
    mToken  BinderProxy  (id=830029434816)  
    mUiThread   Thread  (id=830019799456)   
    mVisibleFromClient  true    
    mVisibleFromServer  false   
    mWindow PhoneWindow  (id=830029500152)  
    mWindowAdded    false   
    mWindowManager  WindowManagerImpl  (id=830029503856)    
container   FragmentActivity$2  (id=830029497744)   
parent  null    

这是我的MainFragment.java代码:

package com.cheerz.citizengage;

import java.util.Arrays;

import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.widget.LoginButton;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MainFragment extends Fragment{

    private static final String TAG = "MainFragment";
    private UiLifecycleHelper uiHelper;

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

        uiHelper = new UiLifecycleHelper(getActivity(), callback);
        uiHelper.onCreate(savedInstanceState);

        LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
        authButton.setFragment(this);
        authButton.setReadPermissions(Arrays.asList("user_likes", "user_status"));

        return view;
    }

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (state.isOpened()) {
            Log.i(TAG, "Logged in...");
        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
        }
    }

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    @Override
    public void onResume() {
        super.onResume();

        Session session = Session.getActiveSession();
        if (session != null &&
               (session.isOpened() || session.isClosed()) ) {
            onSessionStateChange(session, session.getState(), null);
        }

        uiHelper.onResume();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
    }

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

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

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }

}

MainActivity.java

package com.cheerz.citizengage;

import com.facebook.AppEventsLogger;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {

    private MainFragment mainFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            // Add the fragment on initial activity setup
            mainFragment = new MainFragment();
            getSupportFragmentManager()
            .beginTransaction()
            .add(android.R.id.content, mainFragment)
            .commit();
        } else {
            // Or set the fragment from restored state info
            mainFragment = (MainFragment) getSupportFragmentManager()
            .findFragmentById(android.R.id.content);
        }
    }

    @Override
    protected void onResume() {
      super.onResume();

      // Logs 'install' and 'app activate' App Events.
      AppEventsLogger.activateApp(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onPause() {
      super.onPause();

      // Logs 'app deactivate' App Event.
      AppEventsLogger.deactivateApp(this);
    }
}

错误在哪里?我该如何解决? logcat

01-13 14:19:56.185: I/dalvikvm(20934): Could not find method bolts.AppLinks.getAppLinkData, referenced from method com.facebook.AppEventsLogger.setSourceApplication
01-13 14:19:56.185: W/dalvikvm(20934): VFY: unable to resolve static method 8089: Lbolts/AppLinks;.getAppLinkData (Landroid/content/Intent;)Landroid/os/Bundle;
01-13 14:19:56.185: D/dalvikvm(20934): VFY: replacing opcode 0x71 at 0x002e
01-13 14:19:56.195: D/AndroidRuntime(20934): Shutting down VM
01-13 14:19:56.195: W/dalvikvm(20934): threadid=1: thread exiting with uncaught exception (group=0x4108f930)
01-13 14:19:56.235: E/AndroidRuntime(20934): FATAL EXCEPTION: main
01-13 14:19:56.235: E/AndroidRuntime(20934): java.lang.NoClassDefFoundError: bolts.AppLinks
01-13 14:19:56.235: E/AndroidRuntime(20934):    at com.facebook.AppEventsLogger.setSourceApplication(AppEventsLogger.java:1000)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at com.facebook.AppEventsLogger.activateApp(AppEventsLogger.java:277)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at com.facebook.AppEventsLogger.activateApp(AppEventsLogger.java:260)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at com.cheerz.citizengage.MainActivity.onResume(MainActivity.java:37)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1202)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.Activity.performResume(Activity.java:5404)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2830)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2882)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2314)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.ActivityThread.access$700(ActivityThread.java:157)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.os.Looper.loop(Looper.java:176)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at android.app.ActivityThread.main(ActivityThread.java:5317)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at java.lang.reflect.Method.invokeNative(Native Method)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at java.lang.reflect.Method.invoke(Method.java:511)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
01-13 14:19:56.235: E/AndroidRuntime(20934):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:4)

问题在我身边解决了。下载bolts-android1.1.2并放入\ libs文件夹。然后打开项目属性 - > java Build Path-> “项目”选项卡,添加Facebook SDK。 (Facebook SDK libs必须附有项目