问:
Run time error while compiling the app in android studio
When I run this App the Emulator shows that app is not running and we have a runtime error

This is my Main Activity

```<code>package com.mobility.mobilityindia;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button btnLogin;
    EditText input_email,input_password;
    TextView btnSignup,btnForgotPass;

    RelativeLayout activity_main;
    private FirebaseAuth auth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //view
        btnLogin=(Button)findViewById(R.id.login_button);
        input_email=(EditText)findViewById(R.id.login_email);
        input_password=(EditText)findViewById(R.id.login_password);
        btnSignup=(TextView)findViewById(R.id.sign_up);
        btnForgotPass=(TextView)findViewById(R.id.forgot_password);
        activity_main=(RelativeLayout)findViewById(R.id.activity_main);

        btnSignup.setOnClickListener(this);
        btnForgotPass.setOnClickListener(this);
        btnLogin.setOnClickListener(this);

        //Init Firebase Auth
        auth=FirebaseAuth.getInstance();

        //Check already session, if ok--->dashboard

        if(auth.getCurrentUser() !=null)
            startActivity(new Intent(MainActivity.this,dashboard.class));
    }

    @Override
    public void onClick(View view) {

        if(view.getId()==R.id.forgot_password)
        {
            startActivity(new Intent (MainActivity.this,Forgotpassword.class));
            finish();
        }
        else  if(view.getId()==R.id.sign_up)
        {
            startActivity(new Intent (MainActivity.this,Signup.class));
            finish();
        }
        else  if(view.getId()==R.id.login_button)
        {
            loginUser(input_email.getText().toString(),input_password.getText().toString());
        }
    }

    private void loginUser(String email,final String password) {
        auth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (!task.isSuccessful())
                        {
                            if (password.length() < 6)
                            {
                                Snackbar snackbar = Snackbar.make(activity_main, "Password should be more than 6 characters", Snackbar.LENGTH_SHORT);
                                snackbar.show();
                            }
                        }
                        else
                        {
                            startActivity(new Intent(MainActivity.this, dashboard.class));
                        }
                    }

                });

    }
}
</code>```

This is activity_main.xml

```<code> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="16dp"
    android:paddingTop="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:background="@drawable/login"
    tools:context="com.mobility.mobilityindia.MainActivity">

    <ImageView
            android:id="@+id/logo"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="10dp"
            app:srcCompat="@drawable/siemenslogo" />

    <android.support.design.widget.TextInputLayout
        android:layout_below="@+id/logo"
        android:id="@+id/login_input_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/login_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/edittext_background"
            android:hint="  Enter Email ID"
            android:inputType="textEmailAddress"
            android:maxLines="1" />

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout

        android:layout_below="@+id/login_input_email"
        android:id="@+id/login_input_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/login_password"
            android:background="@drawable/edittext_background"
            android:inputType="textPassword"
            android:visibility="visible"
            android:hint=" Enter Password"
            android:maxLines="1" />
    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/login_button"
        style="@style/Widget.AppCompat.Button.Colored"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_input_password"
        android:text="Sign In"
        android:textAllCaps="false" />

    <TextView
        android:id="@+id/forgot_password"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_button"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:clickable="true"
        android:text="Forgot Password ?"
        android:textColor="@android:color/background_light"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/login_layout_or"
        android:layout_below="@+id/forgot_password"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <view
            android:layout_width="200dp"
            android:layout_height="2dp"
            android:background="#FFDFDCDD"
            android:layout_margin="5dp" />

        <TextView
            android:padding="5dp"
            android:text="OR"
            android:textStyle="bold"
            android:textColor="#FFDFDCDD"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <view
            android:layout_width="200dp"
            android:layout_height="2dp"
            android:background="#FFDFDCDD"
            android:layout_margin="5dp" />

    </LinearLayout>

    <TextView
        android:id="@+id/sign_up"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_layout_or"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:clickable="true"
        android:text="Sign Up"
        android:textColor="@android:color/background_light"
        android:textStyle="bold" />
</RelativeLayout>
</code>```

The Relevant logcat details(according to me) are

