Unable to pass data from activity to a fragment - android

I'll start by saying that I'm new to Android programming, and after reading countless posts around here, I'm still unable to determine what I'm doing wrong when trying to pass some arguments from a Fragment to an Activity and any help would be extremely helpful.
My Activity class:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static final MasterFragment newInstance(String numberOfItems) {
MasterFragment masterFragment = new MasterFragment();
Bundle bundle = new Bundle();
bundle.putString("numberOfItems", numberOfItems);
masterFragment.setArguments(bundle);
return masterFragment;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
MasterFragment masterFragment = new MasterFragment();
masterFragment.setArguments(getIntent().getExtras());
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/*getting some buttons here
*/
//not sure if relevant, but just in case I'll add this here too
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_menu_white_24dp);
if (toolbar != null) {
toolbar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SlidingPaneLayout mSlidingLayout;
mSlidingLayout = (SlidingPaneLayout) findViewById(R.id.mainSlidingPaneLayout);
if (mSlidingLayout.isOpen()) {
mSlidingLayout.closePane();
getSupportActionBar().setIcon(R.drawable.ic_menu_white_24dp);
} else {
mSlidingLayout.openPane();
getSupportActionBar().setIcon(R.drawable.ic_arrow_back_white_24dp);
}
}
});
}
}
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), ProductsScrollingActivity
.class);
ArrayList<String> products = new ArrayList<String>();
switch (v.getId()) {
case R.id.baby: {
//getting the products ArrayList here
break;
}
}
intent.putExtra("products", products);
startActivity(intent);
}
}
My Fragment class:
public class MasterFragment extends ListFragment {
String noOfItems;
#Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_master, container);
noOfItems = getArguments().getString("numberOfItems", "0");
setListAdapter(new MenuListAdapter(R.layout.row_menu_action_item, getActivity(), MenuActionItem.values(), noOfItems));
return view;
}
}
My content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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:background="#ffffff"
android:orientation="horizontal"
android:id="#+id/mainSlidingPaneLayout"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.MainActivity"
tools:showIn="#layout/activity_main">
<!--Master fragment-->
<fragment
android:id="#+id/fragment_master"
android:name="com.example.MasterFragment"
android:layout_width="#dimen/mini_drawer_fragment_width"
android:layout_height="match_parent"
tools:layout="#layout/fragment_master">
</fragment>
<!-- A ScrollView goes here with some other stuff-->
</android.support.v4.widget.SlidingPaneLayout>
Stack trace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainActivity}: android.view.InflateException: Binary XML file line #25: Binary XML file line #20: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #20: Error inflating class fragment
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.MainActivity.onCreate(MainActivity.java:59)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
at com.example.MainActivity.onCreate(MainActivity.java:59) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String, java.lang.String)' on a null object reference
at com.example.MasterFragment.onCreateView(MasterFragment.java:26)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1036)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1226)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1328)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2284)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314)
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:754)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
at com.example.MainActivity.onCreate(MainActivity.java:59) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

When you define a fragment in XML, you are not able to set the arguments on the fragment before the fragment is inflated - so in your fragment's code in onViewCreated, getArguments() is null, which causes this crash. If you want to add arguments to your fragment, replace the <fragment> tag in XML with a FrameLayout, define the fragment in your activity (as you are doing already) and add it to the FrameLayout with the FragmentManager:
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, /*id of your frame layout*/
fragment /*instance of the fragment created in your activity*/)
.commit();

Related

Android app crashes at setContentView(R.layout.XXXXXX);

