how the second activity crash? - java

i just want to fill some infos in the activitymain and then pass an intent to a second activity, at the first it works perfect but when i add some xml layout, when running the app on device and pass the intent it crashes
the main activity
public void move(View view) {
Intent i = new Intent(MainActivity.this, FormActivity.class);
EditText name = findViewById(R.id.name);
EditText animal = findViewById(R.id.animal);
String n = name.getText().toString();
String a = animal.getText().toString();
if (n.isEmpty() || a.isEmpty()) {
Toast.makeText(this, "nom ou animal est vide !", Toast.LENGTH_SHORT).show();
} else {
i.putExtra("KEY_Name", name.getText().toString());
i.putExtra("KEY_Animal", animal.getText().toString());
startActivity(i);
}
}
// and the formactivity or the second
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
Intent i = getIntent();
TextView Text1 = findViewById(R.id.t1);
TextView Text2 = findViewById(R.id.t2);
String name = i.getStringExtra("KEY_Name");
String animal = i.getStringExtra("KEY_Animal");
Text1.setText(name);
Text2.setText(animal);
}
// XML file for activity_main it works perfect
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/dog" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:src="#drawable/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/hello"
android:textColor="#ffffff"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView"
app:layout_constraintVertical_bias="0.075" />
<LinearLayout
android:id="#+id/linear1"
style="#style/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/name"
android:textColor="#ffffff" />
<View
android:layout_width="3dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<EditText
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/ex_name"
android:inputType="textCapWords"
android:maxLines="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#ffffff"
app:layout_constraintBottom_toTopOf="#+id/linear2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/linear2" />
<LinearLayout
android:id="#+id/linear2"
style="#style/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:shadowColor="#000000"
android:shadowDx="-2"
android:shadowDy="-2"
android:shadowRadius="1"
android:text="#string/pet"
android:textColor="#ffffff" />
<View
android:layout_width="3dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<EditText
android:id="#+id/animal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="#string/ex_animal"
android:inputType="textCapWords"
android:maxLines="1" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:onClick="move"
android:text="Suivant"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.096"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linear2"
app:layout_constraintVertical_bias="0.344" />
// the activity_form or second that crashes
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/sheep" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:foregroundGravity="center_horizontal"
android:src="#drawable/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:background="#drawable/list_fluid"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/t1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center_horizontal"
android:text="Hello freind!"
android:textColor="#color/green"
android:textSize="24sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:background="#ffffff" />
<TextView
android:id="#+id/t2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="oh, puppy!"
android:textColor="#color/green"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="12dp"
android:text="comment Aidez-Vous ?" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="mon Chat souffre de fièvre"
android:inputType="text"
android:lines="6"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc"
android:textSize="12sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:background="#color/logo"
android:text="envoyer"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
the logcat
10-09 18:03:08.327 29724-29724/com.example.android.workingproject W/ResourceType: Failure getting entry for 0x01080946 (t=7 e=2374) (error -75)
10-09 18:04:20.737 29724-29724/com.example.android.workingproject W/ResourceType: Failure getting entry for 0x01080946 (t=7 e=2374) (error -75)
10-09 18:04:21.538 29724-29724/com.example.android.workingproject E/art: Throwing OutOfMemoryError "Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM"
10-09 18:04:21.608 29724-29724/com.example.android.workingproject E/art: Throwing OutOfMemoryError "Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM"
10-09 18:04:21.628 29724-29724/com.example.android.workingproject E/art: li.han, Prepare to dump hprof for OOM Error !
li.han, Directory [/data/log] could not be write !
10-09 18:04:21.638 29724-29724/com.example.android.workingproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.workingproject, PID: 29724
java.lang.OutOfMemoryError: Failed to allocate a 343944636 byte allocation with 16777120 free bytes and 52MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:837)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:656)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1037)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4056)
at android.content.res.Resources.loadDrawable(Resources.java:3929)
at android.content.res.Resources.loadDrawable(Resources.java:3779)
at android.content.res.TypedArray.getDrawable(TypedArray.java:776)
at android.widget.ImageView.<init>(ImageView.java:151)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
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.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.android.workingproject.FormActivity.onCreate(FormActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6934)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