```07-07 16:16:32.072 3443-3443/? I/zygote: Not late-enabling -Xcheck:jni (already on)
07-07 16:16:32.088 3443-3443/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
07-07 16:16:34.086 3443-3529/com.mobility.mobilityindia W/zygote: Verification of void com.google.android.gms.internal.zzbdd.zzqt() took 109.209ms
07-07 16:16:34.244 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 102.994ms
07-07 16:16:34.377 3443-3529/com.mobility.mobilityindia W/zygote: Verification of void com.google.android.gms.internal.zzbdd.zzqx() took 133.395ms
07-07 16:16:34.513 3443-3459/com.mobility.mobilityindia I/zygote: Background concurrent copying GC freed 20112(2MB) AllocSpace objects, 0(0B) LOS objects, 73% free, 542KB/2MB, paused 49.505ms total 82.869ms
07-07 16:16:34.531 3443-3459/com.mobility.mobilityindia W/zygote: Suspending all threads took: 10.382ms
07-07 16:16:34.572 3443-3443/com.mobility.mobilityindia I/FA: App measurement is starting up, version: 11020
07-07 16:16:34.572 3443-3443/com.mobility.mobilityindia I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-07 16:16:34.718 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 76.453ms
07-07 16:16:34.807 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
07-07 16:16:34.807 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Selected local version of com.google.android.gms.flags
07-07 16:16:34.837 3443-3529/com.mobility.mobilityindia W/zygote: Verification of int android.support.v4.util.ArrayMap$1.colGetSize() took 100.656ms
07-07 16:16:34.884 3443-3443/com.mobility.mobilityindia V/FA: Collection enabled
07-07 16:16:34.885 3443-3443/com.mobility.mobilityindia V/FA: App package, google app id: com.mobility.mobilityindia, 1:308094300316:android:8bb92942b462bf39
07-07 16:16:34.898 3443-3443/com.mobility.mobilityindia I/FA: To enable faster debug mode event logging run:
                                                                adb shell setprop debug.firebase.analytics.app com.mobility.mobilityindia
07-07 16:16:34.898 3443-3443/com.mobility.mobilityindia D/FA: Debug-level message logging enabled
07-07 16:16:35.021 3443-3568/com.mobility.mobilityindia W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
07-07 16:16:35.072 3443-3568/com.mobility.mobilityindia W/zygote: Skipping duplicate class check due to unrecognized classloader
07-07 16:16:35.120 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:4
07-07 16:16:35.120 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 4
07-07 16:16:35.218 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 74.292ms
07-07 16:16:35.271 3443-3568/com.mobility.mobilityindia W/zygote: Skipping duplicate class check due to unrecognized classloader
07-07 16:16:35.294 3443-3529/com.mobility.mobilityindia W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
07-07 16:16:35.304 3443-3443/com.mobility.mobilityindia V/FA: Cancelling job. JobID: -631849166
07-07 16:16:35.335 3443-3568/com.mobility.mobilityindia I/FirebaseCrashApiImpl: FirebaseCrashApiImpl created by ClassLoader p[DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/00000004/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000004/n/x86, /system/lib, /system/vendor/lib]]]
07-07 16:16:35.351 3443-3568/com.mobility.mobilityindia I/FirebaseCrash: FirebaseCrash reporting loaded - com.google.android.gms.internal.ml@c481c82
07-07 16:16:35.405 3443-3443/com.mobility.mobilityindia V/FA: Registered activity lifecycle callback
07-07 16:16:35.411 3443-3443/com.mobility.mobilityindia I/FirebaseInitProvider: FirebaseApp initialization successful
07-07 16:16:35.463 3443-3443/com.mobility.mobilityindia I/InstantRun: starting instant run server: is main process
07-07 16:16:35.649 3443-3569/com.mobility.mobilityindia I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
07-07 16:16:35.650 3443-3569/com.mobility.mobilityindia I/DynamiteModule: Selected local version of com.google.android.gms.flags
07-07 16:16:35.733 3443-3614/com.mobility.mobilityindia V/FA: Using measurement service
07-07 16:16:35.735 3443-3614/com.mobility.mobilityindia V/FA: Connecting to remote service
07-07 16:16:35.992 3443-3529/com.mobility.mobilityindia W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11020000 but found 10930470
07-07 16:16:35.994 3443-3614/com.mobility.mobilityindia W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11020000 but found 10930470
07-07 16:16:36.060 3443-3614/com.mobility.mobilityindia V/FA: Using measurement service
07-07 16:16:36.061 3443-3614/com.mobility.mobilityindia V/FA: Connection attempt already in progress
07-07 16:16:36.133 3443-3569/com.mobility.mobilityindia W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
07-07 16:16:36.781 3443-3443/com.mobility.mobilityindia V/FA: onActivityCreated
07-07 16:16:36.932 3443-3569/com.mobility.mobilityindia E/FirebaseCrash: Failed to initialize crash reporting: Can't create handler inside thread that has not called Looper.prepare()
07-07 16:16:36.940 3443-3570/com.mobility.mobilityindia E/FirebaseCrash: Failed waiting for crash api to load.
                                                                         java.lang.InterruptedException
                                                                             at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1063)
                                                                             at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1352)
                                                                             at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:278)
                                                                             at com.google.firebase.crash.FirebaseCrash.zzFc(Unknown Source:6)
                                                                             at com.google.firebase.crash.FirebaseCrash.zza(Unknown Source:0)
                                                                             at com.google.firebase.crash.zza.run(Unknown Source:2)
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                             at java.lang.Thread.run(Thread.java:764)
07-07 16:16:37.716 3443-3455/com.mobility.mobilityindia I/zygote: Waiting for a blocking GC ObjectsAllocated
07-07 16:16:37.725 3443-3443/com.mobility.mobilityindia I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
07-07 16:16:37.735 3443-3443/com.mobility.mobilityindia I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
07-07 16:16:37.753 3443-3443/com.mobility.mobilityindia D/AndroidRuntime: Shutting down VM
07-07 16:16:37.755 3443-3443/com.mobility.mobilityindia E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.mobility.mobilityindia, PID: 3443
                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobility.mobilityindia/com.mobility.mobilityindia.MainActivity}: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                              at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                           Caused by: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                              at com.mobility.mobilityindia.MainActivity.onCreate(MainActivity.java:33)
                                                                              at android.app.Activity.performCreate(Activity.java:6980)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                              at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-07 16:16:37.759 3443-3443/com.mobility.mobilityindia E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobility.mobilityindia/com.mobility.mobilityindia.MainActivity}: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                              Caused by: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                              Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                at com.mobility.mobilityindia.MainActivity.onCreate(MainActivity.java:33)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-07 16:16:37.823 3443-3459/com.mobility.mobilityindia I/zygote: NativeAllocBackground concurrent copying GC freed 5277(990KB) AllocSpace objects, 5(100KB) LOS objects, 55% free, 1239KB/2MB, paused 5.719ms total 310.202ms
07-07 16:16:37.824 3443-3455/com.mobility.mobilityindia I/zygote: WaitForGcToComplete blocked for 107.393ms for cause ObjectsAllocated
07-07 16:16:38.670 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 15.516ms
```

The line containing 'MainActivity.java:33' is blue in color

答:
Change

```<code><view
</code>```

to

```<code><View
</code>```

in both places

Body:
When I run this App the Emulator shows that app is not running and we have a runtime error

This is my Main Activity

package com.mobility.mobilityindia;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button btnLogin;
    EditText input_email,input_password;
    TextView btnSignup,btnForgotPass;

    RelativeLayout activity_main;
    private FirebaseAuth auth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //view
        btnLogin=(Button)findViewById(R.id.login_button);
        input_email=(EditText)findViewById(R.id.login_email);
        input_password=(EditText)findViewById(R.id.login_password);
        btnSignup=(TextView)findViewById(R.id.sign_up);
        btnForgotPass=(TextView)findViewById(R.id.forgot_password);
        activity_main=(RelativeLayout)findViewById(R.id.activity_main);

        btnSignup.setOnClickListener(this);
        btnForgotPass.setOnClickListener(this);
        btnLogin.setOnClickListener(this);

        //Init Firebase Auth
        auth=FirebaseAuth.getInstance();

        //Check already session, if ok--->dashboard

        if(auth.getCurrentUser() !=null)
            startActivity(new Intent(MainActivity.this,dashboard.class));
    }

    @Override
    public void onClick(View view) {

        if(view.getId()==R.id.forgot_password)
        {
            startActivity(new Intent (MainActivity.this,Forgotpassword.class));
            finish();
        }
        else  if(view.getId()==R.id.sign_up)
        {
            startActivity(new Intent (MainActivity.this,Signup.class));
            finish();
        }
        else  if(view.getId()==R.id.login_button)
        {
            loginUser(input_email.getText().toString(),input_password.getText().toString());
        }
    }

    private void loginUser(String email,final String password) {
        auth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (!task.isSuccessful())
                        {
                            if (password.length() < 6)
                            {
                                Snackbar snackbar = Snackbar.make(activity_main, "Password should be more than 6 characters", Snackbar.LENGTH_SHORT);
                                snackbar.show();
                            }
                        }
                        else
                        {
                            startActivity(new Intent(MainActivity.this, dashboard.class));
                        }
                    }

                });

    }
}