My app gets crashed after the execution of setContentView line. Here is my logcat
--------- beginning of crash
05-09 14:46:29.664 12307-12307/com.bitproject.driverapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bitproject.driverapplication, PID: 12307
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bitproject.driverapplication/com.bitproject.driverapplication.SettingsActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class de.hdodenhof.circleimageview.CircleImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class de.hdodenhof.circleimageview.CircleImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.bitproject.driverapplication.SettingsActivity.onCreate(SettingsActivity.java:37)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class de.hdodenhof.circleimageview.CircleImageView
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
at com.bitproject.driverapplication.SettingsActivity.onCreate(SettingsActivity.java:37) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
at com.bitproject.driverapplication.SettingsActivity.onCreate(SettingsActivity.java:37) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.res.Resources$NotFoundException: Resource "com.bitproject.driverapplication:drawable/profile_image" (7f0700a1) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0700a1 a=-1 r=0x7f0700a1}
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2602)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at de.hdodenhof.circleimageview.CircleImageView.<init>(CircleImageView.java:98)
at de.hdodenhof.circleimageview.CircleImageView.<init>(CircleImageView.java:94)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) 
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) 
at com.bitproject.driverapplication.SettingsActivity.onCreate(SettingsActivity.java:37) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
05-09 14:46:29.892 12307-12375/com.bitproject.driverapplication V/FA: Recording user engagement, ms: 3084
05-09 14:46:29.897 12307-12375/com.bitproject.driverapplication V/FA: Activity paused, time: 64601668
I'm very new to android, I tried to read the log and find the issue. But I failed. There are a couple of related questions but can't understand how to relate them with mine.
Here's the Java file.
public class SettingsActivity extends AppCompatActivity {
private Button updateAccountSettings;
private EditText username;
private CircleImageView userProfileImage;
private String currentUserID;
private FirebaseAuth mAuth;
private DatabaseReference rootRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings); <----------------- App crashes at here
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
rootRef = FirebaseDatabase.getInstance().getReference().child("Users").child("Driver");
updateAccountSettings = (Button) findViewById(R.id.update_settings_button);
username = (EditText) findViewById(R.id.set_user_name);
userProfileImage = (CircleImageView) findViewById(R.id.set_profile_image);
updateAccountSettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
updateSettings();
}
});
}
private void updateSettings() {
String setUsername = username.getText().toString();
if (TextUtils.isEmpty(setUsername)) {
Toast.makeText(this, "Please enter your user name...",Toast.LENGTH_SHORT).show();
}
else {
HashMap<String, String> profileMap = new HashMap<>();
profileMap.put("UserID", currentUserID);
profileMap.put("Name", setUsername);
rootRef.child(currentUserID).setValue(profileMap)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Intent intent = new Intent(SettingsActivity.this, MessageActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
Toast.makeText(SettingsActivity.this, "Profile Updates Successfully!", Toast.LENGTH_SHORT).show();
}
else {
String message = task.getException().toString();
Toast.makeText(SettingsActivity.this, "Error! " + message, Toast.LENGTH_SHORT).show();
}
}
});
}
}
}
I have another activity called mainActivity. If there is no user name under currentUserId at firebase the mainActivity will have an intent to settingsActivity (java coding have provided above). When it gets intent the error occurs.
XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryLight"
tools:context=".SettingsActivity">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/set_profile_image"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
android:src="#drawable/profile_image"
app:civ_border_width="5dp"
app:civ_border_color="#color/colorPrimary"/>
<EditText
android:id="#+id/set_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/set_profile_image"
android:inputType="textMultiLine"
android:hint="Username"
android:textSize="20sp"
android:textAlignment="viewStart"
android:drawablePadding="20dp"
android:drawableStart="#drawable/edit_profile"
android:textColor="#color/colorPrimaryDark"
android:textStyle="bold"
android:background="#drawable/edit_text_background"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:padding="6dp"
android:textColorHint="#color/colorSecondaryText"
android:layout_marginTop="20dp"/>
<Button
android:id="#+id/update_settings_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/set_user_name"
android:inputType="textMultiLine"
android:text="Update"
android:textAlignment="center"
android:textColor="#color/colorPrimaryText"
android:textStyle="bold"
android:background="#drawable/button_corner"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"
android:padding="6dp"
android:layout_marginTop="10dp"
android:textAllCaps="false"
android:textSize="20sp"/>
</RelativeLayout>
Caused by: android.content.res.Resources$NotFoundException: Resource
"com.bitproject.driverapplication:drawable/profile_image" (7f0700a1)
is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0700a1 a=-1
r=0x7f0700a1}
Check these lines at your logcat carefully. I ran your code in my environment. It just worked fine. There is no problem in inflating CircleImageView. It is clear that your #drawable/profile_image is not a valid drawable, may be it is not a supported image file or it is corrupted. Using a valid drawable will solve this issue.
Issue is in CircleImageView. With deleting it your problem will be solved. Check its library to be correctly imported.

How to fix this error? Error inflating class android.support.design.widget.NavigationView

