问:
Make difference between instances of same component in angular2
I just started to learn Angular 2 and I have a question about components. I have created a component named "dropdownComponent" that generates dropdown components. but when I use this component multiple times I dont know how to make difference between instances of one component.drop-down id='1'>drop-down id='2'>
how can I set something like id to each instance and find each component by id, so I can send data or call function of each component separately.
thanks

```<code>     this this my component
    import { Component, Input, OnInit } from '@angular/core';
    import {SelectComponent} from 'ng2-select';

    import { Service } from '../../../service/index';

    interface singleselectitem {
      Value: string;
    }

   @Component({
selector: 'singleselect',
   templateUrl: 'app/home/select/select/singleselect.html',
   providers: [SelectComponent]
 })
 export class singleselectComponent {

@Input() calleditems: string;
public items: Array<string> = [];
//items: singleselectitem[] = [];
selecteditem: singleselectitem;
constructor(private service: Service, private select: SelectComponent) {
    this.select.items = [];
}

ngOnInit() {
    if (this.calleditems == 'ArchiveList')
        this.GetArchiveList();
}

GetArchiveList() {
    this.service.callservice('get', 'basic/getArchiveList', '').subscribe(
        data => {
            for (var i = 0; i < data.length; i++) {
                this.items.push(data[i].Value);
            }
        },
        err => {

        });
}

private value: any = {};
private _disabledV: string = '0';
private disabled: boolean = false;

private get disabledV(): string {
    return this._disabledV;
}

private set disabledV(value: string) {
    this._disabledV = value;
    this.disabled = this._disabledV === '1';
}

public selected(value: any): void {
    console.log('Selected value is: ', value);
}

public removed(value: any): void {
    console.log('Removed value is: ', value);
}

public typed(value: any): void {
    console.log('New search input: ', value);
}

public refreshValue(value: any): void {
    this.value = value;
}
}

    //template of my component
   <div style="width: 300px; margin-bottom: 20px;">
<ng-select [allowClear]="true"
           [items]="items"

           (data)="refreshValue($event)"
           (selected)="selected($event)"
           (removed)="removed($event)"
           (typed)="typed($event)"
           >
</ng-select>
</code>```

```<code>      //host component
     import { Component, OnInit } from '@angular/core';
     import { Router } from '@angular/router';
     import {SelectComponent} from 'ng2-select';

      import { CarouselComponent } from '../home/slider/index';
      import { Service } from '../service/index';
       import {singleselectComponent} from './select/select/singleselect';

       @Component({
moduleId: module.id,
templateUrl: './home.component.html',
providers: [CarouselComponent, singleselectComponent, SelectComponent] // means we have used csscarousel tags in home.html
       })

       export class HomeComponent implements OnInit {

private ArchiveList: any;

constructor(private service: Service, private router: Router, private singleselect: singleselectComponent) { }

ngOnInit() {
    if (this.service.GetToken() == null)
        this.router.navigate(['/login']);
}
    }

       template of host component
       <div class="col-md-6 col-md-offset-3">
<h1>Home</h1>
<p><a [routerLink]="['/login']">Logout</a></p>
      </div>
      <singleselect [calleditems]="'ArchiveList'"></singleselect>
      <singleselect [calleditems]="'ArchiveList1'"></singleselect>
      <div class="wrapper">
           <css-carousel></css-carousel>
      </div>
</code>```

答:
I think you need ViewChild annotation.
you can give to each of your dropdown component an id in your Html page like this:

```<code><drop-down #countriesDropDown></drop-down>
<drop-down #citiesDropDown></drop-down>
</code>```

then in your component.ts file :

```<code>export class HomeComponent implements OnInit {
    @ViewChild("countriesDropDown")
    contriesDp: dropdownComponent;

    @ViewChild("citiesDropDown")
    citiesDp: dropdownComponent;
}
</code>```

now you can use your public methods of your DropDown component seprately like:

```<code>ngOnInit() {
    this.contriesDp.publicMethod();
    this.citiesDp.publicMethod();
}
</code>```

Body:
I just started to learn Angular 2 and I have a question about components. I have created a component named "dropdownComponent" that generates dropdown components. but when I use this component multiple times I dont know how to make difference between instances of one component.drop-down id='1'>drop-down id='2'>
how can I set something like id to each instance and find each component by id, so I can send data or call function of each component separately.
thanks

     this this my component
    import { Component, Input, OnInit } from '@angular/core';
    import {SelectComponent} from 'ng2-select';

    import { Service } from '../../../service/index';

    interface singleselectitem {
      Value: string;
    }

   @Component({
selector: 'singleselect',
   templateUrl: 'app/home/select/select/singleselect.html',
   providers: [SelectComponent]
 })
 export class singleselectComponent {

@Input() calleditems: string;
public items: Array<string> = [];
//items: singleselectitem[] = [];
selecteditem: singleselectitem;
constructor(private service: Service, private select: SelectComponent) {
    this.select.items = [];
}

ngOnInit() {
    if (this.calleditems == 'ArchiveList')
        this.GetArchiveList();
}

GetArchiveList() {
    this.service.callservice('get', 'basic/getArchiveList', '').subscribe(
        data => {
            for (var i = 0; i < data.length; i++) {
                this.items.push(data[i].Value);
            }
        },
        err => {

        });
}

private value: any = {};
private _disabledV: string = '0';
private disabled: boolean = false;

private get disabledV(): string {
    return this._disabledV;
}

private set disabledV(value: string) {
    this._disabledV = value;
    this.disabled = this._disabledV === '1';
}

public selected(value: any): void {
    console.log('Selected value is: ', value);
}

public removed(value: any): void {
    console.log('Removed value is: ', value);
}

public typed(value: any): void {
    console.log('New search input: ', value);
}

public refreshValue(value: any): void {
    this.value = value;
}
}

    //template of my component

<ng-select [allowClear]="true"
           [items]="items"

           (data)="refreshValue($event)"
           (selected)="selected($event)"
           (removed)="removed($event)"
           (typed)="typed($event)"
           >
</ng-select>

      //host component
     import { Component, OnInit } from '@angular/core';
     import { Router } from '@angular/router';
     import {SelectComponent} from 'ng2-select';

      import { CarouselComponent } from '../home/slider/index';
      import { Service } from '../service/index';
       import {singleselectComponent} from './select/select/singleselect';

       @Component({
moduleId: module.id,
templateUrl: './home.component.html',
providers: [CarouselComponent, singleselectComponent, SelectComponent] // means we have used csscarousel tags in home.html
       })

       export class HomeComponent implements OnInit {

private ArchiveList: any;

constructor(private service: Service, private router: Router, private singleselect: singleselectComponent) { }

ngOnInit() {
    if (this.service.GetToken() == null)
        this.router.navigate(['/login']);
}
    }

       template of host component

Home

Logout

      <singleselect [calleditems]="'ArchiveList'"></singleselect>
      <singleselect [calleditems]="'ArchiveList1'"></singleselect>

           <css-carousel></css-carousel>

Body:
I think you need ViewChild annotation.
you can give to each of your dropdown component an id in your Html page like this:

<drop-down #countriesDropDown></drop-down>
<drop-down #citiesDropDown></drop-down>

then in your component.ts file :

export class HomeComponent implements OnInit {
    @ViewChild("countriesDropDown")
    contriesDp: dropdownComponent;