This is activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="16dp"
    android:paddingTop="16dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:background="@drawable/login"
    tools:context="com.mobility.mobilityindia.MainActivity">

    <ImageView
            android:id="@+id/logo"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="10dp"
            app:srcCompat="@drawable/siemenslogo" />

    <android.support.design.widget.TextInputLayout
        android:layout_below="@+id/logo"
        android:id="@+id/login_input_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/login_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/edittext_background"
            android:hint="  Enter Email ID"
            android:inputType="textEmailAddress"
            android:maxLines="1" />

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout

        android:layout_below="@+id/login_input_email"
        android:id="@+id/login_input_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/login_password"
            android:background="@drawable/edittext_background"
            android:inputType="textPassword"
            android:visibility="visible"
            android:hint=" Enter Password"
            android:maxLines="1" />
    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/login_button"
        style="@style/Widget.AppCompat.Button.Colored"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_input_password"
        android:text="Sign In"
        android:textAllCaps="false" />

    <TextView
        android:id="@+id/forgot_password"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_button"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:clickable="true"
        android:text="Forgot Password ?"
        android:textColor="@android:color/background_light"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/login_layout_or"
        android:layout_below="@+id/forgot_password"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <view
            android:layout_width="200dp"
            android:layout_height="2dp"
            android:background="#FFDFDCDD"
            android:layout_margin="5dp" />

        <TextView
            android:padding="5dp"
            android:text="OR"
            android:textStyle="bold"
            android:textColor="#FFDFDCDD"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <view
            android:layout_width="200dp"
            android:layout_height="2dp"
            android:background="#FFDFDCDD"
            android:layout_margin="5dp" />

    </LinearLayout>

    <TextView
        android:id="@+id/sign_up"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_layout_or"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:clickable="true"
        android:text="Sign Up"
        android:textColor="@android:color/background_light"
        android:textStyle="bold" />
</RelativeLayout>

The Relevant logcat details(according to me) are

07-07 16:16:32.072 3443-3443/? I/zygote: Not late-enabling -Xcheck:jni (already on)
07-07 16:16:32.088 3443-3443/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
07-07 16:16:34.086 3443-3529/com.mobility.mobilityindia W/zygote: Verification of void com.google.android.gms.internal.zzbdd.zzqt() took 109.209ms
07-07 16:16:34.244 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 102.994ms
07-07 16:16:34.377 3443-3529/com.mobility.mobilityindia W/zygote: Verification of void com.google.android.gms.internal.zzbdd.zzqx() took 133.395ms
07-07 16:16:34.513 3443-3459/com.mobility.mobilityindia I/zygote: Background concurrent copying GC freed 20112(2MB) AllocSpace objects, 0(0B) LOS objects, 73% free, 542KB/2MB, paused 49.505ms total 82.869ms
07-07 16:16:34.531 3443-3459/com.mobility.mobilityindia W/zygote: Suspending all threads took: 10.382ms
07-07 16:16:34.572 3443-3443/com.mobility.mobilityindia I/FA: App measurement is starting up, version: 11020
07-07 16:16:34.572 3443-3443/com.mobility.mobilityindia I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-07 16:16:34.718 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 76.453ms
07-07 16:16:34.807 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
07-07 16:16:34.807 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Selected local version of com.google.android.gms.flags
07-07 16:16:34.837 3443-3529/com.mobility.mobilityindia W/zygote: Verification of int android.support.v4.util.ArrayMap$1.colGetSize() took 100.656ms
07-07 16:16:34.884 3443-3443/com.mobility.mobilityindia V/FA: Collection enabled
07-07 16:16:34.885 3443-3443/com.mobility.mobilityindia V/FA: App package, google app id: com.mobility.mobilityindia, 1:308094300316:android:8bb92942b462bf39
07-07 16:16:34.898 3443-3443/com.mobility.mobilityindia I/FA: To enable faster debug mode event logging run:
                                                                adb shell setprop debug.firebase.analytics.app com.mobility.mobilityindia
