我是Android编程的完全初学者,我知道这已经发布了很多次了。 问题是,我已阅读过每一篇文章,而且我似乎没有像每个人都发布的任何错误,我认为我正确地遵循了每一个基本步骤。 它应该只是暂时登录Facebook,仅此而已。 我尝试在本机模拟器和Genymotion上运行,结果相同。 现在已经3天了,这让我发疯了。
我的logcat:
11-02 15:24:28.131 1423-1423/? D/dalvikvm: Late-enabling CheckJNI
11-02 15:24:28.299 1423-1423/com.example.tasos.likefeed_4 D/AndroidRuntime: Shutting down VM
11-02 15:24:28.299 1423-1423/com.example.tasos.likefeed_4 W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d7db20)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: FATAL EXCEPTION: main
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: Process: com.example.tasos.likefeed_4, PID: 1423
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application com.example.tasos.likefeed_4.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.tasos.likefeed_4.MyApplication" on path: DexPathList[[zip file "/data/app/com.example.tasos.likefeed_4-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.tasos.likefeed_4-1, /system/lib]]
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:135)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5001)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.tasos.likefeed_4.MyApplication" on path: DexPathList[[zip file "/data/app/com.example.tasos.likefeed_4-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.tasos.likefeed_4-1, /system/lib]]
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.Instrumentation.newApplication(Instrumentation.java:975)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:135)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5001)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-02 15:24:28.307 1423-1423/com.example.tasos.likefeed_4 E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-02 15:24:30.231 1423-1423/com.example.tasos.likefeed_4 I/Process: Sending signal. PID: 1423 SIG: 9
我的Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tasos.likefeed_4" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name=".MyApplication"
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.ApplicationId" android:value="@string/facebook_app_id"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<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:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
</application>
</manifest>
我的主要活动:
package com.example.tasos.likefeed_4;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
My MainFragment:
package com.example.tasos.likefeed_4;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.Profile;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
/**
* A placeholder fragment containing a simple view.
*/
public class MainFragment extends Fragment {
private TextView myTextDetails;
private CallbackManager myCallbackManager;
private FacebookCallback<LoginResult> myCallback=new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
if (profile!=null){
myTextDetails.setText("Welcome" + profile.getName());
}
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
};
public MainFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
myCallbackManager=CallbackManager.Factory.create();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setFragment(this);
loginButton.registerCallback(myCallbackManager,myCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
myCallbackManager.onActivityResult(requestCode,resultCode,data);
}
}
任何帮助表示感谢。
答案 0 :(得分:0)
您的MyApplication
课程是否在com.example.tasos.likefeed_4
下。如果没有提供正确的软件包,它会驻留在或尝试从清单中删除android:name=".MyApplication"
并运行它(如果MyApplication在您的应用中没有自定义内容)。
希望这有帮助。