    @ViewChild("citiesDropDown")
    citiesDp: dropdownComponent;
}

now you can use your public methods of your DropDown component seprately like:

ngOnInit() {
    this.contriesDp.publicMethod();
    this.citiesDp.publicMethod();
}


来源: stackexchange

问:
Docusign return url change parameter
The parameter 'event=signing_complete'  is automatically add in docusign embedded signing. I want to change this something like 'success=signing_complete' or 'complete=signing_complete' or 'thanks=signing_complete' like that. Is there is any way to change that parameter 'event' ??.</p>

答:
No, sorry, the return event parameter and its values are all constants.

Also, if there are additional signers for the envelope after the embedded signer, then the envelope's status will not be complete until all of the recipients/signers have been processed.

ContentLicense: CC BY-SA 3.0

Title: Docusign return url change parameter


问:
SQL Null: Preferred way of distinguishing between unknown and no value
Suppose I have a simple table such as:

```<code>CREATE TABLE authors (
    id INT PRIMARY KEY,
    name VARCHAR(40),
    born DATE,
    died DATE
);
</code>```

Both the born and died dates are optional, so they can contain NULL.

Presumably authors who haven’t been born yet, won’t make it into the table, so the obvious way to interpret NULL would be that the date is unknown.

However, there is some ambiguity with the died date. A null could imply that the date is unknown, or that the author has yet to die.

What is the preferred way allow for both an unknown date and an event which has not yet occurred?

For what it’s worth, I routinely use PostgreSQL, MySQL/MariaDB and SQL Server, so this question isn’t specific to a particular DBMS.

答:
This elaborates on Tim's answer.  I think the best approach is:

```<code>CREATE TABLE authors (
    id INT PRIMARY KEY,
    name VARCHAR(40),
    isDead int not null,  -- well, could be a bit or boolean or tinyint
    bornDate DATE,
    diedDate DATE,
    constraint chk_authors_isDead check (isDead in (0, 1)),  -- valid values
    constraint chk_authors_isDead_diedDate check (isDead = 1 or diedDate is NULL),
    constraint check_authors_bornDate_diedDate check (bornDate <= diedDate)  -- you might want to require that they are actually old enough to have written somthing
);
</code>```

This code validates the following conditions:

The new isDead column only takes on the values of 0 and 1.

When DiedDate is not NULL, then isDead is 1.

The author is born before they died.

Check constraints are standard SQL and supported by most databases -- but not alas by MySQL.

Body:
Suppose I have a simple table such as:

CREATE TABLE authors (
    id INT PRIMARY KEY,
    name VARCHAR(40),
    born DATE,
    died DATE
);

Both the born and died dates are optional, so they can contain NULL.

Presumably authors who haven’t been born yet, won’t make it into the table, so the obvious way to interpret NULL would be that the date is unknown.

However, there is some ambiguity with the died date. A null could imply that the date is unknown, or that the author has yet to die.

What is the preferred way allow for both an unknown date and an event which has not yet occurred?

For what it’s worth, I routinely use PostgreSQL, MySQL/MariaDB and SQL Server, so this question isn’t specific to a particular DBMS.

Body:
This elaborates on Tim's answer.  I think the best approach is:

CREATE TABLE authors (
    id INT PRIMARY KEY,
    name VARCHAR(40),
    isDead int not null,  -- well, could be a bit or boolean or tinyint
    bornDate DATE,
    diedDate DATE,
    constraint chk_authors_isDead check (isDead in (0, 1)),  -- valid values
    constraint chk_authors_isDead_diedDate check (isDead = 1 or diedDate is NULL),
    constraint check_authors_bornDate_diedDate check (bornDate <= diedDate)  -- you might want to require that they are actually old enough to have written somthing
);

This code validates the following conditions:

The new isDead column only takes on the values of 0 and 1.

When DiedDate is not NULL, then isDead is 1.

The author is born before they died.

Check constraints are standard SQL and supported by most databases -- but not alas by MySQL.


问:
Parse Cloud: Send Push to a single user
I'm using Parse and I can't make this method to work.

The idea is to send push to a single user with an already known user identifier from any platform within 'Cloud code'.

Queries I've tried without push being delivered to that user (actually no push was delivered to any user)

PFInstallation through the user pointer:

var targetUser = new Parse.User();

targetUser.id = userID;

var query = new Parse.Query(Parse.Installation);

query.equalTo('user', targetUser);

Query in PFUser itself

var query = new Parse.Query(Parse.User);

query.equalTo('objectId', userID);

Full code for the method:

```<code>Parse.Cloud.define("sendPushContactUser", function(request, response) {

// Get parameters
var userID       = request.params.userID; // I'm obviously passing this parameter in the method call

// Query
/* ------ query = Any of the above options ------ */

Parse.Push.send({
    where: query,
    data: {
        title   : "New message",
        alert   : "User message",
        badge   : "Increment",
        sound   : "soundNotifUserContact.caf",
        "params" : {
            "pushType"  : 2,
            "userID"    : userID
        }
    }
}, {
    success: function() {
        response.success();
    },
    error: function(error) {
        response.error(error);
    }
    });

});
</code>```

Thanks for your time and help.

答:
You can join Parse.Session and Parse.Installation with a user pointer as the Session primary key, next "installationId" as the join key.

```<code>var PushSend = function(payload, dbContact) {
    var querySession = new Parse.Query(Parse.Session);
        querySession.equalTo("user", dbContact);
        querySession.descending("updatedAt");

querySession.first({ useMasterKey: true })

.then(function(dbSession) {
    var installId = dbSession.get("installationId");

    var installQuery = new Parse.Query(Parse.Installation);
        installQuery.equalTo("installationId", installId);

        Parse.Push.send( {
            where: installQuery,
            data: {
                alert: payload
            }
        }, { useMasterKey: true} )

        .then(function() {
            // "success"
        }, function(error) {
            // "failed"
        } );
    }, function(error) {
        // "failed"
    } );
}
</code>```

The above cloud function takes as arguments :

the payload text string

a destination contact pointer (you have for example previously queried from Parse.User)

Title: Parse Cloud: Send Push to a single user

Body:
I'm using Parse and I can't make this method to work.

The idea is to send push to a single user with an already known user identifier from any platform within 'Cloud code'.

Queries I've tried without push being delivered to that user (actually no push was delivered to any user)

PFInstallation through the user pointer:

var targetUser = new Parse.User();

targetUser.id = userID;

var query = new Parse.Query(Parse.Installation);

query.equalTo('user', targetUser);

Query in PFUser itself

var query = new Parse.Query(Parse.User);

query.equalTo('objectId', userID);

Full code for the method:

Parse.Cloud.define("sendPushContactUser", function(request, response) {

// Get parameters
var userID       = request.params.userID; // I'm obviously passing this parameter in the method call

// Query
/* ------ query = Any of the above options ------ */

Parse.Push.send({
    where: query,
    data: {
        title   : "New message",
        alert   : "User message",
        badge   : "Increment",
        sound   : "soundNotifUserContact.caf",
        "params" : {
            "pushType"  : 2,
            "userID"    : userID
        }
    }
}, {
    success: function() {
        response.success();
    },
    error: function(error) {
        response.error(error);
    }
    });

});

Thanks for your time and help.

Body:
You can join Parse.Session and Parse.Installation with a user pointer as the Session primary key, next "installationId" as the join key.

