问:
Android Adapter only fetching the last entered data
I tried looking around but cant seem to find an answer that could resolve it.
Here is the process of what I'm doing:

1: Users enter data in a alert dialog

2: Data get sent into sql.

3: Adapter runs, takes data and put into a cardview.

4: Cardview is displayed(Stacks according to number of inputs made).

What that is not working to plan, the data that is being outputted overrides all previous inputs,and updates all cardviews with the latest information.

EG: Input 1: Test 1, Input 2: Test 2. Output will be 2 cardviews of Test 2.

Contact Activity

```<code>import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.sp.R;

public class Contacts extends AppCompatActivity {

    private Button newContact;
    private AlertDialog.Builder builder;
    private AlertDialog dialog;
    private RecyclerView recyclerView;

    private ContactDatabaseHelper helper;
    private ContactAdapter mAdapter;

    private EditText new_contact_name;
    private EditText new_contact_number;
    private EditText new_contact_relation;
    private Button button_create_contact;
    private Button button_cancel_create;

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

        helper = new ContactDatabaseHelper(this);

        recyclerView = findViewById(R.id.contact_recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new ContactAdapter(this,getAllItems());
        recyclerView.setAdapter(mAdapter);

        newContact = findViewById(R.id.contact_button);
        // New Contact Button
        newContact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                builder = new AlertDialog.Builder(Contacts.this);
                builder.setTitle("Create New Contact");
                builder.setCancelable(false);
                View view = LayoutInflater.from(Contacts.this).inflate(R.layout.new_contact_dialog,null,false);
                CreateDialog(view);
                builder.setView(view);
                dialog = builder.create();
                dialog.show();
            }
        });

    }

    private void CreateDialog(View view) {

        // ContactDialog ID's
        new_contact_name = view.findViewById(R.id.new_contact_name);
        new_contact_number = view.findViewById(R.id.new_contact_number);
        new_contact_relation = view.findViewById(R.id.new_contact_relation);
        button_create_contact = view.findViewById(R.id.button_create_contact);
        button_cancel_create = view.findViewById(R.id.button_cancel_create);

        button_create_contact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                        // Get String of Name, Number, Relationship
                        String contactNameStr = new_contact_name.getText().toString();
                        String contactNumberStr = new_contact_number.getText().toString();
                        String contactRelationStr = new_contact_relation.getText().toString();

                        // Insert into ContactTable
                        helper.insertContactDatabase(contactNameStr,contactNumberStr,contactRelationStr);
                        mAdapter.swapCursor(getAllItems());

                        // Outputs a Toast
                        Toast.makeText(Contacts.this, "Contact Created", Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
            }
        });

        button_cancel_create.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

    }

    private Cursor getAllItems(){
        return helper.getContactDatabase();
    }

}
</code>```

Contact Adapter

```<code>import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.sp.R;

public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.MyHolder>{

    private Context mContext;
    private Cursor c;
    private ContactDatabaseHelper helper;

    public ContactAdapter(Context context,Cursor cursor) {

        mContext = context;
        c = cursor;
        helper = new ContactDatabaseHelper(mContext);
    }

    public static class MyHolder extends RecyclerView.ViewHolder{

        private TextView contact_name;
        private TextView contact_number;
        private TextView contact_relation;

        public MyHolder(View itemView) {
            super(itemView);

            contact_name = itemView.findViewById(R.id.contact_list_name_item);
            contact_number = itemView.findViewById(R.id.contact_list_number_item);
            contact_relation = itemView.findViewById(R.id.contact_list_relation_item);
        }
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.contact_list,parent,false);

        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {

        c.moveToFirst();

        holder.contact_name.setText(helper.getContactName(c));
        holder.contact_number.setText(helper.getContactNumber(c));
        holder.contact_relation.setText(helper.getContactRelation(c));

    }

    @Override
    public int getItemCount() {

        return c.getCount();
    }

    public void swapCursor(Cursor newCursor){
        if (c != null){
            c.close();
        }

        c = newCursor;

        if (newCursor != null){
            notifyDataSetChanged();
        }
    }

}
</code>```

Contact Database

```<code>import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ContactDatabaseHelper extends SQLiteOpenHelper {

    public static String DATABASE_NAME = "contactlist.db";
    private static final int SCHEMA_VERSION = 1;

    public ContactDatabaseHelper(Context context) { super(context, DATABASE_NAME, null, SCHEMA_VERSION); }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE contact_table( name TEXT, number TEXT , relation TEXT);");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    // Adds data into Contact database
    public void insertContactDatabase (String contact_name, String contact_number, String contact_relation) {
        ContentValues cv = new ContentValues();

        cv.put("name", contact_name);
        cv.put("number", contact_number);
        cv.put("relation", contact_relation);

        getWritableDatabase().insert("contact_table", "name", cv);
    }

    // Read Contact database
    public Cursor getContactDatabase() {
        return  (getReadableDatabase().rawQuery(
                "SELECT name, number, relation  FROM contact_table ORDER BY  + name", null));
    }

    // Delete Contact database
    public Integer deleteContactDatabase () {
        SQLiteDatabase db = this.getWritableDatabase();
        return db.delete("contact_table",null,null);

    }

    public String getContactName (Cursor c){ return (c.getString(0)); }

    public String getContactNumber (Cursor c){ return (c.getString(1)); }

    public String getContactRelation (Cursor c){ return (c.getString(2)); }
}
</code>```

contacts

```<code><?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/contact_background"
    tools:context=".Contact.Contacts">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/contact_recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@id/contact_button"
                    android:layout_marginTop="10dp"
                    android:scrollbars="vertical">

                </androidx.recyclerview.widget.RecyclerView>

                <Button
                    android:id="@+id/contact_button"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10sp"
                    android:layout_marginBottom="10sp"
                    android:background="#43464B"
                    android:text="New Contact"
                    android:textAlignment="center"
                    android:textColor="#FFFFFF"
                    android:textSize="18sp" />
            </LinearLayout>
        </ScrollView>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</code>```

contact_list (Cardview)