LOGCAT
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.batyaa.first_gear_automotive, PID: 2582
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.batyaa.first_gear_automotive/com.example.batyaa.first_gear_automotive.HomeActivity}: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.batyaa.first_gear_automotive.HomeActivity.onCreate(HomeActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.batyaa.first_gear_automotive.HomeActivity.onCreate(HomeActivity.java:23) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.batyaa.first_gear_automotive.HomeActivity.onCreate(HomeActivity.java:23) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class ImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:207)
at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:281)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:193)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:104)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.batyaa.first_gear_automotive.HomeActivity.onCreate(HomeActivity.java:23) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(NavigationMenuPresenter.java:207) 
at android.support.design.widget.NavigationView.inflateHeaderView(NavigationView.java:281) 
at android.support.design.widget.NavigationView.<init>(NavigationView.java:193) 
at android.support.design.widget.NavigationView.<init>(NavigationView.java:104) 
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.batyaa.first_gear_automotive.HomeActivity.onCreate(HomeActivity.java:23) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.batyaa.first_gear_automotive:drawable/logo" (7f070103) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070103 a=-1 r=0x7f070103}
at android.content.res.Resources.loadDrawableForCookie(Re
Application terminated.
HOME ACTIVITY
private ActionBarDrawerToggle mToggle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout,toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawerLayout.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//SECOND MENU
mToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_close, R.string.navigation_drawer_open);
mToggle.syncState();
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//******************************* SETTING UP SCROLL BAR *********************************
}
#Override
public void onBackPressed(){
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if(drawer.isDrawerOpen(GravityCompat.START))
{
drawer.closeDrawer(GravityCompat.START);
}
else
{
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
//EXTRA SETTINGS MENU DROP DOWN
getMenuInflater().inflate(R.menu.nav_drawer , menu );
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_settings)
{
return true;
}
if(mToggle.onOptionsItemSelected(item))
{
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
int id = menuItem.getItemId();
if(id == R.id.inventory)
{
Intent goToInventory = new Intent(HomeActivity.this, InventoryActivity.class);
startActivity(goToInventory);
Toast.makeText(getApplicationContext(),"Welcome To Car Inventory", Toast.LENGTH_SHORT).show();
}
else if(id == R.id.home)
{
Intent goToLocation = new Intent(this, HomeActivity.class);
startActivity(goToLocation);
Toast.makeText(getApplicationContext(),"Welcome To HOME", Toast.LENGTH_SHORT).show();
}
else if(id == R.id.location)
{
Intent goToLocation = new Intent(HomeActivity.this, LocationActivity.class);
startActivity(goToLocation);
Toast.makeText(getApplicationContext(),"Welcome To Store Location", Toast.LENGTH_SHORT).show();
}
else if(id == R.id.office_hours)
{
Intent goToOfficeHours = new Intent(HomeActivity.this, Office_Hours_Activity.class);
startActivity(goToOfficeHours);
Toast.makeText(getApplicationContext(),"Welcome To Our Office Hours", Toast.LENGTH_SHORT).show();
}
else if(id == R.id.warranty)
{
Intent goToWarranty = new Intent(HomeActivity.this, Warranty_Activity.class);
startActivity(goToWarranty);
Toast.makeText(getApplicationContext(),"Welcome To Our Car Warranty", Toast.LENGTH_SHORT).show();
}
else if (id == R.id.feedback)
{
Intent goToFeedback = new Intent(HomeActivity.this, Feedback_Activity.class);
startActivity(goToFeedback);
Toast.makeText(getApplicationContext(),"Welcome To Car Feedback", Toast.LENGTH_SHORT).show();
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
The error message includes
Caused by: android.view.InflateException:
Binary XML file line #12: Error inflating class ImageView at
...
android.support.design.internal.NavigationMenuPresenter.inflateHeaderView(
NavigationMenuPresenter.java:207)
...
Caused by: android.content.res.Resources$NotFoundException:
Resource "com.example.batyaa.first_gear_automotive:drawable/logo" (7f070103
is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070103 a=-1 r=0x7f070103}
Your #drawable/logo included in the layout you've set as the header of your NavigationView is not a valid drawable.

Cant return view but only recyclerview in onCreateView method (Fragment)

I plan to add a floating button in new feed function. However, during onCreateView method it only allow me to return recycleview but not the whole view which only return recycleview on the fragment.
This is my code in onCreateView method
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
posts = new ArrayList<>();
for(int i=9; i>=0; i--){
posts.add(new Post("Testing"+i,"For testing","https://picsum.photos/600/300?random?"+i));
}
recyclerView = new RecyclerView(getContext());
LinearLayoutManager lim = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(lim);
pa = new PostAdapter(posts, this);
recyclerView.setAdapter(pa);
recyclerView.setItemAnimator(new DefaultItemAnimator());
return recyclerView;
}
This is how i do while i try to return whole view
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
posts = new ArrayList<>();
for(int i=9; i>=0; i--){
posts.add(new Post("Testing"+i,"For testing","https://picsum.photos/600/300?random?"+i));
}
view = inflater.inflate(R.layout.fragment_chat, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.strView);
LinearLayoutManager lim = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(lim);
pa = new PostAdapter(posts, this);
recyclerView.setAdapter(pa);
return view;
}
Here is the xml file
<FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/strView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/addStrBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:backgroundTint="#color/colorWhite"
android:clickable="true"
android:cropToPadding="false"
android:elevation="#dimen/cardview_default_elevation"
android:src="#drawable/baseline_create_black_18dp"
app:fabSize="normal"/>
Logcat while try to return view
06-20 20:53:57.733 4990-4990/com.example.cheejin.fyp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cheejin.fyp, PID: 4990
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cheejin.fyp/com.example.cheejin.fyp.HomePage}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.example.cheejin.fyp.ChatFragment.onCreateView(ChatFragment.java:56)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1421)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1752)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1821)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2595)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2382)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2337)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2244)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3255)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3205)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:195)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:597)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
at android.app.Activity.performStart(Activity.java:6253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at com.example.cheejin.fyp.ChatFragment.onCreateView(ChatFragment.java:56) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1421) 
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1752) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1821) 
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797) 
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2595) 
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2382) 
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2337) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2244) 
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3255) 
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3205) 
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:195) 
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:597) 
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177) 
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237) 
at android.app.Activity.performStart(Activity.java:6253) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at com.example.cheejin.fyp.ChatFragment.onCreateView(ChatFragment.java:56) 
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1421) 
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1752) 
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1821) 
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797) 
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2595) 
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2382) 
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2337) 
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2244) 
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3255) 
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3205) 
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:195) 
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:597) 
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177) 
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237) 
at android.app.Activity.performStart(Activity.java:6253) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:1723)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1792)
at android.graphics.drawable.RippleDrawabl
I found the solution....
Refer to this link
https://blog.csdn.net/Sean_css/article/details/68592412
Just have to change
android:backgroundTint="#color/colorPrimary"
to
app:backgroundTint="#color/colorPrimary"
You are not using the layout XML at all. You need to inflate the layout from XML and then find the RecyclerView in that layout.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_layout, parent, false);
RecyclerView postList = rootView.findViewById(R.id.strView);
// initialize the recyclerview here like you have above with the layoutmanager and adapter
return rootView;
}
They you can add things like a floating action button, or any other views you want in the layout by writing them in the XML file.

