gpt4 book ai didi

java - ClassNotFoundException 与 Parse 和 Facebook

转载 作者:太空宇宙 更新时间:2023-11-03 12:51:27 25 4
gpt4 key购买 nike

我希望你能帮助我解决我面临的问题。我正在尝试使用 Parse 将 Facebook 登录集成到我的应用程序中,但在调用该方法时出现 ClassNotFoundException 错误

 ParseFacebookUtils.logInWithReadPermissionsInBackground(LoginActivity.this, permissions, new LogInCallback()

错误堆栈跟踪:

05-15 10:36:00.749    3936-3936/kstr14.tipper E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: kstr14.tipper, PID: 3936
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/parse/ParseTaskUtils;
at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:173)
at kstr14.tipper.Activities.LoginActivity.facebookLoginPressed(LoginActivity.java:170)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.parse.ParseTaskUtils" on path: DexPathList[[zip file "/data/app/kstr14.tipper-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:173)
at kstr14.tipper.Activities.LoginActivity.facebookLoginPressed(LoginActivity.java:170)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19749)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Suppressed: java.lang.ClassNotFoundException: com.parse.ParseTaskUtils
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 16 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

我的 lib 文件夹中有以下 jar 文件:Parse-1.9.1.jarjavax.mail.jar bolt -android-1.2.0.jarParseFacebookUtilsV4-1.9.2.jar

我已经对 build.gradle 文件的依赖项部分进行了各种尝试,因为我怀疑这个错误是由于某些库没有被正确包含,但我尝试过的都没有奏效。我尝试了不同的方式来指定编译 jar 文件以及以不同的顺序指定 jar。目前我的 build.gradle 文件如下所示:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "kstr14.tipper"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

repositories {
mavenCentral()
}

dependencies {
compile fileTree(include: ['*.jar'] ,dir: 'libs')
compile files('libs/bolts-android-1.2.0.jar')
compile 'com.parse.bolts:bolts-android:1.2.0'
compile files('libs/Parse-1.9.1.jar')
compile files('libs/ParseFacebookUtilsV4-1.9.2.jar')
compile files('libs/javax.mail.jar')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
}

有人有什么建议吗?

哦,顺便说一句,当我的应用程序因错误而崩溃时,我按确定,然后无论如何都会显示 Facebook 登录屏幕。所以我想 facebook jar 导入正常,问题出在解析 jar 。然而,在我尝试集成 Facebook 之前,我一直在使用 Pars jar,而且它工作得很好。我在导入 Facebook jar 的同时导入了 bolts jar,因为我在某处读到它是必要的,所以它可能是 bolts jar 的问题?

编辑:为 LoginActivity 添加代码:

package kstr14.tipper.Activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.Toast;

import com.facebook.FacebookSdk;
import com.parse.LogInCallback;
import com.parse.ParseException;
import com.parse.ParseFacebookUtils;
import com.parse.ParseObject;
import com.parse.ParseUser;
import com.parse.SignUpCallback;

import java.util.ArrayList;
import java.util.List;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

import kstr14.tipper.Data.Category;
import kstr14.tipper.Data.Group;
import kstr14.tipper.Data.Tip;
import kstr14.tipper.R;


public class LoginActivity extends ActionBarActivity {

// UI elements for default login fragment
private EditText usernameDefaultLogin;
private EditText passwordDefaultLogin;

// UI elements for sign up fragment
private EditText usernameSignup;
private EditText emailSignup;
private EditText passwordSignup;
private EditText reenterPasswordSignup;


@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
getSupportActionBar().hide();

// initalize facebook
FacebookSdk.sdkInitialize(getApplicationContext());

// Initialize Parse
ParseObject.registerSubclass(Tip.class);
ParseObject.registerSubclass(Category.class);
ParseObject.registerSubclass(Group.class);
ParseObject.registerSubclass(ParseUser.class);

// check cache for current user - if found go directly to MainActivity
ParseUser currentUser = ParseUser.getCurrentUser();
if(currentUser != null) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}

// otherwise set fragment to the default login screen
DefaultLoginFragment defaultLoginFragment = new DefaultLoginFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, defaultLoginFragment).commit();
}

