I m trying to integrate the facebook in my app.I am using facebook example app downloaded from facebook as a reference(also generated the appId and all this process on developer.facebook).I am little lazy so I do not want to go through all the code of facebook sdk.In simple words i just add the com_android_facebook library project in my app, and also copy all the classes in facebook example app in my app except Example.java
Now i modify the MyActivity class look like Example.java class, means MyActivity now have all the code of Example class and also my main Activity.
and i change the layout of my app as
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="22px"
android:textColor="#ff00ff"
android:gravity="center"
>
</TextView>
<com.android.facebook.LoginButton
android:id="#+id/login"
android:src="#drawable/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<Button android:id="#+id/uploadButton"
android:text="#string/upload"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
<Button android:id="#+id/requestButton"
android:text="#string/request"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
<Button android:id="#+id/postButton"
android:text="#string/post"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
<Button android:id="#+id/deletePostButton"
android:text="#string/delete"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
</RelativeLayout>
Now when i run my app i am getting there errors
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.myapp/com.android.myapp.MyActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.facebook.LoginButton
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.facebook.LoginButton
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader#44c06850
Any help, suggestions are most welcome...
I also faced the same issue. I changed the main.xml from:
<com.facebook.android.LoginButton
android:id="#+id/login"
android:src="#drawable/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
/>
to (Current package is com.facebook.fbtest_simple):
<com.facebook.fbtest_simple.LoginButton
android:id="#+id/login"
android:src="#drawable/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
/>
As LoginButton is not part of FB standard library.
As of version 3.0 of the Facebook SDK, the LoginButton is now available as part of the SDK as
com.facebook.widget.LoginButton
See https://developers.facebook.com/docs/reference/android/3.0/LoginButton
Note that Facebook's own upgrade instructions here reference the wrong package, the LoginButton must be declared as com.facebook.widget.LoginButton, not com.facebook.LoginButton
There is no LoginButton in the main source of that SDK.
It's available in the sample code only, so it just fails to load the unavailable class (ClassNotFoundException)...
Easy one :
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader#44c06850
Looking for in the facebook src , you can go to this path:
AsyncFacebookRunner.java , Facebook.java, FacebookError.java ,
FbDialog.java, Util.java
..And see that there isn't nothing like LoginButton , then i can think that you are using an old tutorial or something like that.
Initializing the Facebook SDK is what worked for me.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this.getApplicationContext());
setContentView(R.layout.activity_login);
}
Related
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/general_dts_title"
style="#style/TextAppearance.Compat.Notification.Line2"
android:layout_alignParentBottom="false"
android:layout_alignBottom="#+id/imgToggle"
android:textSize="16sp" />
<Switch
android:id="#+id/imgToggle"
android:layout_width="42dp"
android:layout_height="28dp"
android:layout_gravity="right"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp" />
</RelativeLayout>
StatusBar: Caused by: android.view.InflateException: Binary XML file line #338 in com.dts.dtsxultra:layout/view_notification_sample: Class not allowed to be inflated android.widget.Switch ...
Could you please help.
I tried removing background attribute, but still it is not working.
I have tried the above piece of code, without giving the style to the textview, it works great. The error that you are facing may not be because of the piece of code.
RemoveView only allows some layout and widget to inflate. android.widget.Switch as in the error you are getting is not supported by RemoteView. You can see the list of supported views here
I realize that there are a lot of questions with titles similar to this one, but I think my problem is one that has not yet been addressed.
I have an existing Android application that is entering the intensive beta-testing phase. To that end, I am attempting to implement Instabug to help out.
This morning, before attempting to implement Instabug, my app worked (in that it launched).
My MainActivity extends android.app.Activity, so I replaced that with InstabugActivity (com.instabug.wrapper.support.activity.InstabugActivity).
My MainActivity is for login/sign up, and then the app transitions to an AppRootActivity, which is an android.support.v7.app.ActionBarActivity. This is because the app has a navigation drawer. So, I changed AppRootActivity to an InstabugActionBarActivity (com.instabug.wrapper.support.activity.InstabugActionBarActivity).
When I run the app in debug mode using an attached device, it works just fine. When I push the app out to my testers via Fabric/Crashlytics, the app crashes at launch.
From what I can tell, these are the important error messages I'm getting:
java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.company.app/com.company.app.MainActivity}:
android.view.InflateException: Binary XML file line #14:
Error inflating class fragment
Caused by:
android.view.InflateException: Binary XML file line #14:
Error inflating class fragment
at com.company.app.MainActivity.onCreate(Unknown Source)
Caused by:
android.app.Fragment$InstantiationException:
Trying to instantiate a class
com.company.app.NavigationDrawerFragment
that is not a Fragment
at com.company.app.MainActivity.onCreate(Unknown Source)
Caused by: java.lang.ClassCastException
at com.company.app.MainActivity.onCreate(Unknown Source)
Ok, now here's the weird thing. MainActivity is never tied to NavigationDrawerFragment. Never.
I have no idea why the app is trying to instantiate NavigationDrawerFragment when the app is launching.
Even still, though, NavigationDrawerFragment extends MyFragment which extends Fragment (android.support.v4.app.Fragment).
I am really, really lost here. I'd love to use Instabug, because their product on iOS is really nice and impressive, but I can't figure this out!
Edit
Here's the XML layout for ActivityMain:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/main_activity_background"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<View
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
/>
<ImageView
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:src="#drawable/main_activity_logo"
/>
<View
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
/>
<TextView
android:id="#+id/main_activity_tag_line_text_view"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text="#string/tag_line"
android:textColor="#color/off_white"
android:textSize="20dp"
/>
<ImageButton
android:id="#+id/main_activity_sign_up_with_Facebook_button"
android:background="#drawable/main_activity_facebook_button_shape"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/main_activity_vertical_button_margin"
android:layout_marginTop="#dimen/main_activity_vertical_button_margin"
android:layout_width="wrap_content"
android:paddingBottom="#dimen/main_activity_facebook_sign_up_button_vertical_padding"
android:paddingLeft="#dimen/main_activity_facebook_sign_up_button_horizontal_padding"
android:paddingRight="#dimen/main_activity_facebook_sign_up_button_horizontal_padding"
android:paddingTop="#dimen/main_activity_facebook_sign_up_button_vertical_padding"
android:src="#drawable/main_activity_facebook_sign_up"
/>
<Button
android:id="#+id/main_activity_sign_up_button"
android:background="#drawable/sign_up_button_shape"
android:gravity="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/main_activity_vertical_button_margin"
android:layout_marginTop="#dimen/main_activity_vertical_button_margin"
android:layout_width="wrap_content"
android:text="#string/sign_up_title"
android:textColor="#color/dark_gray"
android:textSize="#dimen/login_button_text_size"
/>
<Button
android:id="#+id/main_activity_login_button"
android:background="#drawable/main_activity_login_button_shape"
android:gravity="center"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/main_activity_vertical_button_margin"
android:layout_marginTop="#dimen/main_activity_vertical_button_margin"
android:layout_width="wrap_content"
android:text="#string/login_title"
android:textColor="#color/gold"
android:textSize="#dimen/login_button_text_size"
/>
<TextView
android:id="#+id/main_activity_disclaimer_text_view"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_width="wrap_content"
android:text="#string/disclaimer"
android:textColor="#color/off_white"
android:textSize="12dp"
/>
</LinearLayout>
I am taking the first step into android programming and XML. I am using the Big Nerd Ranch Guide book. In Eclipse, I used the XML given in the book and I got the error XML document structures must start and end within the same entity.
How do I fix this?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="#string/question_text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/true_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/false_button" />
</LinearLayout>
</LinearLayout>
Problem is solved. I removed the code and saved the xml file. After that, I replaced it with the above code and saved. The error is gone. It was probably a remanant from the time when "automatically build project" was enabled.
Strange.
I just created a new projet, building some layouts, writing some code. Everything was fine except I got this error as shown in the picture below.
I tried to remove and type it again and when typing 'R.id.', there was no 'container' showing up in the list. So that means theres no problem with my R file, just that the 'container' word lost somewhere.
Those code above are actually default code in onCreate() method in your main activity everytime you create a new project in Android Studio. (I actually tried to create a new project to compare and yes it's the same, and without error as it's brand new.).
All I did was comment out the if statement block so the error goes away, and the application has run just fine on the emulator. I just don't know why I got that problem and how I can handle it as I may need to do that in the future. Thank you!
Edit after #Raghunandan has mentioned: Below is my xml.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/provide_information"
android:id="#+id/provideInfoButton"
android:layout_alignParentTop="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/take_picture"
android:id="#+id/takePictureButton"
android:layout_below="#+id/provideInfoButton"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_below="#+id/takePictureButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/classNameTextView"
android:layout_above="#+id/personNametextView2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginBottom="38dp"
android:layout_above="#+id/emailTextView"
android:layout_alignLeft="#+id/emailTextView"
android:id="#+id/personNameTextView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/emailTextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/classNameTextView"
android:layout_marginBottom="82dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/send_button"
android:id="#+id/sendButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The reason is that I changed the root layout to RelativeLayout (the default of Android Studio was FrameLayout which has an id of "container"). My bad :). Thanks for mentioning about posting the xml file. I have not noticed that as I'm not as familiar with Android Studio as with Eclipse yet.
I have been tweaking my main xml layout, adjusting the different views' positions in my relative layout, and suddenly when I started it on my emulator, it crashed with the message:ClassCastException
My XML :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<com.example.bingbong.Render
android:id="#+id/render"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#color/pattern5"
android:clickable="true" />
<TextView
android:id="#+id/fps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="fpasds"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/score_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="asd"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/score_bot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="asfa"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
The error log:
10-30 20:25:33.266: E/AndroidRuntime(269): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bingbong/com.example.bingbong.Main_Activity}: java.lang.ClassCastException: android.widget.TextView
...
10-30 20:25:33.266: E/AndroidRuntime(269): Caused by: java.lang.ClassCastException: android.widget.TextView
10-30 20:25:33.266: E/AndroidRuntime(269): at com.example.bingbong.Main_Activity.onCreate(Main_Activity.java:26)
The Main_Activity - where line 26 is :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_layout);
r = (Render) findViewById(R.id.render); // <--- Line 26.
r.setView((TextView)findViewById(R.id.fps),(TextView)findViewById(R.id.score_top),(TextView)findViewById(R.id.score_bot));
}
I get this occasionally if I am moving around views or changing the types of views (ie, a TextView change to a Button, or something like that). What usually fixes it for me is to do a clean build.
In the "Project" menu in Eclipse, select "Clean..." and either do all projects or select that particular project.
Yo need clean the project, I got this error frequently