calling multiple activities using intent

This code is not working as expected. I have created 5 activities, and I am using button faq in activity1 to intent activity2. In activity2 I am calling three more activities 3, 4 and 5, and on running the app it is displaying unfortunately stopped. I do not think I am using the intent correctly.
java code for activity1
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.faq);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// do something when the button is clicked
// Yes we will handle click here but which button clicked??? We don't know
// So we will mak
if(v.getId() == R.id.faq)
{
// do something when the corky is clicked
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}}}
xml for activity1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/educa"
tools:context="com.example.android.educato.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:textColor="#000000"
android:id="#+id/faq"
android:text="frequently asked questions (faq)"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Never stop learning!"
android:textColor="#DC143C"
android:textAllCaps="true"
android:textSize="56sp"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="#+id/textView" />
</RelativeLayout>
java code for activity2
public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Capture our button from layout
Button button = (Button)findViewById(R.id.b1);
Button button2 = (Button)findViewById(R.id.b2);
Button button3 = (Button)findViewById(R.id.b3);
// Register the onClick listener with the implementation above
button.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// do something when the button is clicked
// Yes we will handle click here but which button clicked??? We don't know
// So we will make
switch (v.getId() /*to get clicked view id**/) {
case R.id.b1:
// do something when the corky is clicked
Intent intent = new Intent(Main2Activity.this,Main3Activity.class);
startActivity(intent);
break;
case R.id.b2:
// do something when the corky2 is clicked
Intent intent1 = new Intent(Main2Activity.this,Main4Activity.class);
startActivity(intent1);
break;
case R.id.b3:
// do something when the corky3 is clicked
Intent intent2 = new Intent(Main2Activity.this,Main5Activity.class);
startActivity(intent2);
break;
default:
break;
}
}
}
xml for activity2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/educ"
android:orientation="vertical"
tools:context="com.example.android.educato.Main2Activity">
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:text="emergency contact numbers for resident of siliguri"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/b2"
android:gravity="center_horizontal"
android:text="mode of admission for iits"
android:layout_marginTop="24dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
/>
<Button
android:id="#+id/b3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="tourist attractions nearby siliguri"
android:layout_marginTop="24dp"
`` android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
/>
</LinearLayout>
logcat: after clicking the button in the app
Process: com.example.android.educato, PID: 9131
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.educato/com.example.android.educato.Main2Activity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2576)
at android.app.ActivityThread.access$1000(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.android.educato.Main2Activity.onCreate(Main2Activity.java:17)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2576) 
at android.app.ActivityThread.access$1000(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5539) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.android.educato.Main2Activity.onCreate(Main2Activity.java:17) 
at android.app.Activity.performCreate(Activity.java:6289) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2576) 
at android.app.ActivityThread.access$1000(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5539) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.android.educato.Main2Activity.onCreate(Main2Activity.java:17) 
at android.app.Activity.performCreate(Activity.java:6289) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2576) 
at android.app.ActivityThread.access$1000(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5539) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 814390212 byte allocation with 14818058 free bytes and 170MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2650)
at android.content.res.Resources.loadDrawable(Resources.java:2555)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.view.View.<init>(View.java:3964)
at android.view.ViewGroup.<init>(ViewGroup.java:574)
at android.widget.LinearLayout.<init>(LinearLayout.java:203)
at android.widget.LinearLayout.<init>(LinearLayout.java:199)
at android.widget.LinearLayout.<init>(LinearLayout.java:195)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.android.educato.Main2Activity.onCreate(Main2Activity.java:17) 
at android.app.Activity.performCreate(Activity.java:6289) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2576) 
at android.app.ActivityThread.access$1000(ActivityThread.java:155) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5539) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
12-21 03:16:51.633 9131-9131/com.example.android.educato D/AppTracker: App Event: crash
As what i seem your problem wasn't about intent. You use it correctly your problem is you setting the layout from your Main2Activity same as your MainActivity.
Just change the code inside Main2Activity class
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //change this line
...your code
}
to
setContentView(Your Main2Activity Layout);