07-07 16:16:34.898 3443-3443/com.mobility.mobilityindia D/FA: Debug-level message logging enabled
07-07 16:16:35.021 3443-3568/com.mobility.mobilityindia W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
07-07 16:16:35.072 3443-3568/com.mobility.mobilityindia W/zygote: Skipping duplicate class check due to unrecognized classloader
07-07 16:16:35.120 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:4
07-07 16:16:35.120 3443-3568/com.mobility.mobilityindia I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 4
07-07 16:16:35.218 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 74.292ms
07-07 16:16:35.271 3443-3568/com.mobility.mobilityindia W/zygote: Skipping duplicate class check due to unrecognized classloader
07-07 16:16:35.294 3443-3529/com.mobility.mobilityindia W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
07-07 16:16:35.304 3443-3443/com.mobility.mobilityindia V/FA: Cancelling job. JobID: -631849166
07-07 16:16:35.335 3443-3568/com.mobility.mobilityindia I/FirebaseCrashApiImpl: FirebaseCrashApiImpl created by ClassLoader p[DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/00000004/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/00000004/n/x86, /system/lib, /system/vendor/lib]]]
07-07 16:16:35.351 3443-3568/com.mobility.mobilityindia I/FirebaseCrash: FirebaseCrash reporting loaded - com.google.android.gms.internal.ml@c481c82
07-07 16:16:35.405 3443-3443/com.mobility.mobilityindia V/FA: Registered activity lifecycle callback
07-07 16:16:35.411 3443-3443/com.mobility.mobilityindia I/FirebaseInitProvider: FirebaseApp initialization successful
07-07 16:16:35.463 3443-3443/com.mobility.mobilityindia I/InstantRun: starting instant run server: is main process
07-07 16:16:35.649 3443-3569/com.mobility.mobilityindia I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
07-07 16:16:35.650 3443-3569/com.mobility.mobilityindia I/DynamiteModule: Selected local version of com.google.android.gms.flags
07-07 16:16:35.733 3443-3614/com.mobility.mobilityindia V/FA: Using measurement service
07-07 16:16:35.735 3443-3614/com.mobility.mobilityindia V/FA: Connecting to remote service
07-07 16:16:35.992 3443-3529/com.mobility.mobilityindia W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11020000 but found 10930470
07-07 16:16:35.994 3443-3614/com.mobility.mobilityindia W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11020000 but found 10930470
07-07 16:16:36.060 3443-3614/com.mobility.mobilityindia V/FA: Using measurement service
07-07 16:16:36.061 3443-3614/com.mobility.mobilityindia V/FA: Connection attempt already in progress
07-07 16:16:36.133 3443-3569/com.mobility.mobilityindia W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
07-07 16:16:36.781 3443-3443/com.mobility.mobilityindia V/FA: onActivityCreated
07-07 16:16:36.932 3443-3569/com.mobility.mobilityindia E/FirebaseCrash: Failed to initialize crash reporting: Can't create handler inside thread that has not called Looper.prepare()
07-07 16:16:36.940 3443-3570/com.mobility.mobilityindia E/FirebaseCrash: Failed waiting for crash api to load.
                                                                         java.lang.InterruptedException
                                                                             at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1063)
                                                                             at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1352)
                                                                             at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:278)
                                                                             at com.google.firebase.crash.FirebaseCrash.zzFc(Unknown Source:6)
                                                                             at com.google.firebase.crash.FirebaseCrash.zza(Unknown Source:0)
                                                                             at com.google.firebase.crash.zza.run(Unknown Source:2)
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                             at java.lang.Thread.run(Thread.java:764)
07-07 16:16:37.716 3443-3455/com.mobility.mobilityindia I/zygote: Waiting for a blocking GC ObjectsAllocated
07-07 16:16:37.725 3443-3443/com.mobility.mobilityindia I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
07-07 16:16:37.735 3443-3443/com.mobility.mobilityindia I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
07-07 16:16:37.753 3443-3443/com.mobility.mobilityindia D/AndroidRuntime: Shutting down VM
07-07 16:16:37.755 3443-3443/com.mobility.mobilityindia E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.mobility.mobilityindia, PID: 3443
                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobility.mobilityindia/com.mobility.mobilityindia.MainActivity}: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                              at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                           Caused by: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                           Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                              at com.mobility.mobilityindia.MainActivity.onCreate(MainActivity.java:33)
                                                                              at android.app.Activity.performCreate(Activity.java:6980)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                              at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-07 16:16:37.759 3443-3443/com.mobility.mobilityindia E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobility.mobilityindia/com.mobility.mobilityindia.MainActivity}: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                              Caused by: android.view.InflateException: Binary XML file line #91: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                              Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:767)
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                                                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:827)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                at com.mobility.mobilityindia.MainActivity.onCreate(MainActivity.java:33)
                                                                                at android.app.Activity.performCreate(Activity.java:6980)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                                at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                at android.os.Looper.loop(Looper.java:164)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-07 16:16:37.823 3443-3459/com.mobility.mobilityindia I/zygote: NativeAllocBackground concurrent copying GC freed 5277(990KB) AllocSpace objects, 5(100KB) LOS objects, 55% free, 1239KB/2MB, paused 5.719ms total 310.202ms
07-07 16:16:37.824 3443-3455/com.mobility.mobilityindia I/zygote: WaitForGcToComplete blocked for 107.393ms for cause ObjectsAllocated
07-07 16:16:38.670 3443-3455/com.mobility.mobilityindia W/zygote: Suspending all threads took: 15.516ms

The line containing 'MainActivity.java:33' is blue in color

Body:
Change

<view

to

<View

in both places


来源: stackexchange

问:
Listener not working on linearlayout which contain Edittext
I have an EditText contained in a LinearLayout. For My project I have set an OnclickListener on the LinearLayout. When I launch application nothing happened on click to layout. Maybe It due to the EditText but need that OnCliclistener to be work on LenearLayout.

MyCode:

XML

```<code><LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/lnlabelnameuniteholder"
        android:id="@+id/choix_decategorie"
        android:layout_marginTop="10dp" >

        <EditText
            android:text="@string/choix_de_categorie"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="italic"
            android:textSize="18sp"
            android:textColor="#000" />

    </LinearLayout>
</code>```

CODE

```<code>    maCategorie = (LinearLayout) findViewById(R.id.choix_decategorie);

           maCategorie.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            MyDB db = new MyDB(MyActivityCategorie.this);
            ArrayList<Category> categoryList = db.getCategory();

            ChoiceCategoryDialog categoryDialog = new ChoiceCategoryDialog(MyActivityCategorie.this, R.string.add_category, mCategoryTextView.getText().toString(), categoryList, MyActivityCategorie.this, true);
            categoryDialog.show();
        }
    });
</code>```

Thanks

答: your click listener will work but your edit text hide the linear layout , if you remove the edit text it will work  or you can set height and width not equal to linear layout.</p>

ContentLicense: CC BY-SA 3.0

Body:
I have an EditText contained in a LinearLayout. For My project I have set an OnclickListener on the LinearLayout. When I launch application nothing happened on click to layout. Maybe It due to the EditText but need that OnCliclistener to be work on LenearLayout.

MyCode:

XML

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/lnlabelnameuniteholder"
        android:id="@+id/choix_decategorie"
        android:layout_marginTop="10dp" >

        <EditText
            android:text="@string/choix_de_categorie"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="italic"
            android:textSize="18sp"
            android:textColor="#000" />

    </LinearLayout>

CODE

    maCategorie = (LinearLayout) findViewById(R.id.choix_decategorie);

           maCategorie.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            MyDB db = new MyDB(MyActivityCategorie.this);
            ArrayList<Category> categoryList = db.getCategory();

            ChoiceCategoryDialog categoryDialog = new ChoiceCategoryDialog(MyActivityCategorie.this, R.string.add_category, mCategoryTextView.getText().toString(), categoryList, MyActivityCategorie.this, true);
            categoryDialog.show();
        }
    });

Thanks


问:
Why am I required to provide two option arguments when I only declared one option parameter?
Why am I required to provide two option arguments when I only declared one option parameter?

I declared the following type:

```<code>type MiddleName =    MiddleName of string option
</code>```

To make the compiler happy I have to provide the Some case value twice:

```<code>let middleName = Some <| MiddleName (Some "Kevin")
</code>```

Note: I expect to provide the Some case value only once.

Hence, I thought I should do this:

```<code>let middleName = MiddleName (Some "Kevin")
</code>```

Am I even doing this right?
Hence, a middle name should be optional and as a result, I am trying to model that.

Appendix:

```<code>type FirstName =     FirstName  of string
type LastName  =     LastName   of string
type MiddleName =    MiddleName of string option
type MaidenName =    MaidenName of string option
type Email =         Email      of string
type Phone =         Phone      of string

type Name = {
    FirstName:FirstName
    LastName:LastName
    MiddleName:MiddleName option
    MaidenName:MaidenName option
}

let someName = {
    FirstName=FirstName "Scott"
    LastName= LastName "Nimrod"
    MiddleName = Some <| MiddleName (Some "Kevin")
    MaidenName = None
</code>```

}