var PushSend = function(payload, dbContact) {
    var querySession = new Parse.Query(Parse.Session);
        querySession.equalTo("user", dbContact);
        querySession.descending("updatedAt");

querySession.first({ useMasterKey: true })

.then(function(dbSession) {
    var installId = dbSession.get("installationId");

    var installQuery = new Parse.Query(Parse.Installation);
        installQuery.equalTo("installationId", installId);

        Parse.Push.send( {
            where: installQuery,
            data: {
                alert: payload
            }
        }, { useMasterKey: true} )

        .then(function() {
            // "success"
        }, function(error) {
            // "failed"
        } );
    }, function(error) {
        // "failed"
    } );
}

The above cloud function takes as arguments :

the payload text string

a destination contact pointer (you have for example previously queried from Parse.User)


问:
Flex center vertically and to right horizontally
I would like to achieve this: .right must be aligned vertically to center, but must be placed at the very end of the .wrap just like below.

Here is my code:

.wrap {
  display: flex;
  box-shadow: 0 0 0 1px black;
  height: 400px;
  align-items: center;
}
.wrap > * {
  box-shadow: 0 0 0 1px black;
  padding: 20px;
}
.right {
  align-self: flex-end;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrap">
  <div class="left">1</div>
  <div class="nextToLeft">2</div>
  <div class="right">3</div>
</div></code>```

Codepen

答:
Just add margin-left:auto;</p>

```<code>.right {
  margin-left:auto;
}
</code>```

Body:
I would like to achieve this: .right must be aligned vertically to center, but must be placed at the very end of the .wrap just like below.

Here is my code:

.wrap {
  display: flex;
  box-shadow: 0 0 0 1px black;
  height: 400px;
  align-items: center;
}
.wrap > * {
  box-shadow: 0 0 0 1px black;
  padding: 20px;
}
.right {
  align-self: flex-end;
}

1

2

3

Codepen

Body:
Just add margin-left:auto;

.right {
  margin-left:auto;
}


问:
Why do processors with only AVX out-perform AVX2 processors for many SIMD algorithms?
I've been investigating the benefits of SIMD algorithms in C# and C++, and found that in many cases using 128-bit registers on an AVX processor offers a better improvement than using 256-bit registers on a processor with AVX2, but I don't understand why.

By improvement I mean the speed-up of a SIMD algorithm relative to a non-SIMD algorithm on the same machine.

答:
On an AVX processor, the upper half of the 256 bit registers and floating point units are powered down by the CPU when not executing AVX instructons (VEX encoded opcodes). When code does use AVX instructions, the CPU has to power up the FP units - this takes about 70 microseconds, during which time AVX instructions are actually executed using 128 micro-ops twice.

When AVX instructions haven't been used for about 700 microseconds, the CPU powers down the upper half of the circuitry again.

Now it does this because the upper half of the circuitry consumes power (doh!), and so generates heat (double doh!). This means that the CPU runs hotter when AVX instructions are used. So given that CPUs can "turbo boost" when they have thermal headroom, using AVX instructions reduces this chance, and in fact, the CPU actually reduces the "base clock speed". So if you have, for example, a CPU officially clocked at 2.3GHz that can turbo boost to 2.7, when you start using AVX instructions, the chip is clocked down to 2.1 and boosted to only 2.3, and in extreme cases the base clock may be reduced to 1.9 (see pages 2-4 of this).

At this stage, your CPU is executing ALL instructions about 10-15%, maybe even 20% SLOWER than when not using AVX instructions. If you're doing loads of SIMD operations, the 256 bit wide instructions make this worthwhile. But if you're doing a few AVX instructions, then "normal" code, then a bit of AVX again, then this clock speed penalty will cost more than all the gains you can make from AVX alone.

This can be why 128 bit wide SIMD can run faster than 256 bit wide unless you've got lengthy intensive bursts of SIMD-dominated operations. There is a price to using the rest of the silicon... (or perhaps more accurately, a reward for not using it that we sometimes forget we've been getting).


问:
How to format axis in Python
I'd like to format xaxis as dd:mm HH:MM. My code:

```<code>plt.figure(figsize=(20,10))
plt.plot('a', "r.",data=xxx, markersize=1.5)
plt.axis(["2017-04-24 0:00", "2017-04-24 23:59", 0, 400])
plt.grid(True)
plt.show()
</code>```

My output format is: dd:mm HH. How can I fix it? I don't have any idea;/

答:
You need to add a date formatter to your axis:</p>

```<code>from matplotlib.dates import DateFormatter

# your plot set-up code...
plt.gca().xaxis.set_major_formatter(DateFormatter("%m:%d %H:%M"))
# etc.
</code>```

Title: How to format axis in Python

Body:
I'd like to format xaxis as dd:mm HH:MM. My code:

plt.figure(figsize=(20,10))
plt.plot('a', "r.",data=xxx, markersize=1.5)
plt.axis(["2017-04-24 0:00", "2017-04-24 23:59", 0, 400])
plt.grid(True)
plt.show()

My output format is: dd:mm HH. How can I fix it? I don't have any idea;/

Body:
You need to add a date formatter to your axis:

from matplotlib.dates import DateFormatter

# your plot set-up code...
plt.gca().xaxis.set_major_formatter(DateFormatter("%m:%d %H:%M"))
# etc.


问:
How does a server know which browser or tab I am using?
I had this question for an interview.
Can you tell me how a server know which tab or browser I am using for a specific website?</p>

答:
See this Wikipedia article.

In computing, a user agent is software (a software agent) that is
  acting on behalf of a user. One common use of the term refers to a web
  browser telling a web site information about the browser and operating
  system. This allows the web site to customize content for the
  capabilities of a particular device, but also raises privacy issues.

There are other uses of the term "user agent". For example, an email
  reader is a mail user agent. In many cases, a user agent acts as a
  client in a network protocol used in communications within a
  client–server distributed computing system. In particular, the
  Hypertext Transfer Protocol (HTTP) identifies the client software
  originating the request, using a user-agent header, even when the
  client is not operated by a user. The Session Initiation Protocol
  (SIP) protocol (based on HTTP) followed this usage. In the SIP, the
  term user agent refers to both end points of a communications session.

User agent identification When a software agent operates in a network
  protocol, it often identifies itself, its application type, operating
  system, software vendor, or software revision, by submitting a
  characteristic identification string to its operating peer. In HTTP,
  SIP, and NNTP protocols, this identification is transmitted in a
  header field User-Agent. Bots, such as Web crawlers, often also
  include a URL and/or e-mail address so that the Webmaster can contact
  the operator of the bot.

Use in HTTP In HTTP, the User-Agent string is often used for content
  negotiation, where the origin server selects suitable content or
  operating parameters for the response. For example, the User-Agent
  string might be used by a web server to choose variants based on the
  known capabilities of a particular version of client software. The
  concept of content tailoring is built into the HTTP standard in RFC
  1945 "for the sake of tailoring responses to avoid particular user
  agent limitations.”

The User-Agent string is one of the criteria by which Web crawlers may
  be excluded from accessing certain parts of a Web site using the
  Robots Exclusion Standard (robots.txt file).

As with many other HTTP request headers, the information in the
  "User-Agent" string contributes to the information that the client
  sends to the server, since the string can vary considerably from user
  to user.

Format for human-operated web browsers The User-Agent string format is
  currently specified by section 5.5.3 of HTTP/1.1 Semantics and
  Content. The format of the User-Agent string in HTTP is a list of
  product tokens (keywords) with optional comments. For example, if a
  user's product were called WikiBrowser, their user agent string might
  be WikiBrowser/1.0 Gecko/1.0. The "most important" product component
  is listed first.

The parts of this string are as follows:

product name and version (WikiBrowser/1.0) layout engine and version
  (Gecko/1.0) During the first browser war, many web servers were
  configured to only send web pages that required advanced features,
  including frames, to clients that were identified as some version of
  Mozilla. Other browsers were considered to be older products such as
  Mosaic, Cello or Samba and would be sent a bare bones HTML document.

For this reason, most Web browsers use a User-Agent string value as
  follows:

Mozilla/[version] ([system and browser information]) [platform]
  ([platform details]) [extensions]. For example, Safari on the iPad has
  used the following:

Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us)
  AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405 The components
  of this string are as follows:

Mozilla/5.0: Previously used to indicate compatibility with the
  Mozilla rendering engine. (iPad; U; CPU OS 3_2_1 like Mac OS X;
  en-us): Details of the system in which the browser is running.
  AppleWebKit/531.21.10: The platform the browser uses. (KHTML, like
  Gecko): Browser platform details. Mobile/7B405: This is used by the
  browser to indicate specific enhancements that are available directly
  in the browser or through third parties. An example of this is
  Microsoft Live Meeting which registers an extension so that the Live
  Meeting service knows if the software is already installed, which
  means it can provide a streamlined experience to joining meetings.
  Before migrating to the Chromium code base, Opera was the most widely
  used web browser that did not have the User-Agent string with
  "Mozilla" (instead beginning it with "Opera"). Since July 15, 2013,
  Opera's User-Agent string begins with "Mozilla/5.0" and, to avoid
  encountering legacy server rules, no longer includes the word "Opera"
  (instead using the string "OPR" to denote the Opera version).

Format for automated agents (bots) Automated web crawling tools can
  use a simplified form, where an important field is contact information
  in case of problems. By convention the word "bot" is included in the
  name of the agent[citation needed]. For example:

Googlebot/2.1 (+http://www.google.com/bot.html) Automated agents are
  expected to follow rules in a special file called "robots.txt".

User agent spoofing The popularity of various Web browser products has
  varied throughout the Web's history, and this has influenced the
  design of Web sites in such a way that Web sites are sometimes
  designed to work well only with particular browsers, rather than
  according to uniform standards by the World Wide Web Consortium (W3C)
  or the Internet Engineering Task Force (IETF). Web sites often include
  code to detect browser version to adjust the page design sent
  according to the user agent string received. This may mean that
  less-popular browsers are not sent complex content (even though they
  might be able to deal with it correctly) or, in extreme cases, refused
  all content. Thus, various browsers have a feature to cloak or spoof
  their identification to force certain server-side content. For
  example, the Android browser identifies itself as Safari (among other
  things) in order to aid compatibility.

Other HTTP client programs, like download managers and offline
  browsers, often have the ability to change the user agent string.

Spam bots and Web scrapers often use fake user agents.

At times it has been popular among Web developers to initiate Viewable
  With Any Browser campaigns, encouraging developers to design Web pages
  that work equally well with any browser.

A result of user agent spoofing may be that collected statistics of
  Web browser usage are inaccurate.

User agent sniffing Main article: Browser sniffing The term user agent
  sniffing refers to the practice of Web sites showing different content
  when viewed with a certain user agent. On the Internet, this will
  result in a different site being shown when browsing the page with a
  specific browser. One example of this is Microsoft Exchange Server
  2003's Outlook Web Access feature. When viewed with Internet Explorer
  6 or newer, more functionality is displayed compared to the same page
  in any other browsers. User agent sniffing is now considered poor
  practice, since it encourages browser-specific design and penalizes
  new browsers with unrecognized user agent identifications. Instead,
  the W3C recommends creating HTML markup that is standard, allowing
  correct rendering in as many browsers as possible, and to test for
  specific browser features rather than particular browser versions or
  brands.

Web sites specifically targeted towards mobile phones, like NTT
  DoCoMo's I-Mode or Vodafone's Vodafone Live! portals, often rely
  heavily on user agent sniffing, since mobile browsers often differ
  greatly from each other. Many developments in mobile browsing have
  been made in the last few years,[when?] while many older phones that
  do not possess these new technologies are still heavily used.
  Therefore, mobile Web portals will often generate completely different
  markup code depending on the mobile phone used to browse them. These
  differences can be small, e.g., resizing of certain images to fit
  smaller screens, or quite extensive, e.g., rendering of the page in
  WML instead of XHTML.

Encryption strength notations Web browsers created in the United
  States, such as Netscape Navigator and Internet Explorer, previously
  used the letters U, I, and N to specify the encryption strength in the
  user agent string. Until 1996, when the United States government
  disallowed encryption with keys longer than 40 bits to be exported,
  vendors shipped various browser versions with different encryption
  strengths. "U" stands for "USA" (for the version with 128-bit
  encryption), "I" stands for "International" – the browser has 40-bit
  encryption and can be used anywhere in the world – and "N" stands (de
  facto) for "None" (no encryption). Following the lifting of export
  restrictions, most vendors supported 256-bit encryption.


问:
Error inflating Class ImageView on RecyclerView
I build an app with minimum SDK 15 and target 23, and I have different view in my RecyclerView.
Apps works well on android version => 5.0 but crashes on android version < 5.0 with the following error message

Binary XML file line #159: Error inflating class ImageView
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                                                at com.shixxels.thankgodrichard.spotpopfinal.adapter.RecyclerAdapter.onCreateViewHolder(RecyclerAdapter.java:64)
                                                                                at com.shixxels.thankgodrichard.spotpopfinal.adapter.RecyclerAdapter.onCreateViewHolder(RecyclerAdapter.java:27)
                                                                                at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5833)
                                                                                at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5057)
                                                                                at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4967)
                                                                                at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
                                                                                at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
                                                                                at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
                                                                                at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
                                                                                at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
                                                                                at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
                                                                                at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
                                                                                at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1652)
                                                                                at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
                                                                                at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                                at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1364)
                                                                                at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:852)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1197)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
                                                                                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
                                                                                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
                                                                                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
                                                                                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGr

And below is my the code for my RecyclerAdapter:

```<code>public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> { // line 27

    private static final int Image_digit = 1;
    private static final int Map_digit = 2;
    private static final int Text_digit = 3;
    private Context context;

    private List<FeedAdapter> mDataList;
    private LayoutInflater inflater;

    public RecyclerAdapter(Context context, List<FeedAdapter> data) {
        inflater = LayoutInflater.from(context);
        this.mDataList = data;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {  // Create the Prime and Non-Prime row Layouts

            case Image_digit:

                ViewGroup imageView = (ViewGroup) inflater.inflate(R.layout.list_item, parent, false);
                MyViewHolder_Images holderPrime = new MyViewHolder_Images(imageView);
                return holderPrime;

            case Map_digit:

                ViewGroup mapView = (ViewGroup) inflater.inflate(R.layout.list_item_map, parent, false);
                MyViewHolder_Map holderNonPrime = new MyViewHolder_Map(mapView);
                return holderNonPrime;

            default:

                ViewGroup defaultRow = (ViewGroup) inflater.inflate(R.layout.list_item_text, parent, false); // line 64
                MyViewHolder_Text holderDefault = new MyViewHolder_Text(defaultRow);
                return holderDefault;
        }
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        FeedAdapter current = mDataList.get(position);

        switch (holder.getItemViewType()) {

            case Image_digit:

                MyViewHolder_Images holder_prime = (MyViewHolder_Images) holder;
                holder_prime.setData(current);

                break;

            case Map_digit:

                MyViewHolder_Map holder_not_prime = (MyViewHolder_Map) holder;
                holder_not_prime.setData(current);

                break;
            default:
                MyViewHolder_Text holder_not_text = (MyViewHolder_Text) holder;
                holder_not_text.setData(current);
                break;
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override // This will help us to determine ROW TYPE : i.e. the PRIME or NON-PRIME row.
    public int getItemViewType(int position) {

        FeedAdapter feedAdapter = mDataList.get(position);
        if (feedAdapter.getViewInt() == 1)
            return Image_digit;
        else if (feedAdapter.getViewInt() == 2){
            return Map_digit;
        }
        else if (feedAdapter.getViewInt() == 3){
            return Text_digit;
        }
        else {
            return 0;
        }

    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
        }
    }

    // Holder class for Images rows
    public class MyViewHolder_Images extends MyViewHolder implements View.OnClickListener {

        TextView title;
        ImageView imgThumb, imgRowType, menu;

        public MyViewHolder_Images(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tvTitle);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_row);
            imgRowType = (ImageView) itemView.findViewById(R.id.img_row2);
            menu   = (ImageView) itemView.findViewById(R.id.img_row_delete);
        }

        public void setData(final FeedAdapter current) {
            this.title.setText(current.getTitle());
            this.imgThumb.setImageResource(current.getImageID());
            this.imgRowType.setImageResource(R.drawable.thumb_1_4);
            this.menu.setOnClickListener(MyViewHolder_Images.this);
            this.imgThumb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showImage(current.getImageID());
                }
            });

        }
        @Override
        public void onClick(View v) {
            Log.i("onClick"," i was clicked");
            openDialog();

        }
    }

    // Holder class for maps rows
    public class MyViewHolder_Map extends MyViewHolder implements View.OnClickListener {

        TextView title;
        ImageView imgThumb, imgRowType, menu;

        public MyViewHolder_Map(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tvTitle);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_row);
            imgRowType = (ImageView) itemView.findViewById(R.id.img_row2);
            menu   = (ImageView) itemView.findViewById(R.id.img_row_delete);
        }

        public void setData(final FeedAdapter current) {
            this.title.setText(current.getTitle());
            this.imgThumb.setImageResource(current.getImageID());
            this.imgRowType.setImageResource(R.drawable.thumb_1_4);
            this.menu.setOnClickListener(MyViewHolder_Map.this);
            this.imgThumb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showImage(current.getImageID());
                }
            });

        }
        @Override
        public void onClick(View v) {
            Log.i("onClick","i was clicked");
            openDialog();

        }
    }
    // Holder class for NON-Text rows
    public class MyViewHolder_Text extends MyViewHolder implements View.OnClickListener {

        TextView title;
        ImageView imgThumb, menu;

        public MyViewHolder_Text(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tvTitle);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_row);
            menu   = (ImageView) itemView.findViewById(R.id.img_row_delete);

        }

        public void setData(final FeedAdapter current) {
            this.title.setText(current.getTitle());
            this.imgThumb.setImageResource(current.getImageID());
            this.menu.setOnClickListener(MyViewHolder_Text.this);
            this.imgThumb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showImage(current.getImageID());
                }
            });

        }
        @Override
        public void onClick(View v) {
            Log.i("onClick","i was clicked");
            openDialog();

        }}

    public void openDialog() {
        final Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        LinearLayout.LayoutParams dialogParams = new LinearLayout.LayoutParams(
                400, 256);//set height and width here, ie (width,height)

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View dislogView = inflater
                .inflate(R.layout.feed_menu, null);
        dialog.setContentView(dislogView, dialogParams);
        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(R.id.text);

        TextView dialogButton = (TextView) dialog.findViewById(R.id.report);
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }

    public void showImage(int imageUri) {
        Dialog builder = new Dialog(context);
        builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
        builder.getWindow().setBackgroundDrawable(
                new ColorDrawable(android.graphics.Color.TRANSPARENT));
        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                //nothing;
            }
        });

        ImageView imageView = new ImageView(context);
        imageView.setImageResource(imageUri);
        builder.addContentView(imageView, new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        builder.show();
    }
}
</code>```

list_item_text.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    card_view:cardCornerRadius="5dp">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/img_row"
                android:layout_width="55dp"
                android:layout_height="57.3dp"
                android:scaleType="fitXY"
                android:layout_margin="7dp"
                android:src="@drawable/thumb_1_0"/>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginTop="4dp">
                    <TextView
                        android:id="@+id/tvTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/title"
                        android:textColor="#000000"
                        android:textSize="12sp"
                        android:textStyle="bold"/>
                    <TextView
                        android:id="@+id/tv_user_tag"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/tag"
                        android:textColor="#616161"
                        android:textSize="9sp"
                        android:layout_marginLeft="5dp" />

                </LinearLayout>

                <TextView
                    android:id="@+id/tvDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/description"
                    android:layout_marginTop="2dp"
                    android:layout_marginBottom="2dp"
                    android:textSize="9sp"
                    android:textStyle="italic"/>
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <View
                        android:layout_width="1dp"
                        android:layout_height="fill_parent"
                        android:background="#FF0000FF" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="@string/lorem"
                        android:maxLines="2"
                        android:ellipsize="end"/>

                </LinearLayout>

            </LinearLayout>

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

                <ImageView
                    android:id="@+id/img_row_delete"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_margin="7dp"
                    android:contentDescription="@string/delete_image"
                    android:src="@drawable/more"
                    android:tint="@color/colorPrimary"
                    android:clickable="true" />

            </LinearLayout>

        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="6.3dp"
            android:layout_marginRight="6.3dp"
            android:layout_height="1dp"
            android:background="@color/colorPrimary" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/time_of_post"
                android:text="about 5 min. ago"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="7dp"/>
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="45dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp">

                <ImageView
                    android:layout_width="20dp"
                    android:id="@+id/comment_count_img"
                    android:src="@drawable/comment_count"
                    android:layout_height="20dp"
                    android:layout_marginRight="3dp"
                    android:layout_toLeftOf="@+id/comment_count_no"
                    android:clickable="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/comment_count_no"
                    android:text="10"
                    android:layout_toLeftOf="@+id/comment_like_img"
                    android:layout_marginRight="5dp"/>

                <ImageView
                    android:layout_width="20dp"
                    android:id="@+id/comment_like_img"
                    android:src="@drawable/like_count"
                    android:layout_marginLeft="6.7dp"
                    android:layout_height="20dp"
                    android:layout_toLeftOf="@+id/comment_like_no"
                    android:layout_marginRight="3dp"
                    android:clickable="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/comment_like_no"
                    android:text="10"
                    android:layout_toLeftOf="@+id/comment_dislike_img"
                    android:layout_marginRight="5dp"/>

                <ImageView
                    android:layout_width="20dp"
                    android:id="@+id/comment_dislike_img"
                    android:src="@drawable/thumbs_down"
                    android:layout_height="20dp"
                    android:layout_marginLeft="6.7dp"
                    android:layout_toLeftOf="@+id/comment_dislike_no"
                    android:layout_marginRight="3dp"
                    android:clickable="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/comment_dislike_no"
                    android:text="10"
                    android:layout_alignParentRight="true"/>

            </RelativeLayout>

        </LinearLayout>

    </LinearLayout>
</android.support.v7.widget.CardView>
</code>```

