2013-06-03 51 views
10

Tôi đã làm việc để ứng dụng thực hành facebook hoạt động và tôi không thể biết được lý do tại sao tôi không thể tham khảo LoginButton được tìm thấy trong Facebook SDK. Dưới đây là lỗi mà tôi đang gặp phải khi tôi nhìn vào bố trí xác định LoginButton.Các lớp sau đây không thể được khởi tạo: - com.facebook.widget.LoginButton

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

The following classes could not be instantiated: 
- com.facebook.widget.LoginButton (Open Class, Show Error Log) 
See the Error Log (Window > Show View) for more details. 
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse 

android.content.res.Resources$NotFoundException: Could not resolve resource value:   0x7F070004. 
at android.content.res.BridgeResources.throwException(BridgeResources.java:693) 
at android.content.res.BridgeResources.getColor(BridgeResources.java:185) 
at com.facebook.widget.LoginButton.<init>(LoginButton.java:211) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at  sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422) 
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179) 
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207) 
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135) 
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746) 
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:372) 
+0

Bất cứ ai có bất cứ ý tưởng là tại sao điều này xảy ra? Tôi dường như không thể nhận được bất kỳ phản ứng nào. –

+0

Eclipse đang cố gắng hiển thị bản xem trước của phần tử nhưng không thể tải tài nguyên tại 0x7F070004, dường như là tài nguyên màu. Kiểm tra R.java đã tạo ra để tìm ra phần tử nào. Hoặc là nó không nằm trong dự án của bạn, hoặc thiếu từ một trong các thư viện. ... Tôi nghĩ .... Tôi gặp rắc rối với điều này cho các nguồn lực hoạt động tốt khi chạy ứng dụng trên thiết bị hoặc trình mô phỏng. Tôi vẫn đang nghiên cứu vấn đề ... –

+1

Tôi có cùng một vấn đề, tôi nhận thấy nó xảy ra nguyên nhân của việc sử dụng dịch vụ google play, tôi chưa có giải pháp nào – user1325188

Trả lời

32

OPTION # 1:

Đôi khi, khi một tài nguyên mới được thêm vào, Eclipse không biên dịch một cách chính xác mã mới (có thể là một vấn đề bộ nhớ đệm), gây ra điều này lỗi.

Thông thường, chỉ cần khởi động lại Eclipse là đủ để khắc phục sự cố.

OPTION # 2:

Đôi khi, làm cho quan điểm tùy chỉnh gây ra ngoại lệ này. Cách giải quyết duy nhất tôi biết là kiểm tra View.isInEditMode mỗi khi bạn cố gắng sử dụng getResources().

Một ví dụ có thể là:

if (isInEditMode()) { 
    //do something else, as getResources() is not valid. 
} else { 
    //you can use getResources() 
    String mystring = getResources().getString(R.string.mystring); 
} 
+1

đây là nhận xét rất hữu ích giúp một số vấn đề khác . – gjnave

+0

Tùy chọn # 1 không trợ giúp trong Android Studio v0.8.14. Làm theo thông báo mẹo nhưng tôi không chắc chắn cách thực hiện mẹo này - suy nghĩ ?: Mẹo: Sử dụng View.isInEditMode() trong chế độ xem tùy chỉnh của bạn để bỏ qua mã hoặc hiển thị dữ liệu mẫu khi được hiển thị trong IDE – natur3

+0

Tìm thấy câu trả lời cho vấn đề riêng. Tôi đang sử dụng ngăn kéo điều hướng và gọi phương thức onCreateView() từ Chế độ xem. Tôi chỉ cần thêm dòng sau Xem rootView = blah blah; rootView.isInEditMode(); Điều này cho phép tôi sử dụng IDE đồ họa để thiết kế. – natur3

1

Nếu bạn đang sử dụng Android studio sau đó tài liệu hướng dẫn rõ ràng của nó ở đây,

Sử dụng facebook với mảnh Tutorial

tài khoản facebook mà không mảnh

Bước 1: Tạo tệp java MyApplication.java bên trong gói của bạn.

Tutorial

và copu myApplicatyon.java

Bước 2: thiết lập androidmenufest.xml

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/Theme.Myapptheme" 
    android:name=".MyApplication" 
    > 
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id" /> 
    <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" /> 

Bước 3: Hoạt động trong Init nơi bạn đang tìm kiếm init Đăng nhập Nút

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    callbackManager = CallbackManager.Factory.create(); 
    FacebookSdk.sdkInitialize(getApplicationContext()); 
    setContentView(R.layout.activity_auth_login); 

    //Init Elements 
    etEmail = (EditText) findViewById(R.id.etEmail); 
    etPassword = (EditText) findViewById(R.id.etPassword); 

    validator = new Validator(this); 
    validator.setValidationListener(this); 

    serverConnection = new ServerConnection(); 

    //Faceboo login init 
    loginButton = (LoginButton) findViewById(R.id.btnFbLogin); 
    loginButton.setReadPermissions(Arrays.asList("public_profile","email","user_photos")); 



    // Other app specific specialization 
    // Callback registration 
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 
      // App code 

      Profile profile = Profile.getCurrentProfile(); 

      Log.v("profile.getName:",profile.getName()); 
     } 

     @Override 
     public void onCancel() { 
      // App code 
     } 

     @Override 
     public void onError(FacebookException exception) { 
      // App code 
     } 
    }); 

} 
2

// viết đầu tiên này

FacebookSdk.sdkInitialize (getApplicationContext());

// sau đó thiết lập contentView

setContentView(R.layout.activity_main); 
Các vấn đề liên quan