Android app crashed if the main activity isn't MainActivity

I want to start with the Loading view but always crashed when I open it if the main activity in AndroidManifiest.xml isn't MainActivity. On the emulator is fine but the problem only is when install the apk in a phone. Any help?
AndroidManifiest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.daniel.jaentodayapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label=""
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".LoadingScreen"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
LoadingScreen
public class LoadingScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_screen);
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = new Intent(LoadingScreen.this, MainActivity.class);
startActivity(intent);
}
}
}).start();
}
#Override
protected void onPause() {
super.onPause();
finish();
}}
Layout Loading Screen
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_loading_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.daniel.jaentodayapp.LoadingScreen">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pcarga"></LinearLayout></RelativeLayout>
This is the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.daniel.jaentodayapp, PID: 18967
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.daniel.jaentodayapp/com.example.daniel.jaentodayapp.LoadingScreen}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.daniel.jaentodayapp.LoadingScreen.onCreate(LoadingScreen.java:13)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.daniel.jaentodayapp.LoadingScreen.onCreate(LoadingScreen.java:13) 
at android.app.Activity.performCreate(Activity.java:6285) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.daniel.jaentodayapp.LoadingScreen.onCreate(LoadingScreen.java:13) 
at android.app.Activity.performCreate(Activity.java:6285) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 255322380 byte allocation with 12571568 free bytes and 126MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.view.View.<init>(View.java:3955)
at android.view.ViewGroup.<init>(ViewGroup.java:574)
at android.widget.LinearLayout.<init>(LinearLayout.java:203)
at android.widget.LinearLayout.<init>(LinearLayout.java:199)
at android.widget.LinearLayout.<init>(LinearLayout.java:195)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.example.daniel.jaentodayapp.LoadingScreen.onCreate(LoadingScreen.java:13) 
at android.app.Activity.performCreate(Activity.java:6285) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
You can call startActivity() only from the main thread. If you want to make the call from a Runnable use a Handler If you call .run() instead of .start() the runnable would be executed on the calling thread
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_screen);
}
#Override
protected void onResume() {
super.onResume();
Intent intent = new Intent(LoadingScreen.this, MainActivity.class);
startActivity(intent);
finish();
}
Never put wait timer in loading screen unless necessary, call the MainActvity in onResume as by the time onResume is called, Sytem finishes the operations to load the App.
There are many examples on Stack overflow on how to implement Splash Screen (Loading Screen) in good way. meanwhile you can use this solution
You can try:
private final Handler mHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_screen);
mHandler.postDelayed(moveToMain, 3000);
}
private final Runnable moveToMain = new Runnable() {
public void run() {
startActivity(new Intent(LoadingScreen.this, MainActivity.class));
finish();
}
};
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
try {
Intent intent = new Intent(LoadingScreen.this,MainActivity.class);
startActivity(intent);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}, 3000);
please finish your activity while you start your new activity .
instead of finishing onpause()
This is an issue of running a UIThread on main thread .
hope that answer the question .
if you paste or show your stacktrace or error log it would make more easy to find a solution for this.
Thanks

Categories

Resources