build.gradle

```<code>apply plugin: 'com.android.application'
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.shixxels.thankgodrichard.spotpopfinal"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}
</code>```

答:
If you use vectors icon as background in your ImageView and the version of android is below 5.0, the imageview will cause this crash. Try to use <android.support.v7.widget.AppCompatImageView instead of ImageView and don't forget in your java code to declare and cast you imageview with appCompatImageView as well.
To set the vector as background use this xml attribute: app:srcCompat for choosing a color use android:tint and finally in your gradle file you must add support to vectors:

```<code>android {
    //...
    defaultConfig {
 //...

        vectorDrawables {
            useSupportLibrary = true
        }
    }
</code>```

Body:
I build an app with minimum SDK 15 and target 23, and I have different view in my RecyclerView.
Apps works well on android version => 5.0 but crashes on android version < 5.0 with the following error message

Binary XML file line #159: Error inflating class ImageView
                                                                                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                                                at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                                                at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                                                at com.shixxels.thankgodrichard.spotpopfinal.adapter.RecyclerAdapter.onCreateViewHolder(RecyclerAdapter.java:64)
                                                                                at com.shixxels.thankgodrichard.spotpopfinal.adapter.RecyclerAdapter.onCreateViewHolder(RecyclerAdapter.java:27)
                                                                                at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5833)
                                                                                at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5057)
                                                                                at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4967)
                                                                                at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
                                                                                at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
                                                                                at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
                                                                                at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
                                                                                at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
                                                                                at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
                                                                                at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
                                                                                at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1652)
                                                                                at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
                                                                                at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                                at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1364)
                                                                                at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:852)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1197)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
                                                                                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
                                                                                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGroup.java:4373)
                                                                                at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
                                                                                at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
                                                                                at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
                                                                                at android.view.View.layout(View.java:14008)
                                                                                at android.view.ViewGroup.layout(ViewGr

And below is my the code for my RecyclerAdapter:

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> { // line 27

    private static final int Image_digit = 1;
    private static final int Map_digit = 2;
    private static final int Text_digit = 3;
    private Context context;

    private List<FeedAdapter> mDataList;
    private LayoutInflater inflater;

    public RecyclerAdapter(Context context, List<FeedAdapter> data) {
        inflater = LayoutInflater.from(context);
        this.mDataList = data;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {  // Create the Prime and Non-Prime row Layouts

            case Image_digit:

                ViewGroup imageView = (ViewGroup) inflater.inflate(R.layout.list_item, parent, false);
                MyViewHolder_Images holderPrime = new MyViewHolder_Images(imageView);
                return holderPrime;

            case Map_digit:

                ViewGroup mapView = (ViewGroup) inflater.inflate(R.layout.list_item_map, parent, false);
                MyViewHolder_Map holderNonPrime = new MyViewHolder_Map(mapView);
                return holderNonPrime;

            default:

                ViewGroup defaultRow = (ViewGroup) inflater.inflate(R.layout.list_item_text, parent, false); // line 64
                MyViewHolder_Text holderDefault = new MyViewHolder_Text(defaultRow);
                return holderDefault;
        }
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        FeedAdapter current = mDataList.get(position);

        switch (holder.getItemViewType()) {

            case Image_digit:

                MyViewHolder_Images holder_prime = (MyViewHolder_Images) holder;
                holder_prime.setData(current);

                break;

            case Map_digit:

                MyViewHolder_Map holder_not_prime = (MyViewHolder_Map) holder;
                holder_not_prime.setData(current);

                break;
            default:
                MyViewHolder_Text holder_not_text = (MyViewHolder_Text) holder;
                holder_not_text.setData(current);
                break;
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override // This will help us to determine ROW TYPE : i.e. the PRIME or NON-PRIME row.
    public int getItemViewType(int position) {

        FeedAdapter feedAdapter = mDataList.get(position);
        if (feedAdapter.getViewInt() == 1)
            return Image_digit;
        else if (feedAdapter.getViewInt() == 2){
            return Map_digit;
        }
        else if (feedAdapter.getViewInt() == 3){
            return Text_digit;
        }
        else {
            return 0;
        }

    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
        }
    }

    // Holder class for Images rows
    public class MyViewHolder_Images extends MyViewHolder implements View.OnClickListener {

        TextView title;
        ImageView imgThumb, imgRowType, menu;

        public MyViewHolder_Images(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tvTitle);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_row);
            imgRowType = (ImageView) itemView.findViewById(R.id.img_row2);
            menu   = (ImageView) itemView.findViewById(R.id.img_row_delete);
        }

        public void setData(final FeedAdapter current) {
            this.title.setText(current.getTitle());
            this.imgThumb.setImageResource(current.getImageID());
            this.imgRowType.setImageResource(R.drawable.thumb_1_4);
            this.menu.setOnClickListener(MyViewHolder_Images.this);
            this.imgThumb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showImage(current.getImageID());
                }
            });

        }
        @Override
        public void onClick(View v) {
            Log.i("onClick"," i was clicked");
            openDialog();

        }
    }

    // Holder class for maps rows
    public class MyViewHolder_Map extends MyViewHolder implements View.OnClickListener {

        TextView title;
        ImageView imgThumb, imgRowType, menu;

        public MyViewHolder_Map(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tvTitle);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_row);
            imgRowType = (ImageView) itemView.findViewById(R.id.img_row2);
            menu   = (ImageView) itemView.findViewById(R.id.img_row_delete);
        }

        public void setData(final FeedAdapter current) {
            this.title.setText(current.getTitle());
            this.imgThumb.setImageResource(current.getImageID());
            this.imgRowType.setImageResource(R.drawable.thumb_1_4);
            this.menu.setOnClickListener(MyViewHolder_Map.this);
            this.imgThumb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showImage(current.getImageID());
                }
            });

        }
        @Override
        public void onClick(View v) {
            Log.i("onClick","i was clicked");
            openDialog();

        }
    }
    // Holder class for NON-Text rows
    public class MyViewHolder_Text extends MyViewHolder implements View.OnClickListener {

        TextView title;
        ImageView imgThumb, menu;

        public MyViewHolder_Text(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tvTitle);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_row);
            menu   = (ImageView) itemView.findViewById(R.id.img_row_delete);

        }

        public void setData(final FeedAdapter current) {
            this.title.setText(current.getTitle());
            this.imgThumb.setImageResource(current.getImageID());
            this.menu.setOnClickListener(MyViewHolder_Text.this);
            this.imgThumb.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showImage(current.getImageID());
                }
            });

        }
        @Override
        public void onClick(View v) {
            Log.i("onClick","i was clicked");
            openDialog();

        }}

    public void openDialog() {
        final Dialog dialog = new Dialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        LinearLayout.LayoutParams dialogParams = new LinearLayout.LayoutParams(
                400, 256);//set height and width here, ie (width,height)

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View dislogView = inflater
                .inflate(R.layout.feed_menu, null);
        dialog.setContentView(dislogView, dialogParams);
        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(R.id.text);

        TextView dialogButton = (TextView) dialog.findViewById(R.id.report);
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();
    }

    public void showImage(int imageUri) {
        Dialog builder = new Dialog(context);
        builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
        builder.getWindow().setBackgroundDrawable(
                new ColorDrawable(android.graphics.Color.TRANSPARENT));
        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                //nothing;
            }
        });

        ImageView imageView = new ImageView(context);
        imageView.setImageResource(imageUri);
        builder.addContentView(imageView, new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        builder.show();
    }
}