```<code><?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/list_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#FFEAB8"
    app:cardCornerRadius="15dp"
    app:cardElevation="5dp"
    app:cardUseCompatPadding="true">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="#00ACEE"
        app:cardCornerRadius="5dp"
        app:cardElevation="15dp"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:id="@+id/contact_layout_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Name"
                android:textAlignment="center"
                android:textColor="#E6E6E6"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text=":"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/contact_list_name_item"
                android:layout_width="190dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="Name"
                android:textColor="#FFFF00"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/contact_layout_number"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="35dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:text="Number"
                android:textAlignment="center"
                android:textColor="#E6E6E6"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:text=":"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/contact_list_number_item"
                android:layout_width="190dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:text="Number"
                android:textColor="#FFFF00"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/contact_layout_relation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="60dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                android:text="Relationship"
                android:textAlignment="center"
                android:textColor="#E6E6E6"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:text=":"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/contact_list_relation_item"
                android:layout_width="190dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:text="Relationship"
                android:textColor="#FFFF00"
                android:textSize="20sp" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

</androidx.cardview.widget.CardView>
</code>```

答:
Are you debug your code? What about method

```<code> public void swapCursor(Cursor newCursor){
        if (c != null){
            c.close();
        }

        c = newCursor;

        if (newCursor != null){
            notifyDataSetChanged();
        }
    }
</code>```

notifyDataSetChanged() is method which you should call.

Body:
I tried looking around but cant seem to find an answer that could resolve it.
Here is the process of what I'm doing:

1: Users enter data in a alert dialog

2: Data get sent into sql.

3: Adapter runs, takes data and put into a cardview.

4: Cardview is displayed(Stacks according to number of inputs made).

What that is not working to plan, the data that is being outputted overrides all previous inputs,and updates all cardviews with the latest information.

EG: Input 1: Test 1, Input 2: Test 2. Output will be 2 cardviews of Test 2.

Contact Activity

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.sp.R;

public class Contacts extends AppCompatActivity {

    private Button newContact;
    private AlertDialog.Builder builder;
    private AlertDialog dialog;
    private RecyclerView recyclerView;

    private ContactDatabaseHelper helper;
    private ContactAdapter mAdapter;

    private EditText new_contact_name;
    private EditText new_contact_number;
    private EditText new_contact_relation;
    private Button button_create_contact;
    private Button button_cancel_create;

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

        helper = new ContactDatabaseHelper(this);

        recyclerView = findViewById(R.id.contact_recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new ContactAdapter(this,getAllItems());
        recyclerView.setAdapter(mAdapter);

        newContact = findViewById(R.id.contact_button);
        // New Contact Button
        newContact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                builder = new AlertDialog.Builder(Contacts.this);
                builder.setTitle("Create New Contact");
                builder.setCancelable(false);
                View view = LayoutInflater.from(Contacts.this).inflate(R.layout.new_contact_dialog,null,false);
                CreateDialog(view);
                builder.setView(view);
                dialog = builder.create();
                dialog.show();
            }
        });

    }

    private void CreateDialog(View view) {

        // ContactDialog ID's
        new_contact_name = view.findViewById(R.id.new_contact_name);
        new_contact_number = view.findViewById(R.id.new_contact_number);
        new_contact_relation = view.findViewById(R.id.new_contact_relation);
        button_create_contact = view.findViewById(R.id.button_create_contact);
        button_cancel_create = view.findViewById(R.id.button_cancel_create);

        button_create_contact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                        // Get String of Name, Number, Relationship
                        String contactNameStr = new_contact_name.getText().toString();
                        String contactNumberStr = new_contact_number.getText().toString();
                        String contactRelationStr = new_contact_relation.getText().toString();

                        // Insert into ContactTable
                        helper.insertContactDatabase(contactNameStr,contactNumberStr,contactRelationStr);
                        mAdapter.swapCursor(getAllItems());

                        // Outputs a Toast
                        Toast.makeText(Contacts.this, "Contact Created", Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
            }
        });

        button_cancel_create.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

    }

    private Cursor getAllItems(){
        return helper.getContactDatabase();
    }

}

Contact Adapter

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.sp.R;

public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.MyHolder>{

    private Context mContext;
    private Cursor c;
    private ContactDatabaseHelper helper;

    public ContactAdapter(Context context,Cursor cursor) {

        mContext = context;
        c = cursor;
        helper = new ContactDatabaseHelper(mContext);
    }

    public static class MyHolder extends RecyclerView.ViewHolder{

        private TextView contact_name;
        private TextView contact_number;
        private TextView contact_relation;

        public MyHolder(View itemView) {
            super(itemView);

            contact_name = itemView.findViewById(R.id.contact_list_name_item);
            contact_number = itemView.findViewById(R.id.contact_list_number_item);
            contact_relation = itemView.findViewById(R.id.contact_list_relation_item);
        }
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.contact_list,parent,false);

        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {

        c.moveToFirst();

        holder.contact_name.setText(helper.getContactName(c));
        holder.contact_number.setText(helper.getContactNumber(c));
        holder.contact_relation.setText(helper.getContactRelation(c));

    }

    @Override
    public int getItemCount() {

        return c.getCount();
    }

    public void swapCursor(Cursor newCursor){
        if (c != null){
            c.close();
        }

        c = newCursor;

        if (newCursor != null){
            notifyDataSetChanged();
        }
    }

}

Contact Database

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class ContactDatabaseHelper extends SQLiteOpenHelper {

    public static String DATABASE_NAME = "contactlist.db";
    private static final int SCHEMA_VERSION = 1;

    public ContactDatabaseHelper(Context context) { super(context, DATABASE_NAME, null, SCHEMA_VERSION); }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE contact_table( name TEXT, number TEXT , relation TEXT);");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    // Adds data into Contact database
    public void insertContactDatabase (String contact_name, String contact_number, String contact_relation) {
        ContentValues cv = new ContentValues();

        cv.put("name", contact_name);
        cv.put("number", contact_number);
        cv.put("relation", contact_relation);

        getWritableDatabase().insert("contact_table", "name", cv);
    }

    // Read Contact database
    public Cursor getContactDatabase() {
        return  (getReadableDatabase().rawQuery(
                "SELECT name, number, relation  FROM contact_table ORDER BY  + name", null));
    }

    // Delete Contact database
    public Integer deleteContactDatabase () {
        SQLiteDatabase db = this.getWritableDatabase();
        return db.delete("contact_table",null,null);

    }

    public String getContactName (Cursor c){ return (c.getString(0)); }

    public String getContactNumber (Cursor c){ return (c.getString(1)); }

    public String getContactRelation (Cursor c){ return (c.getString(2)); }
}

