facebook android app在本地设备上测试时崩溃了

时间:2015-01-09 09:09:01

标签: java android facebook

我正在开发一个用于登录Facebook的应用程序。但是当它在本地设备中测试时它会崩溃.Log Cat说它是由 ClassNotFoundException引起的:没找到类“com.cheerz.citizengage.MainActivity”。请帮我解决一下

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);
    }
}

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);
    }

}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.cheerz.citizengage.MainActivity" >

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

</LinearLayout>

Log Cat

    01-09 14:32:30.163: W/dalvikvm(26973): Unable to resolve superclass of Lcom/cheerz/citizengage/MainActivity; (107)
    01-09 14:32:30.163: W/dalvikvm(26973): Link of class 'Lcom/cheerz/citizengage/MainActivity;' failed
    01-09 14:32:30.163: D/AndroidRuntime(26973): Shutting down VM
    01-09 14:32:30.163: W/dalvikvm(26973): threadid=1: thread exiting with uncaught exception (group=0x41639930)
    01-09 14:32:30.183: E/AndroidRuntime(26973): FATAL EXCEPTION: main
    01-09 14:32:30.183: E/AndroidRuntime(26973): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.cheerz.citizengage/com.cheerz.citizengage.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.cheerz.citizengage.MainActivity" on path: /data/app/com.cheerz.citizengage-2.apk
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.ActivityThread.access$700(ActivityThread.java:157)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.os.Handler.dispatchMessage(Handler.java:99)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.os.Looper.loop(Looper.java:176)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.ActivityThread.main(ActivityThread.java:5317)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at java.lang.reflect.Method.invokeNative(Native Method)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at java.lang.reflect.Method.invoke(Method.java:511)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at dalvik.system.NativeStart.main(Native Method)
    01-09 14:32:30.183: E/AndroidRuntime(26973): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.cheerz.citizengage.MainActivity" on path: /data/app/com.cheerz.citizengage-2.apk
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2171)
    01-09 14:32:30.183: E/AndroidRuntime(26973):    ... 11 more

0 个答案:

没有答案