Autore Topic: LoginButton di FB, errore nell'xml  (Letto 294 volte)

Offline ValerioAdo

  • Utente normale
  • ***
  • Post: 323
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Huawei Ascend g525
  • Sistema operativo:
    windows 8.1
LoginButton di FB, errore nell'xml
« il: 01 Settembre 2015, 09:32:13 CEST »
0
Salve a tutti!

Sto cercando di implementare il login a facebook con la mia app ma nell'xml mi ritrovo questo errore:

The following classes could not be instatiated:
-com.facebook.wodget.LoginButton

Codice: [Seleziona]
java.lang.ClassNotFoundException: org.json.JSONException
        at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:144)
        at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:54)
        at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:87)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at com.facebook.internal.CallbackManagerImpl$RequestCodeOffset.toRequestCode(CallbackManagerImpl.java:109)
        at com.facebook.login.widget.LoginButton.<clinit>(LoginButton.java:56)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
        at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:437)
        at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:154)
        at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:93)
        at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:190)
        at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:216)
        at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:143)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:413)
        at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:322)
        at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
        at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:511)
        at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:499)
        at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
        at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:499)
        at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
        at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:611)
        at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:608)
        at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:363)
        at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:608)
        at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:630)
        at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
        at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
        at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
        at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
        at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

io non so più dove mettere le mani....

questo è il codice java associato alla main_activiy:
Codice (Java): [Seleziona]
public class MainActivity extends AppCompatActivity {

    private TextView info;
    private LoginButton loginButton;

    private CallbackManager callbackManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        callbackManager = CallbackManager.Factory.create();

        FacebookSdk.sdkInitialize(getApplicationContext());
        setContentView(R.layout.activity_main);

        FacebookSdk.sdkInitialize(this.getApplicationContext());

        info = (TextView)findViewById(R.id.info);
        loginButton = (LoginButton)findViewById(R.id.login_button);

        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                info.setText(
                        "User ID: "
                                + loginResult.getAccessToken().getUserId()
                                + "\n" +
                                "Auth Token: "
                                + loginResult.getAccessToken().getToken()
                );
            }

            @Override
            public void onCancel() {
                info.setText("Login attempt canceled.");
            }

            @Override
            public void onError(FacebookException e) {
                info.setText("Login attempt failed.");
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }

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

questo è l'xml:
Codice (XML): [Seleziona]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.test.facebooklogin" >

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:theme="@style/AppTheme" >
        <activity
           android:name=".MainActivity"
           android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <meta-data android:name="com.facebook.sdk.ApplicationId"
                   android:value="@string/facebook_app_id"/>

                <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>

e questo è il gradle:
Codice: [Seleziona]
ndroid {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.test.facebooklogin"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}


avete suggerimenti? grazie mille!