小编New*_*ddy的帖子

在Git中恢复已删除的分支

我错误地删除了我的分支,如下所示:

git branch -D demo
Run Code Online (Sandbox Code Playgroud)

但是我想要恢复它...我之后得到了它 git reflog

541b2f5 HEAD@{23}: checkout: moving from demo to master
06fa6d5 HEAD@{24}: commit (merge): remove ajax call for deleting variables and transfomers
b84b60a HEAD@{25}: checkout: moving from demo1 to demo
Run Code Online (Sandbox Code Playgroud)

我想用sha创建分支06fa6d5...所以我尝试了这个:

git checkout -b demo  06fa6d5

git checkout -b demo  HEAD@{24}
Run Code Online (Sandbox Code Playgroud)

但是我没有从中得到代码......

git git-branch

24
推荐指数
1
解决办法
3万
查看次数

无法以编程方式将android联系人插入Android设备

ArrayList<ContentProviderOperation> ops =new ArrayList<ContentProviderOperation>();
         ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                  .withValue(Data.RAW_CONTACT_ID, 3)
                  .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
                  .withValue(Phone.NUMBER, "999999999")
                  .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
                  .withValue(Phone.DISPLAY_NAME, "hhhhhhh")
                  .withValue(ContactsContract.CommonDataKinds.Email.DATA, "abcd@gmail.com")
                  .build());
         ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                  .withValue(Data.RAW_CONTACT_ID, 4)
                  .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
                  .withValue(Phone.NUMBER, "999999999")
                  .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
                  .withValue(Phone.DISPLAY_NAME, "hhhlllllllllll")
                  .withValue(ContactsContract.CommonDataKinds.Email.DATA, "efgh@gmail.com")
                  .build());

         try {
             cr.applyBatch(ContactsContract.AUTHORITY, ops);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OperationApplicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Run Code Online (Sandbox Code Playgroud)

我已经添加了 <uses-permission android:name="android.permission.WRITE_CONTACTS"/>许可.

我收到以下错误:

09-25 09:30:41.365: W/System.err(1057): android.content.OperationApplicationException: insert failed
09-25 09:30:41.375: W/System.err(1057):     at android.database.DatabaseUtils.readExceptionWithOperationApplicationExceptionFromParcel(DatabaseUtils.java:161)
09-25 09:30:41.375: W/System.err(1057):     at android.content.ContentProviderProxy.applyBatch(ContentProviderNative.java:461) …
Run Code Online (Sandbox Code Playgroud)

android contactscontract android-contacts

8
推荐指数
1
解决办法
8378
查看次数

Java 8 获取地址以 P 开头的所有员工

我有员工和地址类如下

class Employee {
    private String name;
    private int age;
    private List<Address> addresses;
    //getter and setter
}

class Address {
    private String city;
    private String state;
    private String country;
    //getter and setter
}
Run Code Online (Sandbox Code Playgroud)

使用java 8过滤器我想打印所有以P开头的城市的员工

在下面的代码中添加什么来获取过滤地址的 emp

employees.stream()
    .map(Employee::getAddresses)
    .flatMap(Collection::stream)
    .filter(children -> children.getCity().startsWith("p"))
    .collect(Collectors.toList())
    .forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)

提前致谢。

java filter java-8 java-stream

5
推荐指数
2
解决办法
3163
查看次数

添加侦听器以切换操作栏

我已经添加了切换到这样的活动的操作栏

switch layout.xml是

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
    android:layout_height="match_parent"
   android:orientation="horizontal" >

<Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Menu.xml是

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

 <item
    android:id="@+id/myswitch"
    android:title=""
    android:showAsAction="always"
    android:actionLayout="@layout/switch_layout"
/>   
</menu>
Run Code Online (Sandbox Code Playgroud)

在java文件中我有这个代码

    public boolean onCreateOptionsMenu(Menu menu)
  {

    getMenuInflater().inflate(R.menu.Menu, menu);
    switch1 = (Switch) findViewById(R.id.switch1);
    if(switch1 == null){
        Toast.makeText(this, "Null", Toast.LENGTH_SHORT).show();
    }
         //     switch1.setOnCheckedChangeListener(this);
       return true;
}

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
       Toast.makeText(this, "Monitored switch is " + (isChecked ? "on" : "off"),
               Toast.LENGTH_SHORT).show();
    }

public boolean onOptionsItemSelected(MenuItem item) …
Run Code Online (Sandbox Code Playgroud)

android

4
推荐指数
1
解决办法
3413
查看次数

HibernateException:拥有实体实例不再引用具有cascade ="all-delete-orphan"的集合

我在它们之间有PolicyDO和PolicyDocumentDO.relation如下

PolicyDO.hbm.xml

<bag name="listPolicyDocumentDOList" cascade="all-delete-orphan" lazy="false"   inverse="true">
            <key column="POLICYSEQ" />
            <one-to-many class="dataobjects.policy.PolicyDocumentDO" />
Run Code Online (Sandbox Code Playgroud)

PolicyDO.java
protected List<PolicyDocumentDO> policyDocumentDOList = new ArrayList<PolicyDocumentDO>();
 public java.util.List<PolicyDocumentDO> getListPolicyDocumentDOList() {
    return this.policyDocumentDOList;
  }

  public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
      policyDocumentDOList.clear();
      policyDocumentDOList = list;
  }


    PolicyDocumentDO.hbm.xml

    <many-to-one name="parentGuidObj" class="dataobjects.policy.PolicyDO"  not-null="true" >
            <column name="POLICYSEQ"  />
    </many-to-one>  
Run Code Online (Sandbox Code Playgroud)

我什么时候尝试从数据库中查询某些内容,如下所示

session = sessionFactory.openSession();
Query query = session.createQuery(strBuff.toString());
List listQuery = query.list();
Run Code Online (Sandbox Code Playgroud)

我得到以下错误

org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: 
Run Code Online (Sandbox Code Playgroud)

dataobjects.policy.PolicyDO.listPolicyDocumentDOList

所以在谷歌搜索后,我在PolicyDO中设置listPolicyDocumentDOList时做了以下更改

public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) …
Run Code Online (Sandbox Code Playgroud)

java hibernate hibernate-mapping

4
推荐指数
1
解决办法
9001
查看次数

Kafka 事务性读已提交消费者

我在应用程序中有事务性和普通的生产者,它们正在写入主题 kafka-topic ,如下所示。

事务性 Kafka Producer 的配置

@Bean
    public Map<String, Object> producerConfigs() {

        Map<String, Object> props = new HashMap<>();
        // list of host:port pairs used for establishing the initial connections to the Kakfa cluster
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        props.put(ProducerConfig.RETRIES_CONFIG, 5);
        /*The amount of time to wait before attempting to retry a failed request to a given topic partition. 
         * This avoids repeatedly sending requests in a tight loop under some failure scenarios.*/
        props.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, 3);
        /*"The configuration controls the …
Run Code Online (Sandbox Code Playgroud)

transactions apache-kafka kafka-consumer-api spring-kafka kafka-transactions-api

1
推荐指数
1
解决办法
1433
查看次数