答:
You've declared a MiddleName type is an optional string, but you've also declared your MiddleName member as optional itself. So you have an optional MiddleName that contains an optional string.

One of those optional suffixes is not required. Note this also applies for MaidenName too.

You can either remove the option from the members like this (see this fiddle):

```<code>type Name =
    { FirstName : FirstName
      LastName : LastName
      MiddleName : MiddleName
      MaidenName : MaidenName }

let someName =
    { FirstName = FirstName "Scott"
      LastName = LastName "Nimrod"
      MiddleName = MiddleName (Some "Kevin")
      MaidenName = MaidenName None }
</code>```

Or from the MiddleName / MaidenName types like this (see this fiddle):

```<code>type MiddleName = MiddleName of string
type MaidenName = MaidenName of string

type Name =
    { FirstName : FirstName
      LastName : LastName
      MiddleName : MiddleName option
      MaidenName : MaidenName option }

let someName =
    { FirstName = FirstName "Scott"
      LastName = LastName "Nimrod"
      MiddleName = Some (MiddleName "Kevin")
      MaidenName = None }
</code>```

Body:
Why am I required to provide two option arguments when I only declared one option parameter?

I declared the following type:

type MiddleName =    MiddleName of string option

To make the compiler happy I have to provide the Some case value twice:

let middleName = Some <| MiddleName (Some "Kevin")

Note: I expect to provide the Some case value only once.

Hence, I thought I should do this:

let middleName = MiddleName (Some "Kevin")

Am I even doing this right?
Hence, a middle name should be optional and as a result, I am trying to model that.

Appendix:

type FirstName =     FirstName  of string
type LastName  =     LastName   of string
type MiddleName =    MiddleName of string option
type MaidenName =    MaidenName of string option
type Email =         Email      of string
type Phone =         Phone      of string

type Name = {
    FirstName:FirstName
    LastName:LastName
    MiddleName:MiddleName option
    MaidenName:MaidenName option
}

let someName = {
    FirstName=FirstName "Scott"
    LastName= LastName "Nimrod"
    MiddleName = Some <| MiddleName (Some "Kevin")
    MaidenName = None

}

Body:
You've declared a MiddleName type is an optional string, but you've also declared your MiddleName member as optional itself. So you have an optional MiddleName that contains an optional string.

One of those optional suffixes is not required. Note this also applies for MaidenName too.

You can either remove the option from the members like this (see this fiddle):

type Name =
    { FirstName : FirstName
      LastName : LastName
      MiddleName : MiddleName
      MaidenName : MaidenName }

let someName =
    { FirstName = FirstName "Scott"
      LastName = LastName "Nimrod"
      MiddleName = MiddleName (Some "Kevin")
      MaidenName = MaidenName None }

Or from the MiddleName / MaidenName types like this (see this fiddle):

type MiddleName = MiddleName of string
type MaidenName = MaidenName of string

type Name =
    { FirstName : FirstName
      LastName : LastName
      MiddleName : MiddleName option
      MaidenName : MaidenName option }

let someName =
    { FirstName = FirstName "Scott"
      LastName = LastName "Nimrod"
      MiddleName = Some (MiddleName "Kevin")
      MaidenName = None }


问:
A short javascript to keep scrolling to the top of page until the end?
I'm using web interface of telegram (a IM like whatsapp) so I want to view some message which is on top of page and I want to scroll but there are like 15000 lines and i dont want to keep pressing pageup so is there a java script which i could execute in console to reach to the top??</p>

答:
Just run the following in browser console:

```<code>window.scrollTo(0,0);
</code>```