list_item_text.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    card_view:cardCornerRadius="5dp">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/img_row"
                android:layout_width="55dp"
                android:layout_height="57.3dp"
                android:scaleType="fitXY"
                android:layout_margin="7dp"
                android:src="@drawable/thumb_1_0"/>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginTop="4dp">
                    <TextView
                        android:id="@+id/tvTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/title"
                        android:textColor="#000000"
                        android:textSize="12sp"
                        android:textStyle="bold"/>
                    <TextView
                        android:id="@+id/tv_user_tag"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/tag"
                        android:textColor="#616161"
                        android:textSize="9sp"
                        android:layout_marginLeft="5dp" />

                </LinearLayout>

                <TextView
                    android:id="@+id/tvDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/description"
                    android:layout_marginTop="2dp"
                    android:layout_marginBottom="2dp"
                    android:textSize="9sp"
                    android:textStyle="italic"/>
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <View
                        android:layout_width="1dp"
                        android:layout_height="fill_parent"
                        android:background="#FF0000FF" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dp"
                        android:text="@string/lorem"
                        android:maxLines="2"
                        android:ellipsize="end"/>

                </LinearLayout>

            </LinearLayout>

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

                <ImageView
                    android:id="@+id/img_row_delete"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_margin="7dp"
                    android:contentDescription="@string/delete_image"
                    android:src="@drawable/more"
                    android:tint="@color/colorPrimary"
                    android:clickable="true" />

            </LinearLayout>

        </LinearLayout>

        <View
            android:layout_width="fill_parent"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="6.3dp"
            android:layout_marginRight="6.3dp"
            android:layout_height="1dp"
            android:background="@color/colorPrimary" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/time_of_post"
                android:text="about 5 min. ago"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="7dp"/>
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="45dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="3dp">

                <ImageView
                    android:layout_width="20dp"
                    android:id="@+id/comment_count_img"
                    android:src="@drawable/comment_count"
                    android:layout_height="20dp"
                    android:layout_marginRight="3dp"
                    android:layout_toLeftOf="@+id/comment_count_no"
                    android:clickable="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/comment_count_no"
                    android:text="10"
                    android:layout_toLeftOf="@+id/comment_like_img"
                    android:layout_marginRight="5dp"/>

                <ImageView
                    android:layout_width="20dp"
                    android:id="@+id/comment_like_img"
                    android:src="@drawable/like_count"
                    android:layout_marginLeft="6.7dp"
                    android:layout_height="20dp"
                    android:layout_toLeftOf="@+id/comment_like_no"
                    android:layout_marginRight="3dp"
                    android:clickable="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/comment_like_no"
                    android:text="10"
                    android:layout_toLeftOf="@+id/comment_dislike_img"
                    android:layout_marginRight="5dp"/>

                <ImageView
                    android:layout_width="20dp"
                    android:id="@+id/comment_dislike_img"
                    android:src="@drawable/thumbs_down"
                    android:layout_height="20dp"
                    android:layout_marginLeft="6.7dp"
                    android:layout_toLeftOf="@+id/comment_dislike_no"
                    android:layout_marginRight="3dp"
                    android:clickable="true" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/comment_dislike_no"
                    android:text="10"
                    android:layout_alignParentRight="true"/>

            </RelativeLayout>

        </LinearLayout>

    </LinearLayout>