At least one of the drawables referenced in your second XML file is too big.
Check the following drawables and resize them:
sheep
title
list_fluid
PNGs generally don't need to be very large. Keep them below 1600x1600 if you can, preferably 800x800.

Related

sending data of two fragments to firebase (Fragment wise or in one go)

I have two fragments in one activity. In the first fragment, I have fields like name, email, gender and phone number and by the next button replace with second fragment and on the second fragment, I have a password and confirm password fields. Now I want to send data to firebase fragment-wise or send data of two fragments at one time(by pressing the register button which is on the second fragment).but did not know how to do that
//First Fragment
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/purple_200"
tools:context=".CustomerRegisterFragment">
<ImageView
android:id="#+id/imageView"
android:layout_width="131dp"
android:layout_height="46dp"
android:src="#drawable/logo"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.18"
tools:ignore="MissingConstraints"
android:contentDescription="TODO" />
<TextView
android:id="#+id/textViewCustomerDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/personal_details"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.28"
tools:ignore="MissingConstraints" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.439"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:fontFamily="#font/courbd"
android:text="#string/user_name"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserName"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="textPersonName"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/user_email"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserEmail"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="textEmailAddress"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout1"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="Phone #:"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextUserPhone"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:backgroundTint="#color/black"
android:fontFamily="#font/courbd"
android:inputType="phone"
android:paddingBottom="4dp"
android:singleLine="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout2"
tools:ignore="MissingConstraints">
<TextView
android:id="#+id/textViewUserGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:fontFamily="#font/courbd"
android:text="#string/user_gender"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="true"
android:clickable="false"
android:focusableInTouchMode="true"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_male"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="false"
android:clickable="false"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_female"
android:textColor="#color/black" />
<CheckBox
android:id="#+id/other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/black"
android:checked="false"
android:clickable="false"
android:fontFamily="#font/courbd"
android:text="#string/user_gender_other"
android:textColor="#color/black" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnRegisterCustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="71dp"
android:layout_marginBottom="120dp"
android:background="#drawable/button_style"
android:text="#string/btn_next"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout3" />
</androidx.constraintlayout.widget.ConstraintLayout>
//Second Fragment
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/purple_200"
tools:context=".CustomerRegisterFragment1">
<ImageView
android:id="#+id/imageView"
android:layout_width="131dp"
android:layout_height="46dp"
android:src="#drawable/logo"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.18"
tools:ignore="MissingConstraints"
android:contentDescription="TODO" />
<TextView
android:id="#+id/textViewCustomerPassTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/courbd"
android:text="#string/c_password"
android:textColor="#color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.28"
tools:ignore="MissingConstraints" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/CustomerRegisterFragment1.linearLayout"
android:layout_centerVertical="true"
android:layout_marginBottom="288dp"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textViewCustomerPassTitle"
tools:ignore="MissingConstraints">
<EditText
android:id="#+id/editTextCustomerPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#695547"
android:fontFamily="#font/courbd"
android:hint="#string/customer_password"
android:inputType="textPassword"
android:textColor="#color/black"
android:textColorHint="#A88973" />
<EditText
android:id="#+id/editTextCustomerConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#695547"
android:fontFamily="#font/courbd"
android:hint="#string/cconfirm_password"
android:inputType="textPassword"
android:textColor="#color/black"
android:textColorHint="#A88973" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/btnRegisterCustomer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="67dp"
android:layout_marginBottom="123dp"
android:background="#drawable/button_style"
android:text="#string/btn_register_client"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/CustomerRegisterFragment1.linearLayout"
app:layout_constraintVertical_bias="0.229" />
</androidx.constraintlayout.widget.ConstraintLayout>
Interface;
interface:
public interface FragmentInterface {
String getName();
String getEmail();
String getPassword();
}
Fragment:
public class FragmentA extend Fragment implements FragmentInterface{}
public class FragmentB extend Fragment implements FragmentInterface{}
xxxActivity:
FragmentInterface fia = (FragmentInterface)FragmentA;
FragmentInterface fib = (FragmentInterface)FragmentB;
get Field:
String name = fia.getName();
String pw = fib.getPassword();
BroadcastReceiver
Global singleton
you have to use bundle in fragment to pass data from one fragment to another
Without Arch. Component...
send data to another fragment
Fragment fragment = new ProductdetailFragment();
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.frame_main,fragment);
transaction.addToBackStack(null);
transaction.commit();
Bundle bundle = new Bundle();
bundle.putString("product_id","value");
bundle.putString("product_name","value");
bundle.putString("price","value");
bundle.putString("product_desc","value");
bundle.putString("product_image",productmodels.get(position).getProduct_image());
fragment.setArguments(bundle);
get data from the previous fragment. for getting data, you have to use key of apply of the previous fragment.do not mismatch key argument
Bundle bundle = getArguments();
String product_id = bundle.getString("product_id");
String name = bundle.getString("product_name");
String price = bundle.getString("price");
String description = bundle.getString("product_desc");
String imageurl = bundle.getString("product_image");
Second Way if You use Navigation Arch. Component
Bundle bundle = new Bundle();
bundle.putString("amount", amount);
Navigation.findNavController(view).navigate(R.id.confirmationAction, bundle);