div {
height: 800px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div>
scroll down to see the button
</div>
<button onclick="window.scrollTo(0,0)">scroll to Top</button></code>```

Body:
Just run the following in browser console:

window.scrollTo(0,0);

div {
height: 800px;
}

<div>
scroll down to see the button
</div>
<button onclick="window.scrollTo(0,0)">scroll to Top</button>


问:
Side loading instant app failed: Reading bundle timed out
Unable to use Android Emulator, for testing the Instant Apps!! Every-time I'm getting "Side loading instant app failed: Reading bundle timed out."

I'm using, Android Studio 3.0 Canary-5

Emulator: Nexus 5X image running Android 6.0 (API level 23), x86, with Google APIs. Google APIs Intel x86 Atom System Image (Revision 21)

Note: After updating Android Studio 3.0 (Canary-4 > Canary-5) &
  Emulator system image from revision (20 > 21). I'm unable to run the
  instant App through emulator. Always I'm getting the error message saying "Side loading instant app failed: Reading bundle timed out."

```<code>com.google.android.gms.persistent E/InstantApps: DomainFilterImpl: Error while reading domain filter from WHAPI
                                                                              java.util.concurrent.ExecutionException: awjr: INVALID_ARGUMENT: Application credential header not valid. Please fix the client to pass a valid application credential header.
                                                                                at java.util.concurrent.FutureTask.report(FutureTask.java:94)
                                                                                at java.util.concurrent.FutureTask.get(FutureTask.java:164)
                                                                                at tey.get(:com.google.android.gms:1)
                                                                                at tir.a(:com.google.android.gms:25)
                                                                                at tir.a(:com.google.android.gms:16)
                                                                                at tir.a(:com.google.android.gms:9)
                                                                                at tir.b(:com.google.android.gms:0)
                                                                                at tio.b(:com.google.android.gms:0)
                                                                                at com.google.android.gms.instantapps.routing.DomainFilterUpdateChimeraService.a(:com.google.android.gms:14)
                                                                                at tiu.run(:com.google.android.gms:0)
                                                                                at lhb.run(:com.google.android.gms:24)
                                                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                at lmc.run(:com.google.android.gms:0)
                                                                                at java.lang.Thread.run(Thread.java:818)
                                                                               Caused by: awjr: INVALID_ARGUMENT: Application credential header not valid. Please fix the client to pass a valid application credential header.
                                                                                at awjn.c(:com.google.android.gms:0)
                                                                                at lbb.a(:com.google.android.gms:97)
                                                                                at tem.b(:com.google.android.gms:43)
                                                                                at tem.a(:com.google.android.gms:0)
                                                                                at tez.call(:com.google.android.gms:1)
                                                                                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                at lhb.run(:com.google.android.gms:24)
                                                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                at lmc.run(:com.google.android.gms:0)
                                                                                at java.lang.Thread.run(Thread.java:818)

    W/ActivityManager: Unable to start service Intent { act=com.google.android.instantapps.devman.iapk.LOAD cmp=com.google.android.instantapps.devman/.iapk.IapkLoadService (has extras) } U=0: not found
</code>```

Appreciate your help.

Update:

Found solution in Android studio release notes here. This is a known-issue under Android Studio canary-5.

Reliability issue with instant app provisioning cache. If you manually
  unprovision your device or emulator image for instant app development,
  and then deploy the instant app from Android Studio, the deployment
  will fail because Android Studio will not provision your
  device/emulator image again. To workaround for this issue: Go into the
  Run Configuration dialog and select the instantapp module on the
  left-hand pane. Click the “Instant App Provision” task under “Before
  launch:Gradle-aware Make, Instant App Provision” Click the edit (the
  pencil icon) Check “Clear provisioned devices cache”

答:
The device is being considered as "already provisioned for instant apps" but it's not, probably because another device with the same serial number (same emulator) was used before and modified or because the device was modified externally (not by Android Studio).

A workaround for that is to clear the cache before each run:
InstantApp run configuration -> before run tasks -> provision for instant app task -> edit -> clear provisioned devices cache.

Body:
Unable to use Android Emulator, for testing the Instant Apps!! Every-time I'm getting "Side loading instant app failed: Reading bundle timed out."

I'm using, Android Studio 3.0 Canary-5

Emulator: Nexus 5X image running Android 6.0 (API level 23), x86, with Google APIs. Google APIs Intel x86 Atom System Image (Revision 21)

Note: After updating Android Studio 3.0 (Canary-4 > Canary-5) &
  Emulator system image from revision (20 > 21). I'm unable to run the
  instant App through emulator. Always I'm getting the error message saying "Side loading instant app failed: Reading bundle timed out."

com.google.android.gms.persistent E/InstantApps: DomainFilterImpl: Error while reading domain filter from WHAPI
                                                                              java.util.concurrent.ExecutionException: awjr: INVALID_ARGUMENT: Application credential header not valid. Please fix the client to pass a valid application credential header.
                                                                                at java.util.concurrent.FutureTask.report(FutureTask.java:94)
                                                                                at java.util.concurrent.FutureTask.get(FutureTask.java:164)
                                                                                at tey.get(:com.google.android.gms:1)
                                                                                at tir.a(:com.google.android.gms:25)
                                                                                at tir.a(:com.google.android.gms:16)
                                                                                at tir.a(:com.google.android.gms:9)
                                                                                at tir.b(:com.google.android.gms:0)
                                                                                at tio.b(:com.google.android.gms:0)
                                                                                at com.google.android.gms.instantapps.routing.DomainFilterUpdateChimeraService.a(:com.google.android.gms:14)
                                                                                at tiu.run(:com.google.android.gms:0)
                                                                                at lhb.run(:com.google.android.gms:24)
                                                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                at lmc.run(:com.google.android.gms:0)
                                                                                at java.lang.Thread.run(Thread.java:818)
                                                                               Caused by: awjr: INVALID_ARGUMENT: Application credential header not valid. Please fix the client to pass a valid application credential header.
                                                                                at awjn.c(:com.google.android.gms:0)
                                                                                at lbb.a(:com.google.android.gms:97)
                                                                                at tem.b(:com.google.android.gms:43)
                                                                                at tem.a(:com.google.android.gms:0)
                                                                                at tez.call(:com.google.android.gms:1)
                                                                                at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                at lhb.run(:com.google.android.gms:24)
                                                                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                at lmc.run(:com.google.android.gms:0)
                                                                                at java.lang.Thread.run(Thread.java:818)

    W/ActivityManager: Unable to start service Intent { act=com.google.android.instantapps.devman.iapk.LOAD cmp=com.google.android.instantapps.devman/.iapk.IapkLoadService (has extras) } U=0: not found

Appreciate your help.

Update:

Found solution in Android studio release notes here. This is a known-issue under Android Studio canary-5.

Reliability issue with instant app provisioning cache. If you manually
  unprovision your device or emulator image for instant app development,
  and then deploy the instant app from Android Studio, the deployment
  will fail because Android Studio will not provision your
  device/emulator image again. To workaround for this issue: Go into the
  Run Configuration dialog and select the instantapp module on the
  left-hand pane. Click the “Instant App Provision” task under “Before
  launch:Gradle-aware Make, Instant App Provision” Click the edit (the
  pencil icon) Check “Clear provisioned devices cache”


问:
Forkjoin with empty (or not) array of observables
I'm trying to detect when all my observables have completed. I have the following Observables:

let observables:any[] = [];
if(valid){
    observables.push(new Observable((observer:any) => {
        async(()=>{
            observer.next();
            observer.complete();
        })
    }))
}
if(confirmed){
    observables.push(new Observable((observer:any) => {
        async(()=>{
            observer.next();
            observer.complete();
        })
    }))
}

Observable.forkJoin(observables).subscribe(
    data => {
        console.log('all completed');
    },
    error => {
        console.log(error);
    }
);
```

I need to do something whenever all my functions are completed. Forkjoin seems to work when the observables array is not empty. But when the array is empty, it never gets called. How can I solve this?

答:
You're missing complete callback. You can pass the third argument or pass an observer object instead of 3 arguments to make event checking more readable.

yourObservable.subscribe({
  next: value => console.log(value),
  error: error => console.log(error),
  complete: () => console.log('complete'),
});
```

Body:
I'm trying to detect when all my observables have completed. I have the following Observables:

let observables:any[] = [];
if(valid){
    observables.push(new Observable((observer:any) => {
        async(()=>{
            observer.next();
            observer.complete();
        })
    }))
}
if(confirmed){
    observables.push(new Observable((observer:any) => {
        async(()=>{
            observer.next();
            observer.complete();
        })
    }))
}

Observable.forkJoin(observables).subscribe(
    data => {
        console.log('all completed');
    },
    error => {
        console.log(error);
    }
);

I need to do something whenever all my functions are completed. Forkjoin seems to work when the observables array is not empty. But when the array is empty, it never gets called. How can I solve this?


问:
Single endpoint for Elasticsearch
So, We have created a elasticsearch cluster ourselves using EC2 instances. The cluster works perfectly fine.

We have a total of 3 nodes of which 1 is master, 1 is data node and 1 is master + data node.

So currently, Route53 points to the only master node. What happens when the master node fails for some reason? How do i reroute it to the second master node until the failed node is back in place?

Need some inputs here. How is this achieved?

答: Are you using any programming language in front? If so you can use the elasticsearh library for that programming language can handle that for you and you just have to add all your addresses while creating the client. When you refer to the client it will use the master node for querying . So even if one fails the other server will become master and your client will refer to the new master.</p>

Title: Single endpoint for Elasticsearch


问:
should this example not alter the memory address rather than the value at that memory address?
In a book I am reading, C++ from scratch, on page 113 the writer creates a char array:

```<code>myString[80];
</code>```

then he uses a function that copies some charectars:

```<code>strcpy(myString,"Hello there");
</code>```

then he creates a pointer to the array:

```<code>*p1 = myString;
</code>```

then he uses an offset and assings a value at that offset:

```<code>p1[4]='c';
</code>```

my question is, p1 is a pointer so it is a memory address, and the offset of 4 gives him the memory address 4 spaces in front, so that means he is assingning the letter 'c' to the memory address rather than at the value stored at that address. Shouldnt it be:

```<code>*(p1[4])='c';
</code>```

basically, how come *(p1 + 4) needs dereferencing but p1[4] does not?

I tried to understand this and the only thing that could make sense to me was if the square brackets act as an asterisk to dereference the pointer. Is this correct or is there another reason why p1[4] does not need to be dereferenced?

答:
then he creates a pointer to the array:

```<code>*p1 = myString;
</code>```

Assuming, by this, you actually mean that p1 is declared and initialised using;

```<code>char *p1 = myString;
</code>```

then your interpretation is wrong.   p1 is a pointer to a char not a pointer to an array.

In this definition, myString is the (previously declared in your question) name of an array of char.   In the initialisation

```<code>char *p1 = myString;
</code>```

the name myString is converted to a pointer.  That pointer will have the value &myString[0] (i.e. the address of the first character in myString).   That is the value that p1 will receive.

The statement

```<code> p1[4] = 'c';
</code>```

will then set the fifth character (since indexing is zero based) of myString to be 'c'.   The result is therefore changing myString[4] to the value 'c'.   This means that (the first 11 characters of) myString will be "Hellc there".

Assuming the above, the expression *(p1[4])='c' will not compile, since (p1[4]) is of type char, and cannot be dereferenced using the * operator.

Semantically, in an expression p1[4] is equivalent to *(p1 + 4).   Since p1 is initialised to be equal to &myString[0], p1[4] is ALSO equivalent to both myString[4] and to *(myString + 4).

Note: If *(p1[4])='c' was valid in your code, then p1[4] = 'c' would not be valid, which suggests my assumption about the declaration and initialisation of p1 is correct - despite the fact you have omitted such information.

Body:
In a book I am reading, C++ from scratch, on page 113 the writer creates a char array:

myString[80];

then he uses a function that copies some charectars:

strcpy(myString,"Hello there");

then he creates a pointer to the array:

*p1 = myString;

then he uses an offset and assings a value at that offset:

p1[4]='c';

my question is, p1 is a pointer so it is a memory address, and the offset of 4 gives him the memory address 4 spaces in front, so that means he is assingning the letter 'c' to the memory address rather than at the value stored at that address. Shouldnt it be:

*(p1[4])='c';

basically, how come *(p1 + 4) needs dereferencing but p1[4] does not?

I tried to understand this and the only thing that could make sense to me was if the square brackets act as an asterisk to dereference the pointer. Is this correct or is there another reason why p1[4] does not need to be dereferenced?

Body:
then he creates a pointer to the array:

*p1 = myString;

Assuming, by this, you actually mean that p1 is declared and initialised using;

char *p1 = myString;

then your interpretation is wrong.   p1 is a pointer to a char not a pointer to an array.

In this definition, myString is the (previously declared in your question) name of an array of char.   In the initialisation

char *p1 = myString;

the name myString is converted to a pointer.  That pointer will have the value &myString[0] (i.e. the address of the first character in myString).   That is the value that p1 will receive.

The statement

 p1[4] = 'c';

will then set the fifth character (since indexing is zero based) of myString to be 'c'.   The result is therefore changing myString[4] to the value 'c'.   This means that (the first 11 characters of) myString will be "Hellc there".

Assuming the above, the expression *(p1[4])='c' will not compile, since (p1[4]) is of type char, and cannot be dereferenced using the * operator.

Semantically, in an expression p1[4] is equivalent to *(p1 + 4).   Since p1 is initialised to be equal to &myString[0], p1[4] is ALSO equivalent to both myString[4] and to *(myString + 4).

Note: If *(p1[4])='c' was valid in your code, then p1[4] = 'c' would not be valid, which suggests my assumption about the declaration and initialisation of p1 is correct - despite the fact you have omitted such information.


问:
Using Cloud Stream Test does not work
I tried some stuff with spring-cloud-stream. Everything works and now I tried to write some test cases. Unfortunately they are not working. I reduced everything to the following (Everything is in the same boot app):

The Sender:

```<code>@EnableBinding(Sender.Emitter.class)
public class Sender {

    public interface Emitter {
        String CHANNEL = "emitter";
        @Output(CHANNEL)
        MessageChannel events();
    }
    private Emitter emitter;

    public Sender(Emitter emitter) {
        this.emitter = emitter;
    }

    public void sendMessage(String massage) {
        emitter.events().send(MessageBuilder.withPayload(massage).build());
    }
}
</code>```

The Receiver:

```<code>@EnableBinding(Receiver.Subscriber.class)
public class Receiver {
    public interface Subscriber {
        String CHANNEL = "subscriber";
        @Input(CHANNEL)
        SubscribableChannel events();
    }
    private String lastMessage;

    public String getLastMessage() {
        return lastMessage;
    }

    @StreamListener(Subscriber.CHANNEL)
    public void event(String message) {
        this.lastMessage = message;
    }
}
</code>```

My config:

```<code>spring:
  cloud:
    stream:
      default-binder: rabbit
      bindings:
        emitter:
          destination: testtock
          content-type: application/json
        subscriber:
          destination: testtock
</code>```

The Test:

```<code>@RunWith(SpringRunner.class)
@SpringBootTest
public class BasicTest {

    @Autowired
    private Receiver receiver;
    @Autowired
    private Sender sender;

    @Test
    public void test() throws InterruptedException {
        String massage = UUID.randomUUID().toString();
        sender.sendMessage(massage);
        //Thread.sleep(1000);
        assertEquals(massage, receiver.getLastMessage());
    }
}
</code>```

I want use spring-cloud-stream-test-support for testing to not need a AMQP message broker. Outside of testing I use a rabbitmq, there everything is working.
Maybe the spring-cloud-stream-test-support does not really route messages? Or what is the Problem here?

答:
The spring-cloud-stream-test-support provides an ability to test individual Spring Cloud Stream application and uses TestSupportBinder. Hence, this is not meant for end-to-end integration testing like the one you are using above.

For more information on using spring-cloud-stream-test-support and the TestSupportBinder, you can refer the doc here

Title: Using Cloud Stream Test does not work

Body:
I tried some stuff with spring-cloud-stream. Everything works and now I tried to write some test cases. Unfortunately they are not working. I reduced everything to the following (Everything is in the same boot app):

The Sender:

@EnableBinding(Sender.Emitter.class)
public class Sender {

    public interface Emitter {
        String CHANNEL = "emitter";
        @Output(CHANNEL)
        MessageChannel events();
    }
    private Emitter emitter;

    public Sender(Emitter emitter) {
        this.emitter = emitter;
    }

    public void sendMessage(String massage) {
        emitter.events().send(MessageBuilder.withPayload(massage).build());
    }
}

The Receiver:

@EnableBinding(Receiver.Subscriber.class)
public class Receiver {
    public interface Subscriber {
        String CHANNEL = "subscriber";
        @Input(CHANNEL)
        SubscribableChannel events();
    }
    private String lastMessage;

    public String getLastMessage() {
        return lastMessage;
    }

    @StreamListener(Subscriber.CHANNEL)
    public void event(String message) {
        this.lastMessage = message;
    }
}

My config:

spring:
  cloud:
    stream:
      default-binder: rabbit
      bindings:
        emitter:
          destination: testtock
          content-type: application/json
        subscriber:
          destination: testtock

The Test:

@RunWith(SpringRunner.class)
@SpringBootTest
public class BasicTest {

    @Autowired
    private Receiver receiver;
    @Autowired
    private Sender sender;

    @Test
    public void test() throws InterruptedException {
        String massage = UUID.randomUUID().toString();
        sender.sendMessage(massage);
        //Thread.sleep(1000);
        assertEquals(massage, receiver.getLastMessage());
    }
}

I want use spring-cloud-stream-test-support for testing to not need a AMQP message broker. Outside of testing I use a rabbitmq, there everything is working.
Maybe the spring-cloud-stream-test-support does not really route messages? Or what is the Problem here?


问:
Can RxJava and RxJava 2 coexist in the same Android project?
I have a project that uses RxJava 1. Now I'm building a module component, and thinking of starting with RxJava 2.

When perform gradle sync, all good. However during compilation I got the following error

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForProductionDebug'.
  com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
      File1: /Users/user.name/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.2.5/b423532b5a3c949cbb799468f83bf566032fe98d/rxjava-1.2.5.jar
      File2: /Users/user.name/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar

Is there anyway I could have them coexist in a single project (but different library), or this is a definitely no-no?

i.e. on one, I have

```<code>compile 'io.reactivex:rxjava:1.2.5'
compile 'io.reactivex:rxandroid:1.2.1'
</code>```

on the other one I have

```<code>compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
</code>```

答:
So regarding to this documentation they can co-exist theoretically, because the classes are located in different packages.

The error message you face is probably just caused by the android packaging into an apk, which tries to import both libraries and found a file that exists in both libs (have a look at this issue).

You can ignore that file by adding the following into the "android" block of your build.gradle:

```<code>android {
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    ...
}
</code>```

However, be sure to properly test your project after that change.

Body:
I have a project that uses RxJava 1. Now I'm building a module component, and thinking of starting with RxJava 2.

When perform gradle sync, all good. However during compilation I got the following error

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForProductionDebug'.
  com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
      File1: /Users/user.name/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.2.5/b423532b5a3c949cbb799468f83bf566032fe98d/rxjava-1.2.5.jar
      File2: /Users/user.name/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar

Is there anyway I could have them coexist in a single project (but different library), or this is a definitely no-no?

i.e. on one, I have

compile 'io.reactivex:rxjava:1.2.5'
compile 'io.reactivex:rxandroid:1.2.1'

on the other one I have

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

Body:
So regarding to this documentation they can co-exist theoretically, because the classes are located in different packages.

The error message you face is probably just caused by the android packaging into an apk, which tries to import both libraries and found a file that exists in both libs (have a look at this issue).

You can ignore that file by adding the following into the "android" block of your build.gradle:

android {
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    ...
}

However, be sure to properly test your project after that change.


问:
get half value of buffer java
I wouldike to get value from my buffer until half values :

```<code>public void run() {
                byte[] buffer = new byte[1048576]; // 20 bits
                int bytes;
                String strRx = "";

                while (running) {
                    try {
                        bytes = connectedInputStream.read(buffer);
                        final String strReceived_freq = new String(buffer,0, buffer/2); // buffer/2 not working
                        final String strReceived_pxx = new String(buffer,buffer/2, bytes); // buffer/2 not working
                        //final int samples_sdr=new Integer(buffer,0,bytes);
                        final String strByteCnt = String.valueOf(bytes) + " bytes received.\n";
</code>```

The problem, buffer/2 is not working, how can I do that for get half values from my buffer ?

Thanks for your help !

答:
```<code>public void run() {
   byte[] buffer = new byte[1048576]; // 20 bits
   int bytes = 0;
   String strRx = "";
   while (running) {
      try {
         bytes = connectedInputStream.read(buffer);
         if(bytes == 0) {
            Log.d("DEBUG","connectedInputStream returned 0 bytes");
         }
         byte[] strReceived_freq_byte = new byte[(buffer.length)/2];
         for(int i = 0; i < (buffer.length)/2; i++) {
            strReceived_freq_byte[i] = buffer[i];
         }
         byte[] strReceived_pxx_byte = new byte[(buffer.length)/2];
         for(int i =0 ; i < (buffer.length)/2; i++) {
            strReceived_freq_byte[i] = buffer[i+((buffer.length)/2)];
         }
     String strReceived_freq = new String(strReceived_freq_byte);
     String strReceived_pxx = new String(strReceived_pxx_byte);
     final String strByteCnt = String.valueOf(bytes) + " bytes received.\n";
      }
   }
}
</code>```

Title: get half value of buffer java

Body:
I wouldike to get value from my buffer until half values :

public void run() {
                byte[] buffer = new byte[1048576]; // 20 bits
                int bytes;
                String strRx = "";

                while (running) {
                    try {
                        bytes = connectedInputStream.read(buffer);
                        final String strReceived_freq = new String(buffer,0, buffer/2); // buffer/2 not working
                        final String strReceived_pxx = new String(buffer,buffer/2, bytes); // buffer/2 not working
                        //final int samples_sdr=new Integer(buffer,0,bytes);
                        final String strByteCnt = String.valueOf(bytes) + " bytes received.\n";

The problem, buffer/2 is not working, how can I do that for get half values from my buffer ?

Thanks for your help !