contacts

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/contact_background"
    tools:context=".Contact.Contacts">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/contact_recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@id/contact_button"
                    android:layout_marginTop="10dp"
                    android:scrollbars="vertical">

                </androidx.recyclerview.widget.RecyclerView>

                <Button
                    android:id="@+id/contact_button"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="10sp"
                    android:layout_marginBottom="10sp"
                    android:background="#43464B"
                    android:text="New Contact"
                    android:textAlignment="center"
                    android:textColor="#FFFFFF"
                    android:textSize="18sp" />
            </LinearLayout>
        </ScrollView>

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

contact_list (Cardview)

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/list_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#FFEAB8"
    app:cardCornerRadius="15dp"
    app:cardElevation="5dp"
    app:cardUseCompatPadding="true">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="#00ACEE"
        app:cardCornerRadius="5dp"
        app:cardElevation="15dp"
        app:cardUseCompatPadding="true">

        <LinearLayout
            android:id="@+id/contact_layout_name"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Name"
                android:textAlignment="center"
                android:textColor="#E6E6E6"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text=":"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/contact_list_name_item"
                android:layout_width="190dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="Name"
                android:textColor="#FFFF00"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/contact_layout_number"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="35dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:text="Number"
                android:textAlignment="center"
                android:textColor="#E6E6E6"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:text=":"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/contact_list_number_item"
                android:layout_width="190dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:text="Number"
                android:textColor="#FFFF00"
                android:textSize="20sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/contact_layout_relation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="60dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                android:text="Relationship"
                android:textAlignment="center"
                android:textColor="#E6E6E6"
                android:textSize="20sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:text=":"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/contact_list_relation_item"
                android:layout_width="190dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:text="Relationship"
                android:textColor="#FFFF00"
                android:textSize="20sp" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

</androidx.cardview.widget.CardView>

Body:
Are you debug your code? What about method

 public void swapCursor(Cursor newCursor){
        if (c != null){
            c.close();
        }

        c = newCursor;

        if (newCursor != null){
            notifyDataSetChanged();
        }
    }

notifyDataSetChanged() is method which you should call.


来源: stackexchange

问:
How do I cache Python variables in Google Colab
After a period of inactivity, my Google Colab variables are lost and I have to recompute them. I know I can work around it with

```<code>from google.colab import drive
drive.mount('/content/drive/')
%cd '/content/drive/My Drive/path/to/my/project/folder'
</code>```

and then use numpy.save, torch.utils.checkpoint or tf.train.Checkpoint which will save it to Google Drive if my variable is in one of these formats.

Is there a way to cache any Python variable on Colab (i.e. not be bound to a specific data science framework or format)?

答:
You can use the cache-magic package with a symbolic link to your Drive folder.

Make the following your first cell in Colab and always run it first (replace path/to/my/project/folder with your Drive project folder):

```<code>from google.colab import drive
drive.mount('/content/drive')
%cd '/content/drive/My Drive/path/to/my/project/folder'

!pip install cache-magic
import cache_magic
!mkdir .cache
!ln -s '/content/drive/My Drive/path/to/my/project/folder/.cache' /content/.cache
</code>```

Now when you have some long computation:

```<code>bigVariable = longComputation()
</code>```

you replace it with

```<code>%cache bigVariable = longComputation()
</code>```

and it will be reloaded from cache if it was computed before!

Your cache lives in a folder named .cache inside your project folder.

ContentLicense: CC BY-SA 4.0

Body:
After a period of inactivity, my Google Colab variables are lost and I have to recompute them. I know I can work around it with

from google.colab import drive
drive.mount('/content/drive/')
%cd '/content/drive/My Drive/path/to/my/project/folder'

and then use numpy.save, torch.utils.checkpoint or tf.train.Checkpoint which will save it to Google Drive if my variable is in one of these formats.

Is there a way to cache any Python variable on Colab (i.e. not be bound to a specific data science framework or format)?

Body:
You can use the cache-magic package with a symbolic link to your Drive folder.

Make the following your first cell in Colab and always run it first (replace path/to/my/project/folder with your Drive project folder):

from google.colab import drive
drive.mount('/content/drive')
%cd '/content/drive/My Drive/path/to/my/project/folder'

!pip install cache-magic
import cache_magic
!mkdir .cache
!ln -s '/content/drive/My Drive/path/to/my/project/folder/.cache' /content/.cache

Now when you have some long computation:

bigVariable = longComputation()

you replace it with

%cache bigVariable = longComputation()

and it will be reloaded from cache if it was computed before!

Your cache lives in a folder named .cache inside your project folder.


问:
Regex to find invalid characters in integer with whitespaces
I want to use regular expression (regex) to find invalid characters in a string. The string is a user input and when the regex finds invalid characters I want to give the user feedback which characters where invalid. Example warning message: "Only 0-9 and whitespace allowed. Found invalid characters: ab" when input was "- 10 a 0 b".

A valid string is:

integer

negative or positive

is allowed to have any amount of whitespace at any position.

So for example those VALID strings should NOT match the regex:

```<code>"-100"
"- 1 00"
"  - 1 00"
"100"
" 1 0 0 "
"1 00"
</code>```

While the regex should find matches in these INVALID strings:

```<code>"- 1 a 0 0 b" should match "a" and "b"
"- 1 a 0 0 -" should match "a" and "-"
</code>```

I had a working regex for positive integers, until i found out that I forgot to include negative integers:

```<code>var regex = new Regex(@"[^0-9\s]")
var invalidCharacters = regex.Matches(text)
</code>```

I have only very basic knowledge of regex. I tried out negating the regex to include negative integers, but it is not working:

```<code>new Regex(@"(?!-?[0-9\s])")
</code>```

I hope someone can help me with this. If this can be solved easier by removing the whitespace requirement. Then please feel free to ignore the whitespace part.

答:
I would approach this by thinking about the positive case first - which strings are valid? And then negate that with a negative lookaround.

I think this meets your requirements:

```<code>(?!\s*-?[\d\s]).
</code>```

\s* will match any whitespace at the start

-? will optionally match a hyphen

[\d\s] will match numbers and whitespace

(?!expression) is a negative lookaround to negate the whole expression

The . at the end is a way to generate matches. The negative lookaround is just an assertion - it doesn't return any results.

It produces the desired results for the test cases in your question.

Body:
I want to use regular expression (regex) to find invalid characters in a string. The string is a user input and when the regex finds invalid characters I want to give the user feedback which characters where invalid. Example warning message: "Only 0-9 and whitespace allowed. Found invalid characters: ab" when input was "- 10 a 0 b".

A valid string is:

integer

negative or positive

is allowed to have any amount of whitespace at any position.

So for example those VALID strings should NOT match the regex:

"-100"
"- 1 00"
"  - 1 00"
"100"
" 1 0 0 "
"1 00"

While the regex should find matches in these INVALID strings:

"- 1 a 0 0 b" should match "a" and "b"
"- 1 a 0 0 -" should match "a" and "-"

I had a working regex for positive integers, until i found out that I forgot to include negative integers:

var regex = new Regex(@"[^0-9\s]")
var invalidCharacters = regex.Matches(text)

I have only very basic knowledge of regex. I tried out negating the regex to include negative integers, but it is not working:

new Regex(@"(?!-?[0-9\s])")

I hope someone can help me with this. If this can be solved easier by removing the whitespace requirement. Then please feel free to ignore the whitespace part.

Body:
I would approach this by thinking about the positive case first - which strings are valid? And then negate that with a negative lookaround.

I think this meets your requirements:

(?!\s*-?[\d\s]).

\s* will match any whitespace at the start

-? will optionally match a hyphen

[\d\s] will match numbers and whitespace

(?!expression) is a negative lookaround to negate the whole expression

The . at the end is a way to generate matches. The negative lookaround is just an assertion - it doesn't return any results.

It produces the desired results for the test cases in your question.


问:
How do I find the following data

Possible Duplicate:

  How do I query a table based with HABTM relationship while providing additional conditions in CakePHP?

I,m using two tables (regions and safaris) having many to many relationship. the tables are joined by another table called regions_safaris (with the fields - region_id $ safari-id). I want to fetch all safaris meeting a given criteria like durations of 5 days and in a given region.
This should be implemented in cakephp

答:
Assuming you have your models associated correctly. These are the lines of code I would use in a similar situation. When filtering on a habtm condition, I've found it helpful to start with the model that has the most restrictive filter (or the one that pears down the database the fastest). In this case, the region.

From the Safaris Controller:

```<code>$conditions = array('conditions' => array('Region.id' => 'yourRegion', 'Safari.duration' => 5);
$this->Safari->Region->recursive = 1;
$safaris = $this->Safari->Region->find('all', $conditions);
</code>```

You should then be able to print_r($safaris) and access each safari via a nested region array. i.e.:

```<code>$safaris['Region'][0]['Safari'][0]['name']
</code>```

This should give you the first returned regions first associated safari that matches the criteria. print_r($safaris) to get a better look at the data structure and you will see what I mean.

OwnerDisplayName: juma

ContentLicense: CC BY-SA 2.5

Title: How do I find the following data

LastEditorDisplayName: Karsten

Body:
Assuming you have your models associated correctly. These are the lines of code I would use in a similar situation. When filtering on a habtm condition, I've found it helpful to start with the model that has the most restrictive filter (or the one that pears down the database the fastest). In this case, the region.

From the Safaris Controller:

$conditions = array('conditions' => array('Region.id' => 'yourRegion', 'Safari.duration' => 5);
$this->Safari->Region->recursive = 1;
$safaris = $this->Safari->Region->find('all', $conditions);

You should then be able to print_r($safaris) and access each safari via a nested region array. i.e.:

$safaris['Region'][0]['Safari'][0]['name']

This should give you the first returned regions first associated safari that matches the criteria. print_r($safaris) to get a better look at the data structure and you will see what I mean.

OwnerDisplayName: Mike B


问:
If I have vim open in two terminals, how can I share the copy/paste buffer?
I want to yy a line from one instance of vim running in one terminal emulator, and p that line into another instance of vim running in another terminal emulator. Possible? Is there a special setting to use?

答:
There is a system clipboard which you can use to share data not only between multiple terminals, but also using shift + insert in GUI application.

First of all, check if system clipboard is enabled for your vim installation

```<code>vim --version | grep clipboard
</code>```

if you see +clipboard you are good to continue, otherwise, follow this page to enable the system clipboard.

Once the system clipboard is enabled, you can copy line via "+yy into + buffer which is a system clipboard, and paste it in another terminal with vim with "+p command.

Body:
There is a system clipboard which you can use to share data not only between multiple terminals, but also using shift + insert in GUI application.

First of all, check if system clipboard is enabled for your vim installation

vim --version | grep clipboard

if you see +clipboard you are good to continue, otherwise, follow this page to enable the system clipboard.

Once the system clipboard is enabled, you can copy line via "+yy into + buffer which is a system clipboard, and paste it in another terminal with vim with "+p command.


问:
Oracle SQL Question, Looking for rows that don't contain specific values
I have seen answers to this that get close, but don't quite do it for me.

Imagine that you have a several strings. You want to find the rows in an existing table that contain these strings and the rows that don't.

To find the rows that do contain the strings in a column is, of course, easy, e.g. myTable has the following columns:

myTableID  varChar(3)

myTableValue varChar(20)

With the following rows:

ABC | The First Row
GHI | The Second Row
JKL | The Third Row
```

```select *
from myTable
where myTableID  in ('ABC','DEF','GHI','JKL');
```

<p>myTable doesn't contain a row with a value of 'DEF' in column myTableID. The answer set would correctly not contain a row for that. There isn't one!</p>

<p>However what I want to be able to do is treat this like a bit like like a LEFT OUTER JOIN with the value 'DEF' in front of a set of columns that contain nulls. Giving the following kind of result:</p>

<pre class="lang-none prettyprint-override"><code>ABC| ABC | The First Row
DEF| null|null
GHI| GHI|The Second Row
JKL| JKL|The Third Row
</code>```

I have several hundred key values that I need to look at.

Does anyone here have any thoughts about the best way to do this?

答:
I have several hundred key values that I need to look at.

That's a lot of values to write manually. I would suggest putting them all in a table, say in a myref(id).

You can then generate the expected resultset with just a left join:

```<code>select
    r.id,
    t.*
from myref r
left join mytable t on t.id = r.id
</code>```

Body:
I have seen answers to this that get close, but don't quite do it for me.

Imagine that you have a several strings. You want to find the rows in an existing table that contain these strings and the rows that don't.

To find the rows that do contain the strings in a column is, of course, easy, e.g. myTable has the following columns:

myTableID  varChar(3)

myTableValue varChar(20)

With the following rows:

ABC | The First Row
GHI | The Second Row
JKL | The Third Row

select *
from myTable
where myTableID  in ('ABC','DEF','GHI','JKL');

myTable doesn't contain a row with a value of 'DEF' in column myTableID. The answer set would correctly not contain a row for that. There isn't one!

However what I want to be able to do is treat this like a bit like like a LEFT OUTER JOIN with the value 'DEF' in front of a set of columns that contain nulls. Giving the following kind of result:

ABC| ABC | The First Row
DEF| null|null
GHI| GHI|The Second Row
JKL| JKL|The Third Row

I have several hundred key values that I need to look at.

Does anyone here have any thoughts about the best way to do this?

Body:
I have several hundred key values that I need to look at.

That's a lot of values to write manually. I would suggest putting them all in a table, say in a myref(id).

You can then generate the expected resultset with just a left join:

select
    r.id,
    t.*
from myref r
left join mytable t on t.id = r.id


问:
Can build Android Project (Cmd F9), but Run (Ctrl R) errors out because of GSON BEGIN_OBJECT BEGIN_ARRAY issue
I migrated yesterday to Android Studio 4.0 because I wanted to start playing with Jetpack Compose. After upgrading Gradle and a few other things to actually get builds to work, I'm able to build (Cmd F9) the project successfully (no errors).

But when I try to run (Ctrl R) the project, it runs through the build process with all green success indicators (plus some warnings about unused variables in my functions), then errors out. What could be causing this?

I do not know how to do anything with Gradle besides add dependencies in my build.gradle or follow direct instructions from a website like Google has to upgrade AS in order to use Jetpack Compose. So I have no idea how to put breakpoints in the build process to see what's going on (googling suggests this is actually impossible) or how to track down the issue. Seems like there's something Gradle is expecting to be a JSON {} but is finding JSON [] instead. But the error sure doens't suggest what it could be.

```<code>> Task :app:assembleDebug

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
> Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
    at com.google.gson.Gson.fromJson(Gson.java:927)
    at com.google.gson.Gson.fromJson(Gson.java:865)
    at com.android.build.api.variant.impl.BuiltArtifactsLoaderImpl$Companion.loadFromFile(BuiltArtifactsLoaderImpl.kt:68)
    at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion.loadVersionTwoFile(EarlySyncBuildOutput.kt:109)
    at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion.load(EarlySyncBuildOutput.kt:70)
    at com.android.build.gradle.internal.ide.EarlySyncBuildOutput.load(EarlySyncBuildOutput.kt)
    at com.android.build.gradle.internal.ide.BuildOutputsSupplier.lambda$get$2(BuildOutputsSupplier.java:59)
    at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
    at com.android.build.gradle.internal.ide.BuildOutputsSupplier.get(BuildOutputsSupplier.java:53)
    at com.android.build.gradle.internal.ide.BuildOutputsSupplier.get(BuildOutputsSupplier.java:34)
    at com.android.build.gradle.internal.ide.ModelBuilder.lambda$buildMinimalisticModel$0(ModelBuilder.java:288)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildMinimalisticModel(ModelBuilder.java:297)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildNonParameterizedModels(ModelBuilder.java:238)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildAll(ModelBuilder.java:208)
    at com.android.build.gradle.internal.AppModelBuilder.buildAll(AppModelBuilder.kt:65)
    at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuildOperationWrappingToolingModelBuilder$1$1.create(DefaultToolingModelBuilderRegistry.java:104)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry.withLenientState(DefaultProjectStateRegistry.java:134)
    at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuildOperationWrappingToolingModelBuilder$1.call(DefaultToolingModelBuilderRegistry.java:100)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuildOperationWrappingToolingModelBuilder.buildAll(DefaultToolingModelBuilderRegistry.java:97)
    at org.gradle.tooling.internal.provider.runner.DefaultBuildController.getModel(DefaultBuildController.java:82)
    at org.gradle.tooling.internal.consumer.connection.InternalBuildActionAdapter$2.getModel(InternalBuildActionAdapter.java:74)
    at org.gradle.tooling.internal.consumer.connection.BuildControllerAdapter.getModel(BuildControllerAdapter.java:62)
    at org.gradle.tooling.internal.consumer.connection.AbstractBuildController.findModel(AbstractBuildController.java:57)
    at org.gradle.tooling.internal.consumer.connection.AbstractBuildController.findModel(AbstractBuildController.java:44)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildModuleModels.findAndAddModel(OutputBuildAction.java:136)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildModuleModels.populate(OutputBuildAction.java:116)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildModuleModels.access$200(OutputBuildAction.java:106)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildProjectModels.populateModule(OutputBuildAction.java:95)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildProjectModels.populate(OutputBuildAction.java:80)
    at com.android.tools.idea.gradle.run.OutputBuildAction.execute(OutputBuildAction.java:64)
    at com.android.tools.idea.gradle.run.OutputBuildAction.execute(OutputBuildAction.java:43)
    at org.gradle.tooling.internal.consumer.connection.InternalBuildActionAdapter.execute(InternalBuildActionAdapter.java:77)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner$ResultBuildingListener.buildResult(ClientProvidedBuildActionRunner.java:114)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner$ResultBuildingListener.buildFinished(ClientProvidedBuildActionRunner.java:106)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:382)
    at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:364)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
    at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:352)
    at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:339)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
    at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:231)
    at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:150)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
    at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:325)
    at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:235)
    at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:141)
    at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy15.buildFinished(Unknown Source)
    at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:174)
    at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:117)
    at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:86)
    at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:78)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:57)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner.run(ClientProvidedBuildActionRunner.java:55)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:39)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:51)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:50)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
    at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:80)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:42)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:28)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:52)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:68)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:37)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:41)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:48)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:32)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:68)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:27)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215)
    ... 132 more

* Get more help at https://help.gradle.org

BUILD FAILED in 34s
32 actionable tasks: 8 executed, 24 up-to-date
</code>```

答:
Using pre-release versions of Android Studio may cause problems from time to time, particularly for existing projects. On the whole, I try to use the pre-release Studio versions only with projects that I create in those versions, not with existing projects.

However, based on this issue, cleaning and rebuilding the project should have cleared up the issue... and based on your comment, apparently it did.

My interpretation: Something in the existing project build files (e.g., in .idea/) has a URL that points to a JSON document, and that document's structure changed. Cleaning the project switched it to a new URL, pointing to a document whose structure matches what the pre-release Android Gradle Plugin expects.

Body:
I migrated yesterday to Android Studio 4.0 because I wanted to start playing with Jetpack Compose. After upgrading Gradle and a few other things to actually get builds to work, I'm able to build (Cmd F9) the project successfully (no errors).

But when I try to run (Ctrl R) the project, it runs through the build process with all green success indicators (plus some warnings about unused variables in my functions), then errors out. What could be causing this?

I do not know how to do anything with Gradle besides add dependencies in my build.gradle or follow direct instructions from a website like Google has to upgrade AS in order to use Jetpack Compose. So I have no idea how to put breakpoints in the build process to see what's going on (googling suggests this is actually impossible) or how to track down the issue. Seems like there's something Gradle is expecting to be a JSON {} but is finding JSON [] instead. But the error sure doens't suggest what it could be.

> Task :app:assembleDebug

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
> Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
    at com.google.gson.Gson.fromJson(Gson.java:927)
    at com.google.gson.Gson.fromJson(Gson.java:865)
    at com.android.build.api.variant.impl.BuiltArtifactsLoaderImpl$Companion.loadFromFile(BuiltArtifactsLoaderImpl.kt:68)
    at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion.loadVersionTwoFile(EarlySyncBuildOutput.kt:109)
    at com.android.build.gradle.internal.ide.EarlySyncBuildOutput$Companion.load(EarlySyncBuildOutput.kt:70)
    at com.android.build.gradle.internal.ide.EarlySyncBuildOutput.load(EarlySyncBuildOutput.kt)
    at com.android.build.gradle.internal.ide.BuildOutputsSupplier.lambda$get$2(BuildOutputsSupplier.java:59)
    at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:405)
    at com.android.build.gradle.internal.ide.BuildOutputsSupplier.get(BuildOutputsSupplier.java:53)
    at com.android.build.gradle.internal.ide.BuildOutputsSupplier.get(BuildOutputsSupplier.java:34)
    at com.android.build.gradle.internal.ide.ModelBuilder.lambda$buildMinimalisticModel$0(ModelBuilder.java:288)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildMinimalisticModel(ModelBuilder.java:297)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildNonParameterizedModels(ModelBuilder.java:238)
    at com.android.build.gradle.internal.ide.ModelBuilder.buildAll(ModelBuilder.java:208)
    at com.android.build.gradle.internal.AppModelBuilder.buildAll(AppModelBuilder.kt:65)
    at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuildOperationWrappingToolingModelBuilder$1$1.create(DefaultToolingModelBuilderRegistry.java:104)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry.withLenientState(DefaultProjectStateRegistry.java:134)
    at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuildOperationWrappingToolingModelBuilder$1.call(DefaultToolingModelBuilderRegistry.java:100)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry$BuildOperationWrappingToolingModelBuilder.buildAll(DefaultToolingModelBuilderRegistry.java:97)
    at org.gradle.tooling.internal.provider.runner.DefaultBuildController.getModel(DefaultBuildController.java:82)
    at org.gradle.tooling.internal.consumer.connection.InternalBuildActionAdapter$2.getModel(InternalBuildActionAdapter.java:74)
    at org.gradle.tooling.internal.consumer.connection.BuildControllerAdapter.getModel(BuildControllerAdapter.java:62)
    at org.gradle.tooling.internal.consumer.connection.AbstractBuildController.findModel(AbstractBuildController.java:57)
    at org.gradle.tooling.internal.consumer.connection.AbstractBuildController.findModel(AbstractBuildController.java:44)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildModuleModels.findAndAddModel(OutputBuildAction.java:136)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildModuleModels.populate(OutputBuildAction.java:116)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildModuleModels.access$200(OutputBuildAction.java:106)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildProjectModels.populateModule(OutputBuildAction.java:95)
    at com.android.tools.idea.gradle.run.OutputBuildAction$PostBuildProjectModels.populate(OutputBuildAction.java:80)
    at com.android.tools.idea.gradle.run.OutputBuildAction.execute(OutputBuildAction.java:64)
    at com.android.tools.idea.gradle.run.OutputBuildAction.execute(OutputBuildAction.java:43)
    at org.gradle.tooling.internal.consumer.connection.InternalBuildActionAdapter.execute(InternalBuildActionAdapter.java:77)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner$ResultBuildingListener.buildResult(ClientProvidedBuildActionRunner.java:114)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner$ResultBuildingListener.buildFinished(ClientProvidedBuildActionRunner.java:106)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:382)
    at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:364)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
    at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:352)
    at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:339)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
    at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:231)
    at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:150)
    at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
    at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:325)
    at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:235)
    at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:141)
    at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy15.buildFinished(Unknown Source)
    at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:174)
    at org.gradle.initialization.DefaultGradleLauncher.finishBuild(DefaultGradleLauncher.java:117)
    at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:86)
    at org.gradle.internal.invocation.GradleBuildController$3.create(GradleBuildController.java:78)
    at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:189)
    at org.gradle.internal.work.StopShieldingWorkerLeaseService.withLocks(StopShieldingWorkerLeaseService.java:40)
    at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:57)
    at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner.run(ClientProvidedBuildActionRunner.java:55)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
    at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
    at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:39)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:51)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:45)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:50)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$1.transform(InProcessBuildActionExecuter.java:47)
    at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:80)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:31)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:42)
    at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:28)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:78)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:52)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:68)
    at org.gradle.tooling.internal.provider.SessionScopeBuildActionExecuter.execute(SessionScopeBuildActionExecuter.java:38)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:37)
    at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
    at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:60)
    at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
    at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:41)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:48)
    at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:32)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:68)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:27)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215)
    ... 132 more