Android: Array loops return null elements

I have been trying to use getResources().getIdentifier() methods to assign ids to an array of images. However, when I consoled the array, I only got 2 valid elements and the rest was null. Could somebody please explain to me why after the onCreate method is executed, the program only consoles the values of the first 2 loops and returns null values afterward?
Currently: [ImageView0, ImageView1, null, null, null, null, null, null, null]
What should I do to make it fully loop through the array and return an array with valid values of [ImageView1, ImageView2, ImageView3, ImageView4, ImageView5, ImageView6, ImageView7, and ImageView8] instead ?
Many thanks! I am appreciated any help!
INPUT
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
ImageView[] computerImages;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
computerImages = new ImageView[9];
for (int i=0; i<computerImages.length; i++){
String computerImageID = "ImageView"+i;
int resID = getResources().getIdentifier(computerImageID,"id",getPackageName());
computerImages[i] = findViewById(resID);
} Log.i("ON CREATE", Arrays.toString(computerImages));
}
OUTPUT
I/ON CREATE: [android.support.v7.widget.AppCompatImageView{fe40fe0 VFED..C.. ......ID 0,0-0,0 #7f070003 app:id/ImageView0}, android.support.v7.widget.AppCompatImageView{8313299 VFED..C.. ......ID 0,0-0,0 #7f070004 app:id/ImageView1}, null, null, null, null, null, null, null]
XML LAYOUT
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<Button
android:id="#+id/button"
android:layout_width="172dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="Computer" />
<Button
android:id="#+id/button2"
android:layout_width="171dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="Player 02" />
</LinearLayout>
<GridLayout 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:id="#+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/board"
android:columnCount="3"
android:rowCount="3">
<ImageView
android:id="#+id/imageView0"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="0" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="0dp"
android:layout_marginTop="15dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="1" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="15dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="2" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_marginTop="16dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="3" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="1dp"
android:layout_marginTop="16dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="4" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="16dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="5" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_marginTop="16dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="6" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="1dp"
android:layout_marginTop="16dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="7" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="95dp"
android:layout_height="95dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="16dp"
android:alpha="0"
android:onClick="clickToPlay"
android:tag="8" />
</GridLayout>
<Button
android:id="#+id/playAgainButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:onClick="clickReset"
android:text="Play Again"
android:textSize="20sp" />
<TextView
android:id="#+id/winnerMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="1"
android:background="#android:color/holo_orange_dark"
android:padding="5dp"
android:text="TextView"
android:textColor="#android:color/white"
android:textSize="25sp"
android:visibility="invisible" />
</RelativeLayout>
It returning null because "ImageView3, ImageView4, ImageView5, ImageView6, ImageView7, and ImageView8" views are not present in resource file. Only ImageView0, ImageView1 are present in resource file.

Cannot Resolve symbol 'binding' error

So I recently started using binding and I enabled it in my gradle but when I try and use it I get an error? I synced the gradle and the project and everything is fine but when I try use the binding it gives me the "Cannot resolve symbol 'binding'" error. Help please! This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.mike.myapplication.adminScreen"
tools:showIn="#layout/activity_admin_screen">
<EditText
android:id="#+id/nameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="37dp"
android:layout_marginTop="31dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/timeToPrepEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Time To Prepare"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="#+id/nameEditText"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="#+id/nameEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/nameEditText" />
<EditText
android:id="#+id/descEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Description"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="#+id/timeToPrepEditText"
android:layout_marginTop="7dp"
app:layout_constraintTop_toBottomOf="#+id/timeToPrepEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/timeToPrepEditText" />
<EditText
android:id="#+id/priceEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Price"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="#+id/descEditText"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="#+id/descEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/descEditText" />
<Button
android:id="#+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Item"
android:onClick="addButtonClicked"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#+id/priceEditText"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/priceEditText" />
<Button
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete Item"
android:onClick="deleteButtonClicked"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="15dp"
app:layout_constraintTop_toBottomOf="#+id/addButton"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/addButton" />
<Button
android:id="#+id/databaseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display Database"
android:onClick="dispDatabaseButton"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="-79dp"
app:layout_constraintTop_toBottomOf="#+id/addButton"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="#+id/addButton"
android:layout_marginLeft="156dp" />
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-41dp"
android:layout_marginStart="15dp"
android:layout_marginTop="54dp"
android:onClick="dispDatabaseButton"
android:text="Results"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintLeft_toRightOf="#+id/deleteButton"
app:layout_constraintTop_toBottomOf="#+id/deleteButton"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
How do I fix my error?
In addition here is the code for the activity, in my case it isn't the default main activity but instead AdminScreen.
public class adminScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_screen);
}
private void saveToDB() {
SQLiteDatabase database = new DBSQLiteHelper(this).getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Menu.MenuItems.COLUMN_NAME, binding.nameEditText.getText().toString());
values.put(Menu.MenuItems.COLUMN_PREP, binding.timeToPrepEditText.getText().toString());
values.put(Menu.MenuItems.COLUMN_DESCRIPTION, binding.descEditText.getText().toString());
values.put(Menu.MenuItems.COLUMN_PRICE, binding.priceEditText.getText().toString());
long newRowId = database.insert(Menu.MenuItems.TABLE_NAME, null, values);
Toast.makeText(this, "The new Row Id is " + newRowId, Toast.LENGTH_LONG).show();
}
}
If you mean DataBinding library you should build you layout this way
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{user.firstName}"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#{user.lastName}"/>
</LinearLayout>
</layout>