</android.support.v7.widget.CardView>

build.gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.shixxels.thankgodrichard.spotpopfinal"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

Body:
If you use vectors icon as background in your ImageView and the version of android is below 5.0, the imageview will cause this crash. Try to use <android.support.v7.widget.AppCompatImageView instead of ImageView and don't forget in your java code to declare and cast you imageview with appCompatImageView as well.
To set the vector as background use this xml attribute: app:srcCompat for choosing a color use android:tint and finally in your gradle file you must add support to vectors:

android {
    //...
    defaultConfig {
 //...

        vectorDrawables {
            useSupportLibrary = true
        }
    }


问:
How can I fetch high-resolution google map satellite image using Python?
I am using Google map to capture satellite images using Python.
 I followed the post: http://stackoverflow.com/questions/7490491/capture-embedded-google-map-image-with-python-without-using-a-browser. However, compared to the  view directly from browser, the images from Python have lower resolution.

For example, at a certain location, what I fetched from Python looks like

But the view of the same location from browser has much higher resolution (though not at the exactly same zoom range):

The Google map API has parameters as follows:

```<code>'center': position,
'zoom': str(zoom),
'size': '%dx%d' % (largura, alturaplus),
'maptype': 'satellite',
'sensor': 'false',
'scale': scale
</code>```

Is there parameter to tune the resolution?
  A ton of thanks!!

答:
I'm afraid the imagery scraping might be against the Terms of Service of Google Maps APIs.

Particularly section 10.1 (a) says

No access to APIs or Content except through the Service. You will not access the Maps API(s) or the Content except through the Service. For example, you must not access map tiles or imagery through interfaces or channels (including undocumented Google interfaces) other than the Maps API(s).

section 10.5 (d) says

No caching or storage. You will not pre-fetch, cache, index, or store any Content to be used outside the Service, except that you may store limited amounts of Content solely for the purpose of improving the performance of your Maps API Implementation due to network latency (and not for the purpose of preventing Google from accurately tracking usage)

https://developers.google.com/maps/terms?#10-license-restrictions

Body:
I am using Google map to capture satellite images using Python.
 I followed the post: http://stackoverflow.com/questions/7490491/capture-embedded-google-map-image-with-python-without-using-a-browser. However, compared to the  view directly from browser, the images from Python have lower resolution.

For example, at a certain location, what I fetched from Python looks like

But the view of the same location from browser has much higher resolution (though not at the exactly same zoom range):

The Google map API has parameters as follows:

'center': position,
'zoom': str(zoom),
'size': '%dx%d' % (largura, alturaplus),
'maptype': 'satellite',
'sensor': 'false',
'scale': scale

Is there parameter to tune the resolution?
  A ton of thanks!!


问:
SQL Server and asp.net application security models / best practice
For my asp.net web applications against sql server(at least the ones that require a logon to access) I generally implement security as follows:

I generally roll my own user signup, user login pages and keep a userid and an encrypted password in an sql server and validate the login against that table - I also provide for forgotten passwords, 'send me my password', email verification to activate accounts etc all thru custom code.

Once the user has been validated by the app (and lets assume that all users have the same privileges), I generally use a utility logonid to let asp.net talk to sql server, so in other words I only need to create a single logon id per application, and since 100% of all data access is done thru stored procedures, I need only grant access to a single user to execute stored procedures, and no other work is required on sql server. Each application has its own database, and the logon for that app can only access that database.

All this works perfectly well for me, the only negative of this is that it would be nice to be able to setup a trace in sql server and see the userid and the procs that are being called, but since all users are 'talking' to the database thru a single database logon, this can't happen.

So, two part question:

1) Are there security models are you folks using that I should consider? Its easy to always do the same thing over and over, - especially since it works - but are there other models that would work better or that I should consider? Is it recommended practice that all database access from an asp.net app would all share a single database login? or is this considered bad practice? and if so, why?