* Get more help at https://help.gradle.org

BUILD FAILED in 34s
32 actionable tasks: 8 executed, 24 up-to-date


问:
Why are my dicts alternating between mutable and immutable?
Consider this code

```<code>from pprint import pprint
test_dict = {}
new = {}
new['slot'] = {}
for k in range(5):
    test_dict[k] = {}
    test_dict[k].update(new)
    if k == 3:
        test_dict[k]['slot']['this should only be in 3'] = []
pprint(test_dict)
print('Round 2, without SLOT')
test_dict = {}
new = {}
for k in range(5):
    test_dict[k] = {}
    test_dict[k].update(new)
    if k == 3:
        test_dict[k]['this should only be in 3'] = []
pprint(test_dict)

</code>```

With this output

```<code>> python -i .\test2.py
{0: {'slot': {'this should only be in 3': []}},
 1: {'slot': {'this should only be in 3': []}},
 2: {'slot': {'this should only be in 3': []}},
 3: {'slot': {'this should only be in 3': []}},
 4: {'slot': {'this should only be in 3': []}}}
Round 2, without SLOT
{0: {}, 1: {}, 2: {}, 3: {'this should only be in 3': []}, 4: {}}
</code>```

Help me understand why in the first case, the 'should only be...' list is appearing in every case and not the second. Dicts are immutable but I don't understand why I'm getting different results.