"InvocationTargetException" Error

so, I'm getting an error after trying to load a tab in a Master/Flow layout. The tab that makes the app crash is a calculator with two images and a background image.
Here's the error:
04-23 09:21:40.609 1157-1157/endangeredspecies.androidbootcamp.net.finalproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: endangeredspecies.androidbootcamp.net.finalproject, PID: 1157
android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at endangeredspecies.androidbootcamp.net.finalproject.ItemDetailFragment.onCreateView(ItemDetailFragment.java:66)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
And this is where it is telling me the error is (ItemDetailFragment.java:66):
it is "rootView = inflater.inflate(R.layout.price_calculator, container, false);"
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
if (mItem !=null) {
if (mItem.id.equals("1")) {
rootView = inflater.inflate(R.layout.welcome_page, container, false);
} else if (mItem.id.equals("2")) {
rootView = inflater.inflate(R.layout.price_calculator, container, false);
} else if (mItem.id.equals("3")) {
((WebView) rootView.findViewById(R.id.item_Detail)).loadUrl(mItem.item_url);
}
}
return rootView;
}
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#mipmap/calc_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtCalc"
android:id="#+id/textView2"
android:layout_marginTop="47dp"
android:textSize="50dp"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/textView3"
android:textColor="#ff000000" />
<ImageView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:src="#mipmap/spiderman_1"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="-10dp" />
<ImageView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:src="#mipmap/hulk"
android:layout_marginTop="279dp"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtAdults"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_toEndOf="#+id/imageView4"
android:layout_marginTop="111dp"
android:textSize="30dp"
android:textColor="#ff000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtChildern"
android:id="#+id/textView4"
android:textSize="30dp"
android:layout_below="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_marginTop="20dp"
android:textColor="#ff000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/txtAdults"
android:layout_above="#+id/textView4"
android:layout_toEndOf="#+id/textView4"
android:layout_marginStart="45dp"
android:textColor="#ff000000"
android:hint="#string/txtHint1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/txtChildren"
android:layout_alignBottom="#+id/textView4"
android:layout_alignStart="#+id/txtAdults"
android:textColor="#ff000000"
android:hint="#string/txtHint2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtDays"
android:id="#+id/textView5"
android:textSize="30dp"
android:layout_below="#+id/textView4"
android:layout_alignStart="#+id/textView4"
android:layout_marginTop="20dp"
android:textColor="#ff000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/txtDays"
android:layout_alignTop="#+id/textView5"
android:layout_alignStart="#+id/txtChildren"
android:textColor="#ff000000"
android:hint="#string/txtHint3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtCalcLbl"
android:id="#+id/btnTotal"
android:layout_marginTop="57dp"
android:hint="#string/txtClickCalc"
android:textSize="20dp"
android:layout_alignTop="#+id/imageView4"
android:layout_toEndOf="#+id/textView4"
android:textColor="#ff000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/txtTotal"
android:id="#+id/txtResult"
android:layout_below="#+id/imageView3"
android:layout_alignStart="#+id/btnTotal"
android:textSize="30dp"
android:textColor="#ff000000" />
</RelativeLayout>