2) Assuming I stick with my model, is there a way to allow for the application login id to be seen in the sql trace window? It would be nice to see the sp's being called and the user id of the person logged into the system (not the database login).

答:
1) It is recommended that your web application use a single login to the database typically. If you don't you are going to be forced to impersonate your caller, which is typcially not recommended, and it doesn't scale very well. You should not use a different connection string for each user. For example using SQL Authentication for each user is a bad idea. It will make connection polling ineffective.

2) You could do this by modifying the connection string but that would make connection pollign ineffective.

OwnerDisplayName: E.J. Brennan

ContentLicense: CC BY-SA 2.5

OwnerDisplayName: Josh


问:
Is My Page Being Loaded from the Browser Cache?
I have a "new items" badge on a page that I want to update immediately the page is loaded from the cache (i.e. when hitting "Back" or "Forward" to return to this page). What is the best way to accomplish this?

The setup is pretty simple. The layout for the app looks for new items every 8 seconds, and updates the badge + list of items accordingly.

```<code>$(function() {
    setInterval( App.pollForNewItems, 8000 );
});
</code>```

When someone navigates away from this page to look at the details of an item, a lot can happen. Things are "new" until any user has viewed them, and the app will likely have several user using it simultaneously (the kind of workflow used for a call center or support tickets).