Thanks,

答:
The update method does not make a copy of new['slot'] for each entry in test_dict.

After

```<code>test_dict = {}
new = {}
new['slot'] = {}
for k in range(5):
    test_dict[k] = {}
    test_dict[k].update(new)
    if k == 3:
        test_dict[k]['slot']['this should only be in 3'] = []
</code>```

test_dict[k]['slot'] is a reference to the same dict for each k = 0, 1, ..., 4. You can confirm this with id:

```<code>>>> for k in range(5): id(test_dict[k]['slot'])
...
4422633104
4422633104
4422633104
4422633104
4422633104
>>> id(new['slot'])
4422633104
</code>```

Body:
Consider this code

from pprint import pprint
test_dict = {}
new = {}
new['slot'] = {}
for k in range(5):
    test_dict[k] = {}
    test_dict[k].update(new)
    if k == 3:
        test_dict[k]['slot']['this should only be in 3'] = []
pprint(test_dict)
print('Round 2, without SLOT')
test_dict = {}
new = {}
for k in range(5):
    test_dict[k] = {}
    test_dict[k].update(new)
    if k == 3:
        test_dict[k]['this should only be in 3'] = []
pprint(test_dict)

With this output

> python -i .\test2.py
{0: {'slot': {'this should only be in 3': []}},
 1: {'slot': {'this should only be in 3': []}},
 2: {'slot': {'this should only be in 3': []}},
 3: {'slot': {'this should only be in 3': []}},
 4: {'slot': {'this should only be in 3': []}}}
Round 2, without SLOT
{0: {}, 1: {}, 2: {}, 3: {'this should only be in 3': []}, 4: {}}

Help me understand why in the first case, the 'should only be...' list is appearing in every case and not the second. Dicts are immutable but I don't understand why I'm getting different results.

Thanks,

Body:
The update method does not make a copy of new['slot'] for each entry in test_dict.

After

test_dict = {}
new = {}
new['slot'] = {}
for k in range(5):
    test_dict[k] = {}
    test_dict[k].update(new)
    if k == 3:
        test_dict[k]['slot']['this should only be in 3'] = []

test_dict[k]['slot'] is a reference to the same dict for each k = 0, 1, ..., 4. You can confirm this with id:

>>> for k in range(5): id(test_dict[k]['slot'])
...
4422633104
4422633104
4422633104
4422633104
4422633104
>>> id(new['slot'])
4422633104


问:
pip install selenium ERROR python 3.7 Windows 10
I downloaded Python 3.7 just now. Now I'm trying to install the selenium module. I am able to run python in my command prompt. But, when I type:

```<code>pip install -U selenium
</code>```

or

```<code>pip install selenium
</code>```

I get a syntax error.

```<code>Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> pip install -U selenium
  File "<stdin>", line 1
    pip install -U selenium
              ^
SyntaxError: invalid syntax
</code>```

I'm thinking it's a bug with the new Python version, but not sure if anybody can tell me what I did wrong.

