Android 不幸的是,应用程序已停止工作?VFY:找不到签名中引用的类
在我的应用程序中,我想添加Facebook SDK。在那个应用程序停止后,我一直在关注一个教程 这是我的密码: 雄激素受体活性Android 不幸的是,应用程序已停止工作?VFY:找不到签名中引用的类,android,facebook,android-studio,Android,Facebook,Android Studio,在我的应用程序中,我想添加Facebook SDK。在那个应用程序停止后,我一直在关注一个教程 这是我的密码: 雄激素受体活性 public class AndroidFacebookActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.
public class AndroidFacebookActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
}
}
登录片段:
public class LoginFragment extends Fragment {
private CallbackManager callbackManager=null;
private AccessTokenTracker mtracker=null;
private ProfileTracker mprofileTracker=null;
public static final String PARCEL_KEY="parcel_key";
private LoginButton loginButton;
FacebookCallback<LoginResult> callback=new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Profile profile=Profile.getCurrentProfile();
homeFragment(profile);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_login, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
callbackManager = CallbackManager.Factory.create();
mtracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
Log.v("AccessTokenTracker", "oldAccessToken=" + oldAccessToken + "||" + "CurrentAccessToken" + currentAccessToken);
}
};
mprofileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
Log.v("Session Tracker", "oldProfile=" + oldProfile + "||" + "currentProfile" + currentProfile);
homeFragment(currentProfile);
}
};
mtracker.startTracking();
mprofileTracker.startTracking();
}
private void homeFragment(Profile profile) {
if (profile != null) {
Bundle mBundle = new Bundle();
mBundle.putParcelable(PARCEL_KEY, profile);
HomeFragment hf = new HomeFragment();
hf.setArguments(mBundle);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.mainContainer, new HomeFragment());
fragmentTransaction.commit();
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
// If using in a fragment
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, callback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onStop() {
super.onStop();
mtracker.stopTracking();
mprofileTracker.stopTracking();
}
public boolean isLoggedIn() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null;
}
@Override
public void onResume() {
super.onResume();
if (isLoggedIn()) {
loginButton.setVisibility(View.INVISIBLE);
Profile profile = Profile.getCurrentProfile();
homeFragment(profile);
}
}
}
Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
每当您的代码遇到一些RuntimeException
时,就会出现错误“不幸的是,应用程序已停止工作”,大多数情况下都是NullPointerException
,就像您的情况一样(您可以在logcat中注意到NullPointerException
)。作为android编程的新手,它经常出现。正如您所说,您从一些教程中获得了帮助,我猜您只是将代码复制到项目中,然后尝试运行。如果我错了,请纠正我。如果你这样做了,那么先撤销它,然后试着先理解代码。当你感觉到你抓住了一些东西,现在你想开始了,从复制小块代码开始,然后在每次添加新的代码块时运行它。像这样,你将继续检查该块是否真的有效,并且你将提升你的信心。那么,总有一天你会遇到那邪恶的部分!现在知道了到底是什么导致疼痛,你就能很好地治疗它了!简而言之,我想说的是,当您继续前进时,继续调试聚合代码。祝你好运
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.facebook.sdk.ApplicatioId"
android:value="@string/facebook_app_id"></meta-data>
<activity android:name=".AndroidFacebookActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
</application>
04-18 23:20:55.898 25376-25376/? D/dalvikvm: Late-enabling CheckJNI
04-18 23:20:56.538 25376-25376/com.example.bebo.facebook W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
04-18 23:20:56.548 25376-25376/com.example.bebo.facebook I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
04-18 23:20:56.558 25376-25376/com.example.bebo.facebook W/dalvikvm: VFY: unable to resolve interface method 15210: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
04-18 23:20:56.568 25376-25376/com.example.bebo.facebook D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
04-18 23:20:56.568 25376-25376/com.example.bebo.facebook I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
04-18 23:20:56.568 25376-25376/com.example.bebo.facebook W/dalvikvm: VFY: unable to resolve interface method 15214: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
04-18 23:20:56.568 25376-25376/com.example.bebo.facebook D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
04-18 23:20:56.828 25376-25376/com.example.bebo.facebook I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
04-18 23:20:56.858 25376-25376/com.example.bebo.facebook W/dalvikvm: VFY: unable to resolve virtual method 464: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-18 23:20:56.858 25376-25376/com.example.bebo.facebook D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
04-18 23:20:56.858 25376-25376/com.example.bebo.facebook I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
04-18 23:20:56.858 25376-25376/com.example.bebo.facebook W/dalvikvm: VFY: unable to resolve virtual method 486: Landroid/content/res/TypedArray;.getType (I)I
04-18 23:20:56.858 25376-25376/com.example.bebo.facebook D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
04-18 23:20:57.328 25376-25376/com.example.bebo.facebook D/OpenGLRenderer: Enabling debug mode 0
04-18 23:20:57.558 25376-25401/com.example.bebo.facebook W/dalvikvm: threadid=11: thread exiting with uncaught exception (group=0x41603c08)
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: Process: com.example.bebo.facebook, PID: 25376
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: java.lang.NullPointerException
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:911)
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: at com.facebook.internal.Utility.queryAppSettings(Utility.java:822)
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: at com.facebook.login.widget.LoginButton$1.run(LoginButton.java:489)
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-18 23:20:57.568 25376-25401/com.example.bebo.facebook E/AndroidRuntime: at java.lang.Thread.run(Thread.java:841)