To make sure that the badges are always up to date, I have:

```<code>$(window).bind('focus load', function ( event ) {
    App.pollForNewItems();
});
</code>```

..And though this works, polling for new items on 'load' is only useful when the page is loaded from the cache. Is there a reliable cross-browser way to tell if a page is being loaded from the cache?

答:
Personally, I would set data attribute containing the item id for each element.

I.e.

```<code><ul>
  <li data-item-id="123">Some item.</li>
  <li data-item-id="122">Some other item.</li>
  <li data-item-id="121">Another one..</li>
</ul>
</code>```

Your App.pollForNewItems function would grab the data-item-id attribute of the first element (if newest are first) and send it to the server with your original request.

The server would then only return the items WHERE id > ... which you can then prepend them to the list.

I'm still confused as to why you want to know if the browser has a cached version of the page.

Also, is there a reason for binding to load instead of ready?

Christian

Body:
I have a "new items" badge on a page that I want to update immediately the page is loaded from the cache (i.e. when hitting "Back" or "Forward" to return to this page). What is the best way to accomplish this?

The setup is pretty simple. The layout for the app looks for new items every 8 seconds, and updates the badge + list of items accordingly.

$(function() {
    setInterval( App.pollForNewItems, 8000 );
});

When someone navigates away from this page to look at the details of an item, a lot can happen. Things are "new" until any user has viewed them, and the app will likely have several user using it simultaneously (the kind of workflow used for a call center or support tickets).

To make sure that the badges are always up to date, I have:

$(window).bind('focus load', function ( event ) {
    App.pollForNewItems();
});

..And though this works, polling for new items on 'load' is only useful when the page is loaded from the cache. Is there a reliable cross-browser way to tell if a page is being loaded from the cache?

Body:
Personally, I would set data attribute containing the item id for each element.

I.e.

<ul>
  <li data-item-id="123">Some item.</li>
  <li data-item-id="122">Some other item.</li>
  <li data-item-id="121">Another one..</li>
</ul>

Your App.pollForNewItems function would grab the data-item-id attribute of the first element (if newest are first) and send it to the server with your original request.

The server would then only return the items WHERE id > ... which you can then prepend them to the list.

I'm still confused as to why you want to know if the browser has a cached version of the page.

Also, is there a reason for binding to load instead of ready?

Christian


问:
Setting a connection to an access database in VBA crashes excel
This is the code I use to open a connection to an access database from excel.  It used to work for more than a year.

```<code>Set dbname = New ADODB.Connection
theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB
With dbname
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .Open theconnection
End With
</code>```

By trial an error I've come to the conclusion that this line is causing the problem.

```<code>Set dbname= New ADODB.Connection
</code>```

The problem began after an automatic update of my PC
My Excel version 2016 MSO (16.0.7726.1036) 32-bit

Please let me know if you have run also into this problem, and if you know any fix or workaround.

答:
try to uncheck your 'ActiveX Data Objects' references and add them back:

 Tools - References

or

use object to define a database:

```<code> Dim dbname As Object
 Set dbname = CreateObject("ADODB.Connection")
</code>```

or

if you create connection variable like this:

```<code>Dim con as New ADODB.Connection
</code>```

change it to:

```<code>Dim con as ADODB.Connection
Set con = New ADODB.Connection
</code>```

Body:
This is the code I use to open a connection to an access database from excel.  It used to work for more than a year.

Set dbname = New ADODB.Connection
theconnection = "//xxx.sharepoint.com/sites" & Application.PathSeparator & TARGET_DB
With dbname
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .Open theconnection
End With

By trial an error I've come to the conclusion that this line is causing the problem.

Set dbname= New ADODB.Connection

The problem began after an automatic update of my PC
My Excel version 2016 MSO (16.0.7726.1036) 32-bit

Please let me know if you have run also into this problem, and if you know any fix or workaround.

Body:
try to uncheck your 'ActiveX Data Objects' references and add them back:

 Tools - References

or

use object to define a database:

 Dim dbname As Object
 Set dbname = CreateObject("ADODB.Connection")

or

if you create connection variable like this:

Dim con as New ADODB.Connection

change it to:

Dim con as ADODB.Connection
Set con = New ADODB.Connection


问:
How to select a Top 1 from another Top-selection?
In my database I'm filtering my records using a Top 101. My goal is to get the last Id which is being returned in my filtered list.

Is there a way to get this in a single statement for use in my SQL Command?

```<code>SELECT TOP 101 Id FROM Messages WHERE Validation = 2 AND Shown > 0 ORDER BY Id DESC
</code>```

And from this list I need the last entry.

How can I get this in a single query?

Thank you.

答:
Assuming that your code returns at least 101 rows, then you can use OFFSET/FETCH:

```<code>SELECT Id
FROM Messages
WHERE Validation = 2 AND Shown > 0
ORDER BY Id DESC
OFFSET 100
FETCH NEXT 1 ROW ONLY;
</code>```

This ANSI-standard construct was introduced in SQL Server 2012.

Body:
In my database I'm filtering my records using a Top 101. My goal is to get the last Id which is being returned in my filtered list.

Is there a way to get this in a single statement for use in my SQL Command?

SELECT TOP 101 Id FROM Messages WHERE Validation = 2 AND Shown > 0 ORDER BY Id DESC

And from this list I need the last entry.

How can I get this in a single query?

Thank you.

Body:
Assuming that your code returns at least 101 rows, then you can use OFFSET/FETCH:

SELECT Id
FROM Messages
WHERE Validation = 2 AND Shown > 0
ORDER BY Id DESC
OFFSET 100
FETCH NEXT 1 ROW ONLY;

This ANSI-standard construct was introduced in SQL Server 2012.