I'm building my first Android app and I've consulted quite some tutorials and stackoverflow posts, but I can't seem to find the proper fix for this problem.
I've been following YouTube tutorials from TheNewBoston and Derek Banas, as well as some written tutorials.
My app runs as it should when starting the app (being in Portrait mode). When I swap it to landscape, it still works fine. However when I rotate it back to portrait, the app crashes with the following error:
04-12 23:42:12.331 28004-28004/nl.avans.mbd2.android.gideon.van.david.multipanefragment E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: nl.avans.mbd2.android.gideon.van.david.multipanefragment, PID: 28004
java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.avans.mbd2.android.gideon.van.david.multipanefragment/nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4054)
at android.app.ActivityThread.access$1000(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1314)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4054)
at android.app.ActivityThread.access$1000(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1314)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Fragment nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainPanelFragment did not create a view.
at android.app.Activity.onCreateView(Activity.java:5020)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:240)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4054)
at android.app.ActivityThread.access$1000(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1314)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
The actual error being:
java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.avans.mbd2.android.gideon.van.david.multipanefragment/nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
Caused by: java.lang.IllegalStateException: Fragment nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainPanelFragment did not create a view.
My MainActivity looks like this:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int screenOrientation = getResources().getConfiguration().orientation;
if (screenOrientation == Configuration.ORIENTATION_PORTRAIT) {
hideSidePanel();
}
}
private void hideSidePanel() {
View detailPane = findViewById(R.id.detail_panel);
if(detailPane.getVisibility() == View.VISIBLE) {
detailPane.setVisibility(View.GONE);
}
}
}
MainPanelFragment:
public class MainPanelFragment extends ListFragment {
boolean orientation;
int currentListViewItem;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter<String> connectArrayToListView = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1, API.dummyData);
setListAdapter(connectArrayToListView);
orientation = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
if (savedInstanceState != null) {
currentListViewItem = savedInstanceState.getInt("curChoice", 0);
}
if (orientation) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
showDetails(currentListViewItem);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.fragment_main_panel, container, false);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("curChoice", currentListViewItem);
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
showDetails(position);
// super.onListItemClick(l, v, position, id);
}
void showDetails(int kaart) {
currentListViewItem = kaart;
if (orientation) {
getListView().setItemChecked(kaart, true);
DetailPanelFragment details = (DetailPanelFragment) getFragmentManager().findFragmentById(R.id.detail_panel);
if (details == null || details.getShowIndex() == -1) {
details = DetailPanelFragment.newInstance(kaart);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.main_panel, details);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
} else {
Intent intent = new Intent();
intent.setClass(getActivity(), DetailsActivity.class);
intent.putExtra("index", kaart);
startActivity(intent);
}
}
}
activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:id="#+id/main_panel"
android:layout_alignParentRight="true"
class="nl.avans.mbd2.android.gideon.van.david.multipanefragment.MainPanelFragment"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/detail_panel"
android:layout_alignParentLeft="true"
class="nl.avans.mbd2.android.gideon.van.david.multipanefragment.DetailPanelFragment"/>
</LinearLayout>
fragment_detail_panel.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_bright"
android:layout_gravity="top|center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detail panel"
android:textColor="#android:color/white"
android:textStyle="bold"
android:id="#+id/kaartenListViewDetail"
/>
</LinearLayout>
fragment_main_panel.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_red_dark"
android:layout_gravity="top|center"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/list">
</ListView>
</LinearLayout>
I also have a folder in /res named layout-land. It contains an activity_main.xml file which is exactly identical to the one posted above.
I've seen similiar questions like this one but it seems that this situation is not (enough) the same to find a valid answer.
Related
I have a fragment, and I want to click on a button in the fragment to open a corresponding Activity that also hosts a fragment.
I am trying to test how the Activity appears (after button click) and am receiving what appears to be an inflation error. Here is the first fragment containing the button to view the next fragment:
HomePollsFragment.Java
mLatestTestButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent latestActivity = new Intent(getActivity().getApplicationContext(), LatestActivity.class);
startActivity(latestActivity);
}
});
And then here is the code for the activity that is opened on button click:
public class LatestActivity extends AppCompatActivity implements LatestFragment.OnFragmentInteractionListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_latest);
// Check that the activity is using the layout version with
// the fragment_container FrameLayout
if (findViewById(R.id.latest_fragment_container) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
return;
}
// Create a new Fragment to be placed in the activity layout
LatestFragment latestFragment = new LatestFragment();
// In case this activity was started with special instructions from an
// Intent, pass the Intent's extras to the fragment as arguments
latestFragment.setArguments(getIntent().getExtras());
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction()
.add(R.id.latest_fragment_container, latestFragment).commit();
}
}
#Override
public void onFragmentInteraction(Uri uri) {
}
}
The error I am receiving is below and appears to be related to the following line:
setContentView(R.layout.activity_latest);
Error:
06-27 22:35:47.787 4252-4252/com.sourcey.materialloginexample E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sourcey.materialloginexample/com.troychuinard.fanpolls.LatestActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.troychuinard.fanpolls.LatestActivity.onCreate(LatestActivity.java:14)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: name == null
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:491)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:454)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2252)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.troychuinard.fanpolls.LatestActivity.onCreate(LatestActivity.java:14)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
activity_latest.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/latest_fragment_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp" />
The error is telling you that you have no name attribute on the <fragment> element specifying its class.
NullPointerException: name == null
However, it looks like you mean to load the Fragment yourself, so you don't want a <fragment> element. Instead, you want a ViewGroup that will hold the Fragment after the dynamic FragmentTransaction. Change your <fragment> to a <FrameLayout>.
That because you have a wrong on your activity_latest.xml. You tried to add your LatestFragment to Fragment. You can add fragment into ViewGroup like FrameLayout. Change your code like here.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/latest_fragment_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp" />
I'm trying to add facebook login with a login button in a fragment.
When I try to run my app, it crashes and I get the following errors in my logcat
02-20 15:30:34.838 12503-12503/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.loomius.loomius, PID: 12503
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.loomius.loomius/com.loomius.loomius.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2200)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.loomius.loomius.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: Unexpected CallbackManager, please use the provided Factory.
at com.facebook.login.LoginManager.registerCallback(LoginManager.java:151)
at com.facebook.login.widget.LoginButton.registerCallback(LoginButton.java:445)
at com.loomius.loomius.facebookLogin.onCreateView(facebookLogin.java:36)
at android.app.Fragment.performCreateView(Fragment.java:1700)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:866)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1040)
at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1142)
at android.app.Activity.onCreateView(Activity.java:4803)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:34)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:41)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:830)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:400)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.loomius.loomius.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.loomius.loomius" >
<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" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<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>
and here is my MainActivity.java file
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
// Initialize the SDK before executing any other operations,
// especially, if you're using Facebook UI elements.
setContentView(R.layout.activity_main);
}
}
My activity_main.xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<fragment android:name="com.loomius.loomius.facebookLogin"
android:id="#+id/facebookLogin"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
and my fragment_facebook_login.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.loomius.loomius.facebookLogin">
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
</FrameLayout>
and finally my facebookLogin.java
public class facebookLogin extends Fragment {
CallbackManager callbackManager;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
View view = inflater.inflate(R.layout.fragment_facebook_login, container, false);
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
// If using in a fragment
loginButton.setFragment(this);
// Other app specific specialization
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.d("facebook_login", "The login was a success");
}
#Override
public void onCancel() {
Log.d("facebook_login", "The login got canceled midway");
}
#Override
public void onError(FacebookException exception) {
Log.d("facebook_login", "The login got failed");
}
});
return view;
}
}
I tried following the guide in the documentation by facebook. Sorry for the code dump, I'm new to android and I have no idea what's causing my app to crash.
callbackManager = CallbackManager.Factory.create(); put this code below
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());.
You have to initialze the callbackManager .
Cheers!!
you also need
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
for callbacks to work
Whenever I run app android application on my tablet, connected with ADB (USB and developers mode in android). In Tablet show message "Unfortunalty stopped". But when i run application on Android-x86 virual device (Virtual box) all fine.
Where is the mistake?
ADT (Logcat) logs says:
02-10 12:52:39.310 3897-3897/com.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #22: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.test.PageSplash.onCreateView(PageSplash.java:17)
at android.app.Fragment.performCreateView(Fragment.java:1695)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
at android.app.BackStackRecord.run(BackStackRecord.java:694)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.test.PageSplash.onCreateView(PageSplash.java:17)
at android.app.Fragment.performCreateView(Fragment.java:1695)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
at android.app.BackStackRecord.run(BackStackRecord.java:694)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=25; index=959
at android.content.res.StringBlock.get(StringBlock.java:64)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)
at android.content.res.TypedArray.getString(TypedArray.java:124)
at android.widget.TextView.<init>(TextView.java:971)
at android.widget.Button.<init>(Button.java:107)
at android.widget.Button.<init>(Button.java:103)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.test.PageSplash.onCreateView(PageSplash.java:17)
at android.app.Fragment.performCreateView(Fragment.java:1695)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
at android.app.BackStackRecord.run(BackStackRecord.java:694)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
PageSplash xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#color/white"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:gravity="center_horizontal" android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView17" android:src="#drawable/splash_image"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_to_test"
android:id="#+id/textView34" android:textColor="#404041" android:textSize="24sp"
android:layout_marginTop="40dp" android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="220dp"
android:layout_height="wrap_content"
android:text="#string/login"
android:id="#+id/btn_login" android:textColor="#color/white" android:background="#drawable/splash_button"
style="#android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="34dp"
android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
<Button
android:layout_width="220dp"
android:layout_height="wrap_content"
android:text="#string/continue_as_guest"
android:id="#+id/btn_guest" android:textColor="#color/white" android:background="#drawable/splash_button"
style="#android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
<Button
android:layout_width="220dp"
android:layout_height="wrap_content"
android:text="#string/create_account"
android:id="#+id/btn_join" android:textColor="#color/white" android:background="#drawable/splash_button"
style="#android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="right" android:layout_marginTop="20dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/done"
android:id="#+id/btn_done" style="#android:style/Widget.DeviceDefault.Button.Borderless.Small"
android:textSize="#dimen/button" android:textColor="#color/main_blue"
android:textAllCaps="true" android:layout_marginRight="30dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
PageSplash java
package com.test;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
public class PageSplash extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.page_splash, null);
Button btn_login = (Button) v.findViewById(R.id.btn_login);
if(btn_login != null)
{
btn_login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Fragment login = new PageLogin();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.main_content, login);
ft.addToBackStack(null);
ft.commit();
}
});
}
Button btn_join = (Button) v.findViewById(R.id.btn_join);
if(btn_join != null)
{
btn_join.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Fragment join = new PageJoin();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.main_content, join);
ft.addToBackStack(null);
ft.commit();
}
});
}
Button btn_guest = (Button) v.findViewById(R.id.btn_guest);
btn_guest.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Fragment index = new PageIndex();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.main_content, index);
ft.addToBackStack(null);
ft.commit();
}
});
Button btn_done = (Button) v.findViewById(R.id.btn_done);
btn_done.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Fragment index = new PageIndex();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.main_content, index);
ft.addToBackStack(null);
ft.commit();
}
});
LinearLayout menu_bottom = (LinearLayout) getActivity().findViewById(R.id.menu_bottom);
menu_bottom.setVisibility(View.GONE);
return v;
}
public void onPause()
{
super.onPause();
LinearLayout menu_bottom = (LinearLayout) getActivity().findViewById(R.id.menu_bottom);
menu_bottom.setVisibility(View.VISIBLE);
}
}
Thanks alot
Apparently there seems to be some issue in
<Button
android:layout_width="220dp"
android:layout_height="wrap_content"
android:text="#string/login"
android:id="#+id/btn_login" android:textColor="#color/white" android:background="#drawable/splash_button"
style="#android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="34dp"
android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
try to debug #android:style/Widget.DeviceDefault.Button.Borderless.Small
I have a class login.java which i am running as main activity but when i run it the application suddenly stops and says following error. I have also pasted activity_login.xml and login.java. I am stuck here and can not understand what the issue is. Any suggestions please
Error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.funtube_mp4/com.example.admin.funtube_mp4.Login}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.admin.funtube_mp4.Login.onCreate(Login.java:24)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.admin.funtube_mp4.Login.onCreate(Login.java:24)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0b0001 a=-1 r=0x7f0b0001}
at android.content.res.Resources.loadDrawable(Resources.java:3348)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3715)
at android.view.ViewGroup.<init>(ViewGroup.java:480)
at android.widget.LinearLayout.<init>(LinearLayout.java:176)
at android.widget.LinearLayout.<init>(LinearLayout.java:172)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.admin.funtube_mp4.Login.onCreate(Login.java:24)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/bg_login"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<EditText
android:id="#+id/email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:hint="#string/hint_email"
android:inputType="textEmailAddress"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_login"
android:textColorHint="#color/input_login_hint" />
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:hint="#string/hint_password"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_login"
android:textColorHint="#color/input_login_hint" />
<!-- Login Button -->
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="#color/btn_login_bg"
android:text="#string/btn_login"
android:textColor="#color/btn_login" />
<!-- Link to Login Screen -->
<Button
android:id="#+id/btnLinkToRegisterScreen"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:background="#null"
android:text="#string/btn_link_to_register"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
login.java
package com.example.admin.funtube_mp4;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends AppCompatActivity {
private FunTubeOperations FunTubeDBOperations;
private DatabaseWrapper db;
private SessionManager session;
public static String UserName;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final AlertDialog ad = new AlertDialog.Builder(this).create();
Button login = (Button) findViewById(R.id.btnLogin);
Button reg = (Button) findViewById(R.id.btnLinkToRegisterScreen);
FunTubeDBOperations = new FunTubeOperations(this);
FunTubeDBOperations.open();
db = new DatabaseWrapper(getApplicationContext());
// Session manager
session = new SessionManager(getApplicationContext());
// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
Intent intent = new Intent(Login.this, Main.class);
// session.setname(UserName);
String n=session.getdata();
//session.pref.getString(USER_NAME,UserName);
intent.putExtra("name", n);
startActivity(intent);
finish();
}
reg.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(Login.this, register.class);
startActivity(intent);
finish();
}
});
try {
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
EditText email = (EditText) findViewById(R.id.email);
EditText password = (EditText) findViewById(R.id.password);
if (email != null && password !=null) {
String em=email.getText().toString();
String pwd=password.getText().toString();
UserName= FunTubeDBOperations.loginUsers(em, pwd);
if(UserName!=null)
{
session.setLogin(true);
session.setname(UserName);
Toast.makeText(getApplicationContext(), "Login successfully!!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Login.this, Main.class);
intent.putExtra("name", UserName);
startActivity(intent);
finish();
}
else
{
Toast.makeText(getApplicationContext(), "Invalid information provided!! Check your credentials or Sign up account!!", Toast.LENGTH_LONG).show();
}
}
else {
Toast.makeText(getApplicationContext(), "Fill all the fields!!", Toast.LENGTH_LONG).show();
}
}
});
} catch (Exception er) {
ad.setMessage(er.toString());
}
}
}
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bg_login">#26AE90</color>
<color name="bg_register">#2E3237</color>
<color name="bg_main">#428BCA</color>
<color name="white">#FFFFFF</color>
<color name="input_login">#222222</color>
<color name="input_login_hint">#999999</color>
<color name="input_register">#888888</color>
<color name="input_register_bg">#3B4148</color>
<color name="input_register_hint">#5E6266</color>
<color name="btn_login">#26AE90</color>
<color name="btn_login_bg">#ECEEF1</color>
<color name="lbl_name">#333333</color>
<color name="btn_logut_bg">#FF6861</color>
<color name="view_background">#E8ECfA</color>
<color name="btn_bg">#277BEC</color>
<color name="txt_font">#4E5572</color>
<color name="action_bar">#1F2649</color>
</resources>
Hello i'm struggling with these error for past of couple of hours to no avail. I am trying to pass data from my activity to the fragment but not succeeding in doing so. My guess it's complaining about my <fragment> in activity_second.xml file. My guess might be wrong. Has anyone encountered this error? But i don't know how to resolve this error.Would some please guide in me what i did wrong. Below is my code:
first_fragment.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fragmentPic" >
<TextView
android:id="#+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/users_FirstName"
android:textSize="#dimen/font_size"
android:layout_gravity="center_horizontal"/>
<com.facebook.login.widget.ProfilePictureView
android:id="#+id/profilePic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>
</com.facebook.login.widget.ProfilePictureView>
</LinearLayout>
FirstFragment.java:
public class FirstFragment extends Fragment {
private ProfilePictureView profilePictureView;
private TextView textView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// return super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.first_fragment, container, false);
Bundle bundle = new Bundle();
bundle = this.getArguments();
String profileId = bundle.getString("profileId"); //complains here and returns null
TextView textView = (TextView)rootView.findViewById(R.id.textName);
textView.setText(bundle.getString("names"));
return rootView;
}
}
activity_second.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/backgroundColor"
>
<include android:id="#+id/toolBar"
layout="#layout/toolbar" />
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/first_fragment"
class="edu.sjsu.cmpe277.termproject.Fragments.FirstFragment"
android:id="#+id/fragment1"
/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
secondActivity.java:
public class secondActivity extends AppCompatActivity {
private Intent intent;
private Toolbar toolbar;
private String firstName, profileId;
private FirstFragment firstFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
intent = getIntent();
firstName = intent.getStringExtra("firstName");
profileId = intent.getStringExtra("Id");
toolbar = (Toolbar)findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
toolbar.setLogo(R.drawable.ic_menu_image);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
firstFragment = new FirstFragment();
Bundle bundle = new Bundle();
bundle.putString("names", firstName);
bundle.putString("profileId", profileId);
firstFragment.setArguments(bundle);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.drawer, firstFragment,"newFrag").commit();
}
#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_second, 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.
switch(item.getItemId()) {
case android.R.id.home:
Intent homeIntent = new Intent(this, secondActivity.class );
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
}
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And this error below:
29 01:50:11.402 13536-13536/edu.sjsu.cmpe277.termproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: edu.sjsu.cmpe277.termproject, PID: 13536
java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.sjsu.cmpe277.termproject/edu.sjsu.cmpe277.termproject.secondActivity}: android.view.InflateException: Binary XML file line #82: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.view.InflateException: Binary XML file line #82: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:255)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at edu.sjsu.cmpe277.termproject.secondActivity.onCreate(secondActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
at edu.sjsu.cmpe277.termproject.Fragments.FirstFragment.onCreateView(FirstFragment.java:44)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1185)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1287)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2243)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:278)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:78)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:255)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at edu.sjsu.cmpe277.termproject.secondActivity.onCreate(secondActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
Get rid of
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/first_fragment"
class="edu.sjsu.cmpe277.termproject.Fragments.FirstFragment"
android:id="#+id/fragment1"
/>
and use only the explicitly transaction you are using in your Activity. You can't pass a Bundle, declaring a Fragment in the layout, and try to accessing it, is making your app crash
In your activity_second.xml file, change:
class="edu.sjsu.cmpe277.termproject.Fragments.FirstFragment"
to
android:name="edu.sjsu.cmpe277.termproject.Fragments.FirstFragment"
That's the correct prefix to use.