// Required for making Facebook login work
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}

/**
* Method called when sign up button pressed on the default login fragment
* Switches the default login fragment with a sign up fragment
* @param view
*/
public void defaultSignUpPressed(View view) {
SignUpFragment signUpFragment = new SignUpFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

// Replace the default login fragment with the sign up fragment,
// and add the transaction to the back stack so the user can navigate back
fragmentTransaction.replace(R.id.fragment_container, signUpFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}

/**
* Method called when login button pressed on the default login fragment
* Attempts to log in the user, if successful goes to MainActivity
* @param view
*/
public void defaultLoginPressed(View view) {
// initialize UI elements for default login fragment
usernameDefaultLogin = (EditText) findViewById(R.id.usernameDefaultLoginFragment);
passwordDefaultLogin = (EditText) findViewById(R.id.passwordDefaultLoginFragment);

// fetch input and attempt login
String username = usernameDefaultLogin.getText().toString();
String password = passwordDefaultLogin.getText().toString();
ParseUser.logInInBackground(username, password, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Login failed.", Toast.LENGTH_SHORT).show();
}
}
});
}

/**
* Method called when sign up button pressed in sign up fragment
* Attempts to register the user, if successful goes to MainActivity
* @param view
*/
public void signupPressed(View view) {
// UI elements for sign up fragment
usernameSignup = (EditText) findViewById(R.id.usernameSignupFragment);
emailSignup = (EditText) findViewById(R.id.emailSignupFragment);
passwordSignup = (EditText) findViewById(R.id.passwordSignupFragment);
reenterPasswordSignup = (EditText) findViewById(R.id.reenterPasswordSignupFragment);

String username = usernameSignup.getText().toString();
String email = emailSignup.getText().toString();
String password1 = passwordSignup.getText().toString();
String password2 = reenterPasswordSignup.getText().toString();

// validate passwords and email
if(!validatePassword(password1, password2)) {
Toast.makeText(getApplicationContext(), "Passwords do not match, try again.", Toast.LENGTH_SHORT).show();
} else if (!validateEmail(email)) {
Toast.makeText(getApplicationContext(), "Please enter a valid email.", Toast.LENGTH_SHORT).show();
} else {
ParseUser user = new ParseUser();
user.setUsername(username);
user.setPassword(password1);
user.setEmail(email);
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Sign up failed. Please try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
}

public void facebookLoginPressed(View view) {
List<String> permissions = new ArrayList<String>();
permissions.add("public_profile");
ParseFacebookUtils.logInWithReadPermissionsInBackground(LoginActivity.this, permissions, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
Log.d("MyApp", "User signed up and logged in through Facebook!");
} else {
Log.d("MyApp", "User logged in through Facebook!");
}
}
});
}

/**
* Validates that two passwords are equal
* @param password1
* @param password2
* @return
*/
public boolean validatePassword(String password1, String password2) {
if(password1.equals(password2)) return true;
else return false;
}

/**
* Validates the structure of an email address
* @param email
* @return
*/
public boolean validateEmail(String email) {
boolean result = true;
try {
InternetAddress internetAddress = new InternetAddress(email);
internetAddress.validate();
} catch (AddressException e) {
e.printStackTrace();
result = false;
}
return result;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

最佳答案

其实我刚刚遇到了同样的问题。希望我可以为搜索此问题的任何人省去很多麻烦。答案是不要使用旧的 SDK。实际上,您需要做的就是确保您使用的是相同版本的 Parse 和 ParseFacebookUtils。看看你上面的 gradle 文件

compile 'com.parse.bolts:bolts-android:1.2.0'
compile files('libs/Parse-1.9.1.jar')
compile files('libs/ParseFacebookUtilsV4-1.9.2.jar')

您使用的是 Parse-1.9.1 和 ParseFacebookUtilsV4-1.9.2。我其实犯了同样的错误。我从另一个项目中拉出 Parse-1.9.1 并再次下载 SDK 以拉出 FacebookUtils 库。

关于java - ClassNotFoundException 与 Parse 和 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30257822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com