答:
python -m pip install selenium --user
```

pip defaults to installing Python packages to a system directory (such as /usr/local/lib/python3.4). This requires root access.

--user makes pip install packages in your home directory instead, which doesn't require any special privileges.

Body:
I downloaded Python 3.7 just now. Now I'm trying to install the selenium module. I am able to run python in my command prompt. But, when I type:

pip install -U selenium

or

pip install selenium

I get a syntax error.

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> pip install -U selenium
  File "<stdin>", line 1
    pip install -U selenium
              ^
SyntaxError: invalid syntax

I'm thinking it's a bug with the new Python version, but not sure if anybody can tell me what I did wrong.

Body:
python -m pip install selenium --user

pip defaults to installing Python packages to a system directory (such as /usr/local/lib/python3.4). This requires root access.

--user makes pip install packages in your home directory instead, which doesn't require any special privileges.


问:
How to restore files from recycle bin

Possible Duplicate:

  How do I restore a file from the recycle bin using C#?

Someone knows how to restore files from recycle bin using C# with the Windows API?.

答:
This link can help you </p>

```<code>using System;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using Shell32; //Reference Microsoft Shell Controls And Automation on the COM tab.
using System.Runtime.InteropServices;
using Microsoft.VisualBasic.FileIO;
namespace RecyclerCS
{
  public partial class Form1 : Form
  {
    public Form1() {
      InitializeComponent();
    }
    private Shell Shl;
    private const long ssfBITBUCKET = 10;
    private const int recycleNAME = 0;
    private const int recyclePATH = 1;

    private void button1_Click(object sender, System.EventArgs e) {
      string S = "This is text in the file to be restored from the Recycle Bin.";
      string FileName = "C:\\Temp\\Text.txt";
      File.WriteAllText(FileName, S);
      Delete(FileName);
      MessageBox.Show(FileName + " has been moved to the Recycle Bin.");
      if (Restore(FileName))
        MessageBox.Show(FileName + " has been restored");
      else
        MessageBox.Show("Error");
      Marshal.FinalReleaseComObject(Shl);
    }
    private void Delete(string Item) {
      FileSystem.DeleteFile(Item, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
      //Gives the most control of dialogs.
    }
    private bool Restore(string Item) {
      Shl = new Shell();
      Folder Recycler = Shl.NameSpace(10);
      for (int i = 0; i < Recycler.Items().Count; i++) {
        FolderItem FI = Recycler.Items().Item(i);
        string FileName = Recycler.GetDetailsOf(FI, 0);
        if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path);
        //Necessary for systems with hidden file extensions.
        string FilePath = Recycler.GetDetailsOf(FI, 1);
        if (Item == Path.Combine(FilePath, FileName)) {
          DoVerb(FI, "ESTORE");
          return true;
        }
      }
      return false;
    }
    private bool DoVerb(FolderItem Item, string Verb) {
      foreach (FolderItemVerb FIVerb in Item.Verbs()) {
        if (FIVerb.Name.ToUpper().Contains(Verb.ToUpper())) {
          FIVerb.DoIt();
          return true;
        }
      }
      return false;
    }
  }
}
</code>```

ContentLicense: CC BY-SA 3.0

Title: How to restore files from recycle bin

Body:
This link can help you

using System;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using Shell32; //Reference Microsoft Shell Controls And Automation on the COM tab.
using System.Runtime.InteropServices;
using Microsoft.VisualBasic.FileIO;
namespace RecyclerCS
{
  public partial class Form1 : Form
  {
    public Form1() {
      InitializeComponent();
    }
    private Shell Shl;
    private const long ssfBITBUCKET = 10;
    private const int recycleNAME = 0;
    private const int recyclePATH = 1;

    private void button1_Click(object sender, System.EventArgs e) {
      string S = "This is text in the file to be restored from the Recycle Bin.";
      string FileName = "C:\\Temp\\Text.txt";
      File.WriteAllText(FileName, S);
      Delete(FileName);
      MessageBox.Show(FileName + " has been moved to the Recycle Bin.");
      if (Restore(FileName))
        MessageBox.Show(FileName + " has been restored");
      else
        MessageBox.Show("Error");
      Marshal.FinalReleaseComObject(Shl);
    }
    private void Delete(string Item) {
      FileSystem.DeleteFile(Item, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
      //Gives the most control of dialogs.
    }
    private bool Restore(string Item) {
      Shl = new Shell();
      Folder Recycler = Shl.NameSpace(10);
      for (int i = 0; i < Recycler.Items().Count; i++) {
        FolderItem FI = Recycler.Items().Item(i);
        string FileName = Recycler.GetDetailsOf(FI, 0);
        if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path);
        //Necessary for systems with hidden file extensions.
        string FilePath = Recycler.GetDetailsOf(FI, 1);
        if (Item == Path.Combine(FilePath, FileName)) {
          DoVerb(FI, "ESTORE");
          return true;
        }
      }
      return false;
    }
    private bool DoVerb(FolderItem Item, string Verb) {
      foreach (FolderItemVerb FIVerb in Item.Verbs()) {
        if (FIVerb.Name.ToUpper().Contains(Verb.ToUpper())) {
          FIVerb.DoIt();
          return true;
        }
      }
      return false;
    }
  }
}


问:
How do get the text from specific line in listbox delphi
I want to get the text from a specific line.

Ex.

ListBox Contents:

Line 0    String 1

Line 1    String 2

Line 3    String 3

How do get the text from line 1 per example?

i try with this:

(listbox1.Items.Objects[1] as TText).Text

But generates a random access violation...

There is a another way?

答:
Assuming they exist,

ListBox.Items[0] is the first string in the list box.

ListBox.Items[1] is the second string in the list box.

...

ListBox.Items[ListBox.Items.Count - 1] is the last string in the list box.

Instead of

```<code>ListBox.Items[i]
</code>```

you can also use

```<code>ListBox.Items.Strings[i]
</code>```

but that's more to type.

(The TStrings.Strings property is clearly an array property, and because it is declared as "default", it can be accessed by using the brackets on the object itself.)

Bonus material: The Objects array property you tried is used occasionally to associate an object (pointer) with each item in the list. (And sometimes it is abused to store native-size integers which aren't objects, still one per item.)

Body:
Assuming they exist,

ListBox.Items[0] is the first string in the list box.

ListBox.Items[1] is the second string in the list box.

...

ListBox.Items[ListBox.Items.Count - 1] is the last string in the list box.

Instead of

ListBox.Items[i]

you can also use

ListBox.Items.Strings[i]

but that's more to type.

(The TStrings.Strings property is clearly an array property, and because it is declared as "default", it can be accessed by using the brackets on the object itself.)

Bonus material: The Objects array property you tried is used occasionally to associate an object (pointer) with each item in the list. (And sometimes it is abused to store native-size integers which aren't objects, still one per item.)