NullPointerException on a android Fragment

I’m trying to put some data into a bundle and transfer it to a fragment. But the log show me an error of NullPointerException in the fragment and I don't know what is the relation between the two.
The error code :
09-22 14:19:03.216 1918-1918/com.example.user.unchained E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.user.unchained, PID: 1918
java.lang.NullPointerException
at com.example.user.unchained.HeaderFragement.onCreate(HeaderFragement.java:85)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1481)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
The Fragment code :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
name = (TextView) getView().findViewById(R.id.nameH);
img = (ImageView) getView().findViewById(R.id.imageViewHeader);
Bundle infos = getArguments();
name.setText(infos.getString("Name"));
img.setImageBitmap(getBitmapFromURL(infos.getString("ImgUrl")));
//Name.setText(Name.getText()+" "+infos.getString("Name"));
}
The Activity in which i put data in the bundle.
protected void onPostExecute(final String res) {
//LoginTask = null;
//showProgress(false);
try {
jObj = new JSONObject(res);
} catch (JSONException e) {
e.printStackTrace();
}
try {
if (jObj.getString("code").equals("1")) {
infos = new Bundle();
infos.putString("ID",jObj.getString("ID"));
infos.putString("Name",jObj.getString("display_name"));
infos.putString("ImgUrl","http://unchained-network.com/uploads/profilpics/53f5c570b6ac2.png");
android.support.v4.app.FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
HeaderFragement hf = new HeaderFragement();
//Charger les infos dans l'activité
hf.setArguments(infos);
tr.replace(R.id.frgmnt, hf);
tr.commit();
Intent myIntent = new Intent(getActivity(), HomesActivity.class);
//Lançer l'activité
startActivityForResult(myIntent, 0);
} else {
//password.setError(getString(R.string.error_incorrect_password));
//password.requestFocus();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Error !");
builder.setMessage("The information entered is incorrect.\nPlease try again!")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
The layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical" >
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:visibility="gone"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/logo"
android:focusableInTouchMode="true"
android:src="#drawable/unchained_beta_logo"
android:layout_marginTop="20dp"
android:gravity="center"
android:contentDescription="Unchained-Network Logo"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
style="#style/SignInEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:completionThreshold="1"
android:inputType="textEmailAddress"
android:layout_marginTop="64dp"
android:layout_below="#+id/logo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/email"
android:hint="Email" />
<EditText
style="#style/SignInEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:completionThreshold="1"
android:inputType="textPassword"
android:layout_marginTop="20dp"
android:layout_below="#+id/email"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/password"
android:hint="Password" />
<Button
android:id="#+id/connexion"
style="#style/ShadowText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_below="#+id/password"
android:background="#color/green_android"
android:gravity="center"
android:padding="10dp"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"
android:text="Go Ride !"
/>
<TextView
android:layout_width="200dp"
android:id="#+id/passf"
style="#style/ShadowText"
android:layout_height="30dp"
android:layout_marginLeft="70dp"
android:text="Forgotten your password?"
android:layout_marginTop="20dp"
android:gravity="center"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="#feed01" />
<TextView
android:layout_width="200dp"
style="#style/ShadowText"
android:layout_height="30dp"
android:layout_marginLeft="70dp"
android:text="No account yet ? Get one "
android:layout_marginTop="5dp"
android:gravity="center"
android:id="#+id/newaccount"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#fff" />
</LinearLayout>
</ScrollView>
</LinearLayout>
onCreate() is too early to call getView() and it will return null. Postpone the code that needs to touch the fragment's view hierarchy to onCreateView() or later in the fragment lifecycle.
you should add your fragment container inside your main layout. then you will do that replacement using this layout
<LinearLayout
android:id="#+id/frgmnt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
change your layout with this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical" >
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:visibility="gone"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/logo"
android:focusableInTouchMode="true"
android:src="#drawable/unchained_beta_logo"
android:layout_marginTop="20dp"
android:gravity="center"
android:contentDescription="Unchained-Network Logo"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
style="#style/SignInEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:completionThreshold="1"
android:inputType="textEmailAddress"
android:layout_marginTop="64dp"
android:layout_below="#+id/logo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/email"
android:hint="Email" />
<EditText
style="#style/SignInEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:completionThreshold="1"
android:inputType="textPassword"
android:layout_marginTop="20dp"
android:layout_below="#+id/email"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/password"
android:hint="Password" />
<Button
android:id="#+id/connexion"
style="#style/ShadowText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_below="#+id/password"
android:background="#color/green_android"
android:gravity="center"
android:padding="10dp"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"
android:text="Go Ride !"
/>
<TextView
android:layout_width="200dp"
android:id="#+id/passf"
style="#style/ShadowText"
android:layout_height="30dp"
android:layout_marginLeft="70dp"
android:text="Forgotten your password?"
android:layout_marginTop="20dp"
android:gravity="center"
android:textSize="10sp"
android:textStyle="bold"
android:textColor="#feed01" />
<TextView
android:layout_width="200dp"
style="#style/ShadowText"
android:layout_height="30dp"
android:layout_marginLeft="70dp"
android:text="No account yet ? Get one "
android:layout_marginTop="5dp"
android:gravity="center"
android:id="#+id/newaccount"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#fff" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/frgmnt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>

Categories