问:
JSON Array of objects to plain old java object
this is my first time making an external api call in Java, so please bear with me as I'm not very experienced. I got the http request working and got a response, but now I need to parse it.

I'm trying to convert a json array to java objects. I understand the gist of it, but all examples I've seen don't apply to my issue.

I need the 'entities' objects from the json string. The details (which are an array, too) can contain any key/value pair, so I was thinking of putting that in a hashmap in each Entity object. I've tried the gson library, but I can't find any gson example that goes deeper than a single dimensional json array.

I realize this is kind of a broad question, and I don't expect anyone to deliver me a working solution, but a few tips or a link to a relevant guide would go a long way. :)

```<code>{
   "return": {
      "entities": [
         {
            "id": 2385,
            "details": [
               {
                  "name": "Other Known Name",
                  "value": "John Wick",
                  "match": false
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=2385"
         },
         {
            "id": 2384,
            "details": [
               {
                  "name": "Discord ID",
                  "value": "159985870458322944",
                  "match": false
               },
               {
                  "name": "SteamID64",
                  "value": "76561197991558078",
                  "match": true
               },
               {
                  "name": "SteamVanity",
                  "value": "test",
                  "match": false
               },
               {
                  "name": "PS4",
                  "value": "John_S",
                  "match": false
               },
               {
                  "name": "XBox",
                  "value": "John S",
                  "match": false
               },
               {
                  "name": "Email",
                  "value": "john_smith@gmail.com",
                  "match": true
               },
               {
                  "name": "Comment",
                  "value": "Test user",
                  "match": false
               },
               {
                  "name": "Other Known Name",
                  "value": "Jonathan",
                  "match": false
               },
               {
                  "name": "Reddit",
                  "value": "/u/johns",
                  "match": true
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=2384"
         },
         {
            "id": 1680,
            "details": [
               {
                  "name": "Other Known Name",
                  "value": "Johny",
                  "match": false
               },
               {
                  "name": "SteamID64",
                  "value": "76561198213003675",
                  "match": true
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=1680"
         },
         {
            "id": 1689,
            "details": [
               {
                  "name": "Other Known Name",
                  "value": "JohnnyPeto",
                  "match": false
               },
               {
                  "name": "SteamID64",
                  "value": "76561198094228192",
                  "match": true
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=1689"
         }
      ],
      "notice": "Showing 4 out of 4 matches."
   }
}
</code>```

答:
If I were you, I'd use Jackson, not GSON. It's specialized on JavaBeans-style mapping. Write classes like this:

```<code>public class Detail{
    private String name;
    private String value;
    private boolean match;
    // + getters / setters
}

public class Entity{
    private int id;
    private List<Detail> details;
    private String link;
    private List<String> proofs;
    // you don't have any example data for this, so I'm assuming strings
    // + getters / setters
}

public class Result{
    private List<Entity> entities;
    private String notice;
    // + getters / setters
}
</code>```

and do the conversion with something like

```<code>Result result = new ObjectMapper().readValue(json, Result.class);
</code>```

Body:
this is my first time making an external api call in Java, so please bear with me as I'm not very experienced. I got the http request working and got a response, but now I need to parse it.

I'm trying to convert a json array to java objects. I understand the gist of it, but all examples I've seen don't apply to my issue.

I need the 'entities' objects from the json string. The details (which are an array, too) can contain any key/value pair, so I was thinking of putting that in a hashmap in each Entity object. I've tried the gson library, but I can't find any gson example that goes deeper than a single dimensional json array.

I realize this is kind of a broad question, and I don't expect anyone to deliver me a working solution, but a few tips or a link to a relevant guide would go a long way. :)

{
   "return": {
      "entities": [
         {
            "id": 2385,
            "details": [
               {
                  "name": "Other Known Name",
                  "value": "John Wick",
                  "match": false
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=2385"
         },
         {
            "id": 2384,
            "details": [
               {
                  "name": "Discord ID",
                  "value": "159985870458322944",
                  "match": false
               },
               {
                  "name": "SteamID64",
                  "value": "76561197991558078",
                  "match": true
               },
               {
                  "name": "SteamVanity",
                  "value": "test",
                  "match": false
               },
               {
                  "name": "PS4",
                  "value": "John_S",
                  "match": false
               },
               {
                  "name": "XBox",
                  "value": "John S",
                  "match": false
               },
               {
                  "name": "Email",
                  "value": "john_smith@gmail.com",
                  "match": true
               },
               {
                  "name": "Comment",
                  "value": "Test user",
                  "match": false
               },
               {
                  "name": "Other Known Name",
                  "value": "Jonathan",
                  "match": false
               },
               {
                  "name": "Reddit",
                  "value": "/u/johns",
                  "match": true
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=2384"
         },
         {
            "id": 1680,
            "details": [
               {
                  "name": "Other Known Name",
                  "value": "Johny",
                  "match": false
               },
               {
                  "name": "SteamID64",
                  "value": "76561198213003675",
                  "match": true
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=1680"
         },
         {
            "id": 1689,
            "details": [
               {
                  "name": "Other Known Name",
                  "value": "JohnnyPeto",
                  "match": false
               },
               {
                  "name": "SteamID64",
                  "value": "76561198094228192",
                  "match": true
               }
            ],
            "proofs": [],
            "link": "http://domain.gg/users?id=1689"
         }
      ],
      "notice": "Showing 4 out of 4 matches."
   }
}

Body:
If I were you, I'd use Jackson, not GSON. It's specialized on JavaBeans-style mapping. Write classes like this:

public class Detail{
    private String name;
    private String value;
    private boolean match;
    // + getters / setters
}

public class Entity{
    private int id;
    private List<Detail> details;
    private String link;
    private List<String> proofs;
    // you don't have any example data for this, so I'm assuming strings
    // + getters / setters
}

public class Result{
    private List<Entity> entities;
    private String notice;
    // + getters / setters
}

and do the conversion with something like

Result result = new ObjectMapper().readValue(json, Result.class);


来源: stackexchange

问:
Linq to objects List in list
I have a list of movies

```<code>List<Movie> MovieList
</code>```

and I have a list of selected categories

```<code>List<string> SelCat
</code>```

And say I want to select from the movie list where it matches 2 categories, like the SQL statement below:

SELECT * FROM MovieList WHERE MovieList.Category = 'Action' AND MovieList.Category = 'Drama'

I can get kinda close with linq like so:

var q = (from b in MovieList where b.Categories.Any(p=> SelCat.Contains(p)) select b);

But it acts like an OR query, not an AND. I want it to select all movies that have a category of action and drama.

BTW: Movie.Categories is a List of string. AND Movie.Categories must contain items in the SelCat.

How do I achieve this with Linq to Objects?

答:
If you want the movie to match all of the interesting categories (i.e. all of the categories in SelCat are present in movie.Categories), you can do:

```<code>MovieList.Where(movie => !SelCat.Except(movie.Categories).Any());
</code>```

On the other hand, if you want the movie to match atleast 2 of the selected categories:

```<code>MovieList.Where(movie => SelCat.Intersect(movie.Categories).Count() >= 2);
</code>```

ContentLicense: CC BY-SA 2.5

Title: Linq to objects List in list

Body:
I have a list of movies

List<Movie> MovieList

and I have a list of selected categories

List<string> SelCat

And say I want to select from the movie list where it matches 2 categories, like the SQL statement below:

SELECT * FROM MovieList WHERE MovieList.Category = 'Action' AND MovieList.Category = 'Drama'

I can get kinda close with linq like so:

var q = (from b in MovieList where b.Categories.Any(p=> SelCat.Contains(p)) select b);

But it acts like an OR query, not an AND. I want it to select all movies that have a category of action and drama.

BTW: Movie.Categories is a List of string. AND Movie.Categories must contain items in the SelCat.

How do I achieve this with Linq to Objects?

Body:
If you want the movie to match all of the interesting categories (i.e. all of the categories in SelCat are present in movie.Categories), you can do:

MovieList.Where(movie => !SelCat.Except(movie.Categories).Any());

On the other hand, if you want the movie to match atleast 2 of the selected categories:

MovieList.Where(movie => SelCat.Intersect(movie.Categories).Count() >= 2);


问:
gfortran error: unexpected element '\' in format string at (1)
I have a project written in VS2010 with Intel Visual Fortran. I have a dump subroutine to write a 2D matrix into file:

```<code>subroutine Dump2D(Name,Nx,Ny,Res)
    implicit none
    integer i,j,Nx,Ny
    real(8) :: Res(Nx,Ny)
    character(len=30) name,Filename
    logical alive
    write(filename,*) trim(Name),".dat"
    Write(*,*) "Saving ",trim(Name)," Please wait..."
    open (10,file=filename)
    do i=1,Ny
           Write(10,FMt="(D21.13\)")   (Res(j,i),j=1,Nx)
           Write(10,*)
    end do
    close(10)
    Write(*,*) "Save ",trim(Name),"Complete!"
    return
end subroutine Dump2D
</code>```

It is ok to compile and run. But when I compile in emacs using gfortran it gives me the error:

I think it's because the gfortran doesn't recognize \ in a format for a write command. How do I fix this problem?

```<code>                Write(10,FMt="(D21.13\)") (Res(j,i),j=1,Nx)
                                   1
Error: Unexpected element '\' in format string at (1)
</code>```

答:
The edit descriptor \ relates to backslash editing.  This is a non-standard extension provided by the Intel compiler (and perhaps others).  It is not supported by gfortran.

Such backslash editing is intended to affect carriage control.  Much as in this answer such an effect can be handled with the (standard) non-advancing output.1

As you simply want to output each column of a matrix to a record/line you needn't bother with this effort.2  Instead (as you'll see in many other questions):

```<code>do i=1,Ny
   write(10,fmt="(*(D21.13))") Res(:,i)
end do
</code>```

There are also other approaches which a more general search will find.

1 The Intel compiler treats \ and $ in the same way.

2 There are subtle aspects of \, but I'll assume you don't care about those.

ContentLicense: CC BY-SA 3.0

Body:
I have a project written in VS2010 with Intel Visual Fortran. I have a dump subroutine to write a 2D matrix into file:

subroutine Dump2D(Name,Nx,Ny,Res)
    implicit none
    integer i,j,Nx,Ny
    real(8) :: Res(Nx,Ny)
    character(len=30) name,Filename
    logical alive
    write(filename,*) trim(Name),".dat"
    Write(*,*) "Saving ",trim(Name)," Please wait..."
    open (10,file=filename)
    do i=1,Ny
           Write(10,FMt="(D21.13\)")   (Res(j,i),j=1,Nx)
           Write(10,*)
    end do
    close(10)
    Write(*,*) "Save ",trim(Name),"Complete!"
    return
end subroutine Dump2D

It is ok to compile and run. But when I compile in emacs using gfortran it gives me the error:

I think it's because the gfortran doesn't recognize \ in a format for a write command. How do I fix this problem?

                Write(10,FMt="(D21.13\)") (Res(j,i),j=1,Nx)
                                   1
Error: Unexpected element '\' in format string at (1)

Body:
The edit descriptor \ relates to backslash editing.  This is a non-standard extension provided by the Intel compiler (and perhaps others).  It is not supported by gfortran.

Such backslash editing is intended to affect carriage control.  Much as in this answer such an effect can be handled with the (standard) non-advancing output.1

As you simply want to output each column of a matrix to a record/line you needn't bother with this effort.2  Instead (as you'll see in many other questions):

do i=1,Ny
   write(10,fmt="(*(D21.13))") Res(:,i)
end do

There are also other approaches which a more general search will find.

1 The Intel compiler treats \ and $ in the same way.

2 There are subtle aspects of \, but I'll assume you don't care about those.


问:
C# Linq .Find() return many results
I am trying to create a simple search function for my application. I am using Linq's .Find() method to search through a list of objects. It all works very well, the only problem I'm currently having is that I only get the first result. I know for a fact that there are more than one results to be had, but I only get one. Here is my code:

```<code>case 5: {
    //Search for Price

    Product searchResult = tempList.Find(x => x.getPrice() == searchPrice);
    if (searchResult != null) {
        //Present Result
        searchTable.Rows.Add(convertIDValue(searchResult.getProductID()), searchResult.getTitle(), searchResult.getYear(), searchResult.getAmount(), searchResult.getPrice());
    }
    else {
        MessageBox.Show("No product with that price", "0 results");
    }

    break;
}
</code>```

I thought I could change Product searchResult into List<Product> searchResults in order to get a list of Products, then loop through that list. But that gave me an error saying:

Cannot implicitly convert type '.Product' to 'System.Collections.Generic.List<.Product>

Is there any way to get Linq's .Find() to return multiple results?

答:
There is a FindAll method for that purpose:

```<code>List<Product> products = tempList.FindAll(x => x.getPrice() == searchPrice);
</code>```

Title: C# Linq .Find() return many results

Body:
I am trying to create a simple search function for my application. I am using Linq's .Find() method to search through a list of objects. It all works very well, the only problem I'm currently having is that I only get the first result. I know for a fact that there are more than one results to be had, but I only get one. Here is my code:

case 5: {
    //Search for Price

    Product searchResult = tempList.Find(x => x.getPrice() == searchPrice);
    if (searchResult != null) {
        //Present Result
        searchTable.Rows.Add(convertIDValue(searchResult.getProductID()), searchResult.getTitle(), searchResult.getYear(), searchResult.getAmount(), searchResult.getPrice());
    }
    else {
        MessageBox.Show("No product with that price", "0 results");
    }

    break;
}

I thought I could change Product searchResult into List<Product> searchResults in order to get a list of Products, then loop through that list. But that gave me an error saying:

Cannot implicitly convert type '.Product' to 'System.Collections.Generic.List<.Product>

Is there any way to get Linq's .Find() to return multiple results?

Body:
There is a FindAll method for that purpose:

List<Product> products = tempList.FindAll(x => x.getPrice() == searchPrice);


问:
c# getting content from url after hitting a button
I want to retrieve content from a website. Until now I did it using the following code :

```<code>static String getContent(String url)
{
    WebClient client = new WebClient();
    client.Encoding = System.Text.Encoding.UTF8;

    return client.DownloadString(url);
}
</code>```

Now, I have a page with buttons that lead to the content I actually want.
However, they don't have a full url as link, but only something like javascript:check_eingabe('0');.

How can I proceed to that target and get the information?

答:
There are 3 things here

You can not make a JavaScript method call from WebClient for the you may have to you web browser control and click button from code.

inspect the JavaScript method and inside the method if there's an web call like Ajax call if so you use that to get content.

If the JavaScript method just changes the display of content you want then it will be there in the page.

Body:
I want to retrieve content from a website. Until now I did it using the following code :

static String getContent(String url)
{
    WebClient client = new WebClient();
    client.Encoding = System.Text.Encoding.UTF8;

    return client.DownloadString(url);
}

Now, I have a page with buttons that lead to the content I actually want.
However, they don't have a full url as link, but only something like javascript:check_eingabe('0');.

How can I proceed to that target and get the information?


问:
Theoretical minimum round-trip-time for a packet to travel over/under the North Atlantic Sea?
I'm doing some performance tuning and capacity planning for a low-latency application and have the following question:

What is the theoretical minimum round-trip time for a packet sent between a host in London and one in New York connected via optical fiber?

答:
Just ask Hibernia, they currently are at 72ms and presently looking at 60ms by mid-2012.

http://www.a-teamgroup.com/article/andrews-blog-laying-cable-and-the-low-latency-gauntlet/


问:
Linking shared libraries with gcc on Linux
I need to compile and, most importantly, link a C program that uses a proprietary function present in a shared library file. Because of lack of communication with the previous development team, there is no proper documentation. I declared a function prototype (because I know the number and type of arguments):

```<code>int CustomFunction(unsigned char *in, int size);
</code>```

Since that function name can be grepped from /customlibs/libcustom.so, I tried to compile the code and link it like this:

```<code>gcc -L/customlibs testing.c -o testing -lcustom
</code>```

Which throws a few error messages looking like this:

```<code>/customlibs/libcustom.so: undefined reference to `AnotherCustomFunction'
</code>```

Obviously, I need to tell linker to include other libraries as well, and, to make things worse, they need to be in certain order. I tried exporting LD_LIBRARY_PATH, using -Wl,-rpath=, -Wl,--no-undefined and -Wl,--start-group. Is there an easy way to give the linker all the .so files without the proper order?

答: I found the solution (or a workaround) to my problem: adding -Wl,--warn-unresolved-symbols, which turns errors to warnings. Note that this works only if you are ABSOLUTELY certain your function does not depend on the symbols mentioned in undefined refernce to: messages.

Body:
I need to compile and, most importantly, link a C program that uses a proprietary function present in a shared library file. Because of lack of communication with the previous development team, there is no proper documentation. I declared a function prototype (because I know the number and type of arguments):

int CustomFunction(unsigned char *in, int size);

Since that function name can be grepped from /customlibs/libcustom.so, I tried to compile the code and link it like this:

gcc -L/customlibs testing.c -o testing -lcustom

Which throws a few error messages looking like this:

/customlibs/libcustom.so: undefined reference to `AnotherCustomFunction'

Obviously, I need to tell linker to include other libraries as well, and, to make things worse, they need to be in certain order. I tried exporting LD_LIBRARY_PATH, using -Wl,-rpath=, -Wl,--no-undefined and -Wl,--start-group. Is there an easy way to give the linker all the .so files without the proper order?


问:
vuejs appending a binded url
In my vue template I have

```<code><img class="workimg" v-bind:src="item.imagemobile">
</code>```

I want to try and append it to

```<code><img class="workimg" v-bind:src="/featured/item.imagemobile">
</code>```

The syntax breaks the app, is this possible?

答:
When you use v-bind, the value must be a JavaScript expression.

```<code><img class="workimg" v-bind:src="`/featured/${item.imagemobile}`">
</code>```

or

```<code><img class="workimg" v-bind:src="'/featured/' + item.imagemobile">
</code>```

should work.

Title: vuejs appending a binded url

Body:
In my vue template I have

I want to try and append it to

The syntax breaks the app, is this possible?

Body:
When you use v-bind, the value must be a JavaScript expression.

<img class="workimg" v-bind:src="`/featured/${item.imagemobile}`">

or

<img class="workimg" v-bind:src="'/featured/' + item.imagemobile">

should work.


问:
Fortran90 valgrind output help. Unexplained error happening at the beginning of code execution
I am currently writing a large non-linear solver for a nasty partial differential equation in Fortran90 as part of my research. I have run into an issue where I believe a memory corruption issue is plaguing my code and I am trying to track it down; to do so, I elected to use valgrind as this has worked for me in the past. Unfortunately, I am getting an unexplained error message that is occurring right at the beginning of my code execution, please see below:

```<code>==18257== Memcheck, a memory error detector
==18257== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==18257== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==18257== Command: ./JFNKsolver
==18257==
==18257== Conditional jump or move depends on uninitialised value(s)
==18257==    at 0x6F7F7D: __intel_sse2_strcpy (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x6AA1C0: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x67EF6C: for__open_default (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x69878D: for_write_seq_lis (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
==18257==    by 0x402DAD: main (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==  Uninitialised value was created by a stack allocation
==18257==    at 0x6AA07D: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==
==18257== Conditional jump or move depends on uninitialised value(s)
==18257==    at 0x6F7F7D: __intel_sse2_strcpy (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x677DA5: for__add_to_lf_table (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x6ABA13: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x67EF6C: for__open_default (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x69878D: for_write_seq_lis (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
==18257==    by 0x402DAD: main (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==  Uninitialised value was created by a stack allocation
==18257==    at 0x6AA07D: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==
</code>```

I got this error by running my code with valgrind --track-origins=yes ./JFNKsolver.

Now I know that, typically, these errors mean that there is an uninitialized variable being used somewhere, but the strange thing is that it is appearing before anything is really happening in my code and it points via by 0x65BA69: MAIN__ (JFNKsolver.f90:146) to a test print statement, i.e. print *, "Test" in the code below.

```<code>program JFNKsolver

use modelparams
use initialization
use forcing
use domain_routines
use solver_routines
use var_routines
use csv_file
use validation_routines
use validsoln_routines

implicit none

real(kind = dbl_kind) :: &
    time,       &
    norm_test

integer(kind = int_kind) :: &
    nxT, nyT,   &
    nxN, nyN,   &
    nxU, nyU,   &
    nxV, nyV,   &
    nt,         &
    nU_pnts,    &
    nV_pnts,    &
    nT_pnts,    &
    nN_pnts,    &
    nHT_pnts,   &
    nHN_pnts,   &
    si,         &
    tmp_size,   &
    i, j, ij

integer(kind = int_kind), allocatable, dimension (:) ::  &
    indxUi,     indxUj,         &
    indxVi,     indxVj,         &
    indxTi,     indxTj,         &
    indxNi,     indxNj,         &
    haloTi,     haloTj,         &
    haloNi,     haloNj

real(kind = dbl_kind), allocatable, dimension (:) :: &
    Au,         res_NL,     u_update,       &
    b,          b_0,        vpb_forc

integer(kind = int_kind), allocatable, dimension (:,:,:) :: &
    ulmsk,      vlmsk,      &
    uimsk,      vimsk,      &
    Timsk,      Nimsk,      &
    Tlmsk,      Nlmsk

real(kind = dbl_kind), allocatable, dimension (:,:) :: &
    ugrid,      vgrid,                              &
    uResgrid,   vResgrid,                           &
    uocn_u,     uocn_v,                             &
    vocn_u,     vocn_v,                             &
    uwnd_u,     uwnd_v,                             &
    vwnd_u,     vwnd_v,                             &
    h_u,        h_v,        h_T,                    &
                            A_T,                    &
                            P_T,        P_N,        &
                            zeta_T,     zeta_N,     &
                            eta_T,      eta_N,      &
    Cw_u,   Cw_v,                                   &
                            dist_T,     dist_N,     &
                            dist_gx_T,              &
                            dist_gy_T

print *, "Test"
</code>```

Note that I have removed comments to clean this up and the kind variables are initialized in the modelparams module. Can anyone provide some insight into what might be causing this? Could it be linked to the modules that I am using via the use statements? I originally thought this was a problem with valgrind but now that I'm seeing the effects of memory corruption, and the fact that this is the only error I'm seeing, I've become wary of it.

Note: the reason I believe there is a memory corruption issue is because I am seeing a change in my solver's behaviour just by the presence of code that shouldn't change anything. It was a functionality I added to help verify the code and I've ran extensive tests on this.

答:
Steve Lionel answers essentially the same problem over at the Intel Developer Zone.

Here is the example program used:

```<code>Program Main
  implicit none
  write(*,*) "123"
End Program
</code>```

Compiled with:

```<code>$ ifort -g main.f90
</code>```

Then called with:

```<code>$ valgrind -v --track-origins=yes --leak-check=full ./a.out
</code>```

Valgrind returns essentially the same output seen above.

Here is Steve's reply in full.

Yes, you are correct. You have implicitly opened a file, which requires allocated memory. The file is not closed, so that memory remains allocated at the end of the program. Even if the file is closed (and there is an implicit close when the program exits, not all of the bookkeeping memory may be deallocated. valgrind doesn't understand Fortran.

You may not be able to get rid of all of the valgrind complaints.

So, if I were you, I would ignore these warnings and look at any others you may have.

Body:
I am currently writing a large non-linear solver for a nasty partial differential equation in Fortran90 as part of my research. I have run into an issue where I believe a memory corruption issue is plaguing my code and I am trying to track it down; to do so, I elected to use valgrind as this has worked for me in the past. Unfortunately, I am getting an unexplained error message that is occurring right at the beginning of my code execution, please see below:

==18257== Memcheck, a memory error detector
==18257== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==18257== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==18257== Command: ./JFNKsolver
==18257==
==18257== Conditional jump or move depends on uninitialised value(s)
==18257==    at 0x6F7F7D: __intel_sse2_strcpy (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x6AA1C0: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x67EF6C: for__open_default (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x69878D: for_write_seq_lis (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
==18257==    by 0x402DAD: main (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==  Uninitialised value was created by a stack allocation
==18257==    at 0x6AA07D: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==
==18257== Conditional jump or move depends on uninitialised value(s)
==18257==    at 0x6F7F7D: __intel_sse2_strcpy (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x677DA5: for__add_to_lf_table (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x6ABA13: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x67EF6C: for__open_default (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x69878D: for_write_seq_lis (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==    by 0x65BA69: MAIN__ (JFNKsolver.f90:146)
==18257==    by 0x402DAD: main (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==  Uninitialised value was created by a stack allocation
==18257==    at 0x6AA07D: for__open_proc (in /home/cseinen/Documents/1_Thesis_Work/ThesisGit/Model/Source_Code/JFNKsolver)
==18257==

I got this error by running my code with valgrind --track-origins=yes ./JFNKsolver.

Now I know that, typically, these errors mean that there is an uninitialized variable being used somewhere, but the strange thing is that it is appearing before anything is really happening in my code and it points via by 0x65BA69: MAIN__ (JFNKsolver.f90:146) to a test print statement, i.e. print *, "Test" in the code below.

program JFNKsolver

use modelparams
use initialization
use forcing
use domain_routines
use solver_routines
use var_routines
use csv_file
use validation_routines
use validsoln_routines

implicit none

real(kind = dbl_kind) :: &
    time,       &
    norm_test

integer(kind = int_kind) :: &
    nxT, nyT,   &
    nxN, nyN,   &
    nxU, nyU,   &
    nxV, nyV,   &
    nt,         &
    nU_pnts,    &
    nV_pnts,    &
    nT_pnts,    &
    nN_pnts,    &
    nHT_pnts,   &
    nHN_pnts,   &
    si,         &
    tmp_size,   &
    i, j, ij

integer(kind = int_kind), allocatable, dimension (:) ::  &
    indxUi,     indxUj,         &
    indxVi,     indxVj,         &
    indxTi,     indxTj,         &
    indxNi,     indxNj,         &
    haloTi,     haloTj,         &
    haloNi,     haloNj

real(kind = dbl_kind), allocatable, dimension (:) :: &
    Au,         res_NL,     u_update,       &
    b,          b_0,        vpb_forc

integer(kind = int_kind), allocatable, dimension (:,:,:) :: &
    ulmsk,      vlmsk,      &
    uimsk,      vimsk,      &
    Timsk,      Nimsk,      &
    Tlmsk,      Nlmsk

real(kind = dbl_kind), allocatable, dimension (:,:) :: &
    ugrid,      vgrid,                              &
    uResgrid,   vResgrid,                           &
    uocn_u,     uocn_v,                             &
    vocn_u,     vocn_v,                             &
    uwnd_u,     uwnd_v,                             &
    vwnd_u,     vwnd_v,                             &
    h_u,        h_v,        h_T,                    &
                            A_T,                    &
                            P_T,        P_N,        &
                            zeta_T,     zeta_N,     &
                            eta_T,      eta_N,      &
    Cw_u,   Cw_v,                                   &
                            dist_T,     dist_N,     &
                            dist_gx_T,              &
                            dist_gy_T

print *, "Test"

Note that I have removed comments to clean this up and the kind variables are initialized in the modelparams module. Can anyone provide some insight into what might be causing this? Could it be linked to the modules that I am using via the use statements? I originally thought this was a problem with valgrind but now that I'm seeing the effects of memory corruption, and the fact that this is the only error I'm seeing, I've become wary of it.

Note: the reason I believe there is a memory corruption issue is because I am seeing a change in my solver's behaviour just by the presence of code that shouldn't change anything. It was a functionality I added to help verify the code and I've ran extensive tests on this.

Body:
Steve Lionel answers essentially the same problem over at the Intel Developer Zone.

Here is the example program used:

Program Main
  implicit none
  write(*,*) "123"
End Program

Compiled with:

$ ifort -g main.f90

Then called with:

$ valgrind -v --track-origins=yes --leak-check=full ./a.out

Valgrind returns essentially the same output seen above.

Here is Steve's reply in full.

Yes, you are correct. You have implicitly opened a file, which requires allocated memory. The file is not closed, so that memory remains allocated at the end of the program. Even if the file is closed (and there is an implicit close when the program exits, not all of the bookkeeping memory may be deallocated. valgrind doesn't understand Fortran.

You may not be able to get rid of all of the valgrind complaints.

So, if I were you, I would ignore these warnings and look at any others you may have.


问:
Finding element via xpath with axes
I'm testing steampowered.com and I need to find  element on the form with condition that it has  descendant with text "Games".
It's that element below(it locates in the div with class "store_nav") and I'm using such xpath to locate it.

```<code>//div[contains(@class,'store_nav')]/div[descendant::a[contains(text(),'Games')]]"

<div class="store_nav_bg">
 <div class="store_nav">
  <div id="foryou_tab" class="tab flyout_tab" data-flyout="foryou_flyout" data-flyout-align="left" data-flyout-valign="bottom" onmouseover="EnsureStoreMenuTagsLoaded( '#foryou_yourtags' );">
  <div id="foryou_flyout" class="popup_block_new flyout_tab_flyout responsive_slidedown" style="visibility: visible; top: 42px; left: 0px; display: none; opacity: 0.245479;">
  <div id="genre_tab" class="tab flyout_tab" data-flyout="genre_flyout" data-flyout-align="left" data-flyout-valign="bottom">
    <span class="pulldown">
      <a class="pulldown_desktop" href="http://store.steampowered.com/games/?snr=1_4_4__12">Games</a>
    </span>
  <div id="genre_flyout" class="popup_block_new flyout_tab_flyout responsive_slidedown" style="visibility: visible; top: 42px; left: 131.667px; display: none; opacity: 1;">
  <div id="software_tab" class="tab flyout_tab " data-flyout="software_flyout" data-flyout-align="left" data-flyout-valign="bottom">
  <div id="software_flyout" class="popup_block_new flyout_tab_flyout responsive_slidedown" style="display: none;">
  <div id="hardware_tab" class="tab flyout_tab " data-flyout="hardware_flyout" data-flyout-align="left" data-flyout-valign="bottom">
  <div id="hardware_flyout" class="popup_block_new flyout_tab_flyout responsive_slidedown" style="display: none;">
  <div id="videos_tab" class="tab flyout_tab " data-flyout="videos_flyout" data-flyout-align="left" data-flyout-valign="bottom">
  <div id="videos_flyout" class="popup_block_new flyout_tab_flyout responsive_slidedown" style="display: none;">
  <a class="tab " href="http://store.steampowered.com/news/?snr=1_4_4__12">
  <div class="search_area">
 </div>
</div>
</code>```

The problem is that this xpath points on incorrect element(firepath shows even several elements). For comparison, this xpath works properly

```<code>//div[contains(@class,'store_nav')]/div[span/a[contains(text(),'Games')]]
</code>```

What am I doing incorrect with descendant element?

答:
```<code>//div[contains(@class,'store_nav')]
</code>```

This will match the div class="store_nav_bg" and the div class="store_nav"nodes.

This Xpath:

```<code>//div[contains(@class,'store_nav')]/div[descendant::a[contains(text(),'Games')]]
</code>```

will match div class="store_nav" plus all div/span/a elements you're after, because div class="store_nav" has a descendant of type a. 'Descendant' matches all descendants, however far down the hierarchy they are, not just the combination you're after. If you want only the div/span/a elements, you have to specify that.

Title: Finding element via xpath with axes

Body:
I'm testing steampowered.com and I need to find  element on the form with condition that it has  descendant with text "Games".
It's that element below(it locates in the div with class "store_nav") and I'm using such xpath to locate it.

//div[contains(@class,'store_nav')]/div[descendant::a[contains(text(),'Games')]]"

      Games

The problem is that this xpath points on incorrect element(firepath shows even several elements). For comparison, this xpath works properly

//div[contains(@class,'store_nav')]/div[span/a[contains(text(),'Games')]]

What am I doing incorrect with descendant element?

Body:
//div[contains(@class,'store_nav')]

This will match the div class="store_nav_bg" and the div class="store_nav"nodes.

This Xpath:

//div[contains(@class,'store_nav')]/div[descendant::a[contains(text(),'Games')]]

will match div class="store_nav" plus all div/span/a elements you're after, because div class="store_nav" has a descendant of type a. 'Descendant' matches all descendants, however far down the hierarchy they are, not just the combination you're after. If you want only the div/span/a elements, you have to specify that.


问:
Java Reading Strings to a 2D Boolean Array
I am trying to read a txt file which consists of # and spaces to a 2D boolean array, so that technically a # represents true and a space represents false.

With the help of similar posts i got together a code, although they were reading integers to an array.

My code is:

```<code>public static void main(String[] args) {
    String x;
    String y;
    Scanner fileName = null;
    try {
        fileName = new Scanner(new File("C:/Users/USER/Desktop/hashtag.txt"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    x = fileName.nextLine();
    y = fileName.nextLine();

    boolean[][] cells = new boolean[x][y];

    String finalX = fileName.nextLine();
    String finalY = fileName.nextLine();
    cells[finalX][finalY] = true;

    for (int i = 0; i < cells.length; i++) {
        for (int j = 0; j < cells[i].length; j++) {
            if (cells[i][j])
                System.out.print("#");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

}
</code>```

In my code where I have written boolean[][] cells = new boolean[x][y];

It says the [x] and [y] requires an int, but found a string. The same issue is for cells[finalX][finalY] = true;

I tried parsing i.e. Integer.parseInt(x) however this gets me an error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "#####################"

At what point is my issue? If I parse to an Int, then it can't read the # correct?

答:
You have many mistakes in code and this approach is definitely wrong, you don't even save values that you read from file inside array. Also this code is simply not how you do it, for reading files where you don't know length of file you want to use Lists where you don't need to specify number of elements that list will take(its possible to do get semi-working solution with arrays but there is no point of learning something that is simply wrong). Before even trying to work with files you should learn more basic things, you don't even initialize your arrays properly, you use string for size and index which is causing those issues you mentioned, another beginner mistake is trying to parse non-integer string to int(you are trying to convert ############ to int which is impossible, you can only use this if you know that string is an integer like 1 or 5 or 1000).
So my answer to your question is to just go slowly and learn basics then add new stuff step by step instead just rushing with it.</p>

Body:
I am trying to read a txt file which consists of # and spaces to a 2D boolean array, so that technically a # represents true and a space represents false.

With the help of similar posts i got together a code, although they were reading integers to an array.

My code is:

public static void main(String[] args) {
    String x;
    String y;
    Scanner fileName = null;
    try {
        fileName = new Scanner(new File("C:/Users/USER/Desktop/hashtag.txt"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    x = fileName.nextLine();
    y = fileName.nextLine();

    boolean[][] cells = new boolean[x][y];

    String finalX = fileName.nextLine();
    String finalY = fileName.nextLine();
    cells[finalX][finalY] = true;

    for (int i = 0; i < cells.length; i++) {
        for (int j = 0; j < cells[i].length; j++) {
            if (cells[i][j])
                System.out.print("#");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

}

In my code where I have written boolean[][] cells = new boolean[x][y];

It says the [x] and [y] requires an int, but found a string. The same issue is for cells[finalX][finalY] = true;

I tried parsing i.e. Integer.parseInt(x) however this gets me an error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "#####################"

At what point is my issue? If I parse to an Int, then it can't read the # correct?


问:
Tool for editing .IL files?
Currently I use Notepad for this purpose. Is there any specific tool intended for editing .NET Intermediate Language files?

Dotnet IL Editor (DILE) disassembles files before editing them, I don't need that functionality - only actual editing is needed in the most efficient manner.

答: I found the ReflexIL very helpful. Check out my post on the same for more options.</p>

Title: Tool for editing .IL files?


问:
TensorFlow: "Attempting to use uninitialized value" in variable initialization
I am trying to implement multivariate linear regression in Python using TensorFlow, but have run into some logical and implementation issues. My code throws the following error:

```<code>Attempting to use uninitialized value Variable
Caused by op u'Variable/read'
</code>```

Ideally the weights output should be [2, 3]

```<code>def hypothesis_function(input_2d_matrix_trainingexamples,
                        output_matrix_of_trainingexamples,
                        initial_parameters_of_hypothesis_function,
                        learning_rate, num_steps):
    # calculate num attributes and num examples
    number_of_attributes = len(input_2d_matrix_trainingexamples[0])
    number_of_trainingexamples = len(input_2d_matrix_trainingexamples)

    #Graph inputs
    x = []
    for i in range(0, number_of_attributes, 1):
        x.append(tf.placeholder("float"))
    y_input = tf.placeholder("float")

    # Create Model and Set Model weights
    parameters = []
    for i in range(0, number_of_attributes, 1):
        parameters.append(
            tf.Variable(initial_parameters_of_hypothesis_function[i]))

    #Contruct linear model
    y = tf.Variable(parameters[0], "float")
    for i in range(1, number_of_attributes, 1):
        y = tf.add(y, tf.multiply(x[i], parameters[i]))

    # Minimize the mean squared errors
    loss = tf.reduce_mean(tf.square(y - y_input))
    optimizer = tf.train.GradientDescentOptimizer(learning_rate)
    train = optimizer.minimize(loss)

    #Initialize the variables
    init = tf.initialize_all_variables()

    # launch the graph
    session = tf.Session()
    session.run(init)
    for step in range(1, num_steps + 1, 1):
        for i in range(0, number_of_trainingexamples, 1):
            feed = {}
            for j in range(0, number_of_attributes, 1):
                array = [input_2d_matrix_trainingexamples[i][j]]
                feed[j] = array
            array1 = [output_matrix_of_trainingexamples[i]]
            feed[number_of_attributes] = array1
            session.run(train, feed_dict=feed)

    for i in range(0, number_of_attributes - 1, 1):
        print (session.run(parameters[i]))

array = [[0.0, 1.0, 2.0], [0.0, 2.0, 3.0], [0.0, 4.0, 5.0]]
hypothesis_function(array, [8.0, 13.0, 23.0], [1.0, 1.0, 1.0], 0.01, 200)
</code>```

答: I want to give my resolution, it work when i replace the line [session = tf.Session()] with [sess = tf.InteractiveSession()]. Hope this will be useful to others.

Body:
I am trying to implement multivariate linear regression in Python using TensorFlow, but have run into some logical and implementation issues. My code throws the following error:

Attempting to use uninitialized value Variable
Caused by op u'Variable/read'

Ideally the weights output should be [2, 3]

def hypothesis_function(input_2d_matrix_trainingexamples,
                        output_matrix_of_trainingexamples,
                        initial_parameters_of_hypothesis_function,
                        learning_rate, num_steps):
    # calculate num attributes and num examples
    number_of_attributes = len(input_2d_matrix_trainingexamples[0])
    number_of_trainingexamples = len(input_2d_matrix_trainingexamples)

    #Graph inputs
    x = []
    for i in range(0, number_of_attributes, 1):
        x.append(tf.placeholder("float"))
    y_input = tf.placeholder("float")

    # Create Model and Set Model weights
    parameters = []
    for i in range(0, number_of_attributes, 1):
        parameters.append(
            tf.Variable(initial_parameters_of_hypothesis_function[i]))

    #Contruct linear model
    y = tf.Variable(parameters[0], "float")
    for i in range(1, number_of_attributes, 1):
        y = tf.add(y, tf.multiply(x[i], parameters[i]))

    # Minimize the mean squared errors
    loss = tf.reduce_mean(tf.square(y - y_input))
    optimizer = tf.train.GradientDescentOptimizer(learning_rate)
    train = optimizer.minimize(loss)

    #Initialize the variables
    init = tf.initialize_all_variables()

    # launch the graph
    session = tf.Session()
    session.run(init)
    for step in range(1, num_steps + 1, 1):
        for i in range(0, number_of_trainingexamples, 1):
            feed = {}
            for j in range(0, number_of_attributes, 1):
                array = [input_2d_matrix_trainingexamples[i][j]]
                feed[j] = array
            array1 = [output_matrix_of_trainingexamples[i]]
            feed[number_of_attributes] = array1
            session.run(train, feed_dict=feed)

    for i in range(0, number_of_attributes - 1, 1):
        print (session.run(parameters[i]))

array = [[0.0, 1.0, 2.0], [0.0, 2.0, 3.0], [0.0, 4.0, 5.0]]
hypothesis_function(array, [8.0, 13.0, 23.0], [1.0, 1.0, 1.0], 0.01, 200)


问:
Tensorflow weights that act as linear scaling
I have a neural network with output neurons I want to scale linearly with trained weights before soft maxing.

I have 10 outputs, I want 10 weights which are multiplied by each of the outputs before the output is soft maxed. So 1 weight per output.

But I keep getting the error Shape must be rank 2 but is rank 1 for 'MatMul_2 and it tells me my shapes are [?,10], [10]

Before my code was

```<code>x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
</code>```

Now it is this

```<code>x_ = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
W_pre_final = tf.Variable(tf.ones([10]))
y_pre_final = tf.matmul(x_, W) + b
y = tf.nn.softmax(tf.matmul(y_pre_final, W_pre_final))
y_ = tf.placeholder(tf.float32, [None, 10])
</code>```

答:
I think you are looking for element-wise multiplication, not matrix multiplication</p>

```<code>tf.multiply(y_pre_final, tf.expand_dims(W_pre_final,0))
</code>```

Body:
I have a neural network with output neurons I want to scale linearly with trained weights before soft maxing.

I have 10 outputs, I want 10 weights which are multiplied by each of the outputs before the output is soft maxed. So 1 weight per output.

But I keep getting the error Shape must be rank 2 but is rank 1 for 'MatMul_2 and it tells me my shapes are [?,10], [10]

Before my code was

x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)

Now it is this

x_ = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
W_pre_final = tf.Variable(tf.ones([10]))
y_pre_final = tf.matmul(x_, W) + b
y = tf.nn.softmax(tf.matmul(y_pre_final, W_pre_final))
y_ = tf.placeholder(tf.float32, [None, 10])

Body:
I think you are looking for element-wise multiplication, not matrix multiplication

tf.multiply(y_pre_final, tf.expand_dims(W_pre_final,0))


问:
How to make an a tag border wrap around an image
I need the border to be applied to the a tag but when I do this the border doesn't wrap around the image how can I make this happen?

```<code><div>
  <a href="#">
    <img src="https://cdn.pixabay.com/photo/2015/04/23/17/41/javascript-736400_960_720.png">
  </a>
</div>
</code>```

css:

```<code>a{
  border: 5px solid blue;
}
</code>```

https://jsfiddle.net/b7qdcub1/

答:
```<code>    a{
  border: 5px solid blue;
  display:inline-block;
}
</code>```

Body:
I need the border to be applied to the a tag but when I do this the border doesn't wrap around the image how can I make this happen?

css:

a{
  border: 5px solid blue;
}

https://jsfiddle.net/b7qdcub1/


答:
Find() searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire List.

You need to use FindAll() instead.

Title: C# Linq .Find() return many results


问:
Hbase Scala connectivity issue in Cloudera Quick start VM CDH5.8.0
I am trying to connect HBase from a Scala code but getting below error.

```<code>17/03/28 11:40:53 INFO client.RpcRetryingCaller: Call exception, tries=30, retries=35, started=450502 ms ago, cancelled=false, msg=
17/03/28 11:41:13 INFO client.RpcRetryingCaller: Call exception, tries=31, retries=35, started=470659 ms ago, cancelled=false, msg=
17/03/28 11:41:33 INFO client.RpcRetryingCaller: Call exception, tries=32, retries=35, started=490824 ms ago, cancelled=false, msg=
17/03/28 11:41:53 INFO client.RpcRetryingCaller: Call exception, tries=33, retries=35, started=510834 ms ago, cancelled=false, msg=
17/03/28 11:42:13 INFO client.RpcRetryingCaller: Call exception, tries=34, retries=35, started=530956 ms ago, cancelled=false, msg=
[error] (run-main-0) org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=35, exceptions:
[error] Tue Mar 28 11:33:22 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
[error] Tue Mar 28 11:33:23 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
[error] Tue Mar 28 11:33:23 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
[error] Tue Mar 28 11:33:24 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
.
.
.
.
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:147)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1560)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:239)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:331)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:58383)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1591)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1529)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.createConnection(RpcClientImpl.java:138)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.getConnection(RpcClientImpl.java:1316)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1224)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:226)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:331)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:58383)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1591)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1529)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.net.SocketInputWrapper
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.createConnection(RpcClientImpl.java:138)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.getConnection(RpcClientImpl.java:1316)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1224)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:226)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:331)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:58383)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1591)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1529)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
[trace] Stack trace suppressed: run last compile:run for the full output.
17/03/28 07:56:55 ERROR zookeeper.ClientCnxn: Event thread exiting due to interruption
java.lang.InterruptedException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2052)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
    at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:494)
17/03/28 07:56:55 INFO zookeeper.ClientCnxn: EventThread shut down
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 544 s, completed Mar 28, 2017 7:56:56 AM
</code>```

•   Host OS is Windows 7 with 8 GB RAM and 64 bit arch. Intel core i5.

•   I am using Cloudera Quick start VM CDH 5.8.0. on my Wndows.

•   VM is using 6GB RAM, 2 processors & 64 GB Harddisk.

•   Services running in Cloudera Manager:

```<code>    Hbase
    HDFS
    YARN
    Zookeeper
    Key-Value Indexer
</code>```

•   Services stopped in Cloudera Manager:

```<code>    Hive
    Hue
    Impala
    Oozie
    Solar
    Spark
    Sqoop 1 Client
    Sqoop 2
</code>```

•   Hbase version 1.2.0-cdh5.8.0

•   My client code is in VM only.

•   Created the sbt project.

•   I referred this url https://hbase.apache.org/book.html#scala  for Hbase connectivity with Scala.

•   Setting the CLASSPATH. I did't mention the "/path/to/scala-library.jar" in the CLASSPATH as mentiond in the link.

```<code>$ export CLASSPATH=$CLASSPATH:/usr/lib/hadoop/lib/native:/usr/lib/hbase/lib/native/Linux-amd64-64
</code>```

•   Project root directory = /home/cloudera/Desktop/play-sbt-project

•   My /home/cloudera/Desktop/play-sbt-project/build.sbt looks like this. I changed the dependent library version as per my environment. I added few more dependencies like "hbase-client", "hbase-common" & "hbase-server" as part of error troubleshoot but still didn't got success.

```<code>name := "play-sbt-project"
version := "1.0"
scalaVersion := "2.10.2"
resolvers += "Apache HBase" at "https://repository.apache.org/content/repositories/releases"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-core" % "1.2.1",
"org.apache.hbase" % "hbase" % "1.2.0",
"org.apache.hbase" % "hbase-client" % "1.2.0",
"org.apache.hbase" % "hbase-common" % "1.2.0",
"org.apache.hbase" % "hbase-server" % "1.2.0"
)
</code>```

•   My main code for Hbase connectivity /home/cloudera/Desktop/play-sbt-project/src/main/scala/pw.scala looks like this

```<code>import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{ConnectionFactory,HBaseAdmin,HTable,Put,Get}
import org.apache.hadoop.hbase.util.Bytes

object Hi {
def main(args: Array[String]) = {
println("Hi!")
val conf = new HBaseConfiguration()
val connection = ConnectionFactory.createConnection(conf);
val admin = connection.getAdmin();

// list the tables
val listtables=admin.listTables()
listtables.foreach(println)
}
}
</code>```

•   My /etc/hbase/conf/hbase-site.xml looks like this:

```<code><?xml version="1.0" encoding="UTF-8"?>

<!--Autogenerated by Cloudera Manager-->
<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://quickstart.cloudera:8020/hbase</value>
  </property>
  <property>
    <name>hbase.replication</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.client.write.buffer</name>
    <value>2097152</value>
  </property>
  <property>
    <name>hbase.client.pause</name>
    <value>100</value>
  </property>
  <property>
    <name>hbase.client.retries.number</name>
    <value>35</value>
  </property>
  <property>
    <name>hbase.client.scanner.caching</name>
    <value>100</value>
  </property>
  <property>
    <name>hbase.client.keyvalue.maxsize</name>
    <value>10485760</value>
  </property>
  <property>
    <name>hbase.ipc.client.allowsInterrupt</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.client.primaryCallTimeout.get</name>
    <value>10</value>
  </property>
  <property>
    <name>hbase.client.primaryCallTimeout.multiget</name>
    <value>10</value>
  </property>
  <property>
    <name>hbase.coprocessor.region.classes</name>
    <value>org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint</value>
  </property>
  <property>
    <name>hbase.regionserver.thrift.http</name>
    <value>false</value>
  </property>
  <property>
    <name>hbase.thrift.support.proxyuser</name>
    <value>false</value>
  </property>
  <property>
    <name>hbase.rpc.timeout</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.snapshot.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.snapshot.master.timeoutMillis</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.snapshot.region.timeout</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.snapshot.master.timeout.millis</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.security.authentication</name>
    <value>simple</value>
  </property>
  <property>
    <name>hbase.rpc.protection</name>
    <value>authentication</value>
  </property>
  <property>
    <name>zookeeper.session.timeout</name>
    <value>60000</value>
  </property>
  <property>
    <name>zookeeper.znode.parent</name>
    <value>/hbase</value>
  </property>
  <property>
    <name>zookeeper.znode.rootserver</name>
    <value>root-region-server</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <!-- <value>quickstart.cloudera</value> -->
    <value>127.0.0.1</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.clientPort</name>
    <value>2181</value>
  </property>
  <property>
    <name>hbase.rest.ssl.enabled</name>
    <value>false</value>
  </property>
</configuration>
</code>```

I googled alot to solve this issue but didn't got sucess. In the process of solving this issue I have done below changes:

•   Changed the Dependent libraries version in build.sbt file as per my environment

•   Added few more dependent libraries "hbase-client", "hbase-common" & "hbase-server".

•   Chaned the "hbase.zookeeper.quorum" value from "quickstart.cloudera" to "127.0.0.1" in "hbase-site.xml" file.

Please help me solving this issue. Thank you.

答:
Resolved the issue. There are following changes need to be done:

Change "hadoop-core" to "hadoop-common" inside build.sbt file. Since in latest CDH versions 'hadoop-core' is only supported by code running for MapReduce 1.

Change all the dependecy version as per cloudera 5.8.0 compatibility in build.sbt. Updated build.sbt looks like this:

```<code>name := "play-sbt-project"
version := "1.0"
scalaVersion := "2.10.2"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
resolvers += "Cloudera Repository" at "https://repository.cloudera.com/artifactory/cloudera-repos/"

libraryDependencies ++= Seq(
 "org.apache.hadoop" % "hadoop-common" % "2.6.0-cdh5.8.0",
 "org.apache.hbase" % "hbase" % "1.2.0-cdh5.8.0",
 "org.apache.hbase" % "hbase-client" % "1.2.0-cdh5.8.0",
 "org.apache.hbase" % "hbase-common" % "1.2.0-cdh5.8.0",
 "org.apache.hbase" % "hbase-server" % "1.2.0-cdh5.8.0"
)
</code>```

HBaseConfiguration() class is depricated. Instead use create() method. Also I changed some logic in the main code. Earlier I was getting the tables present in HBase (Since this was giving some issues so I dropped this but I will try this next time), Since my moto is to establish Scala to HBase connectivity so now I am trying to insert new row to the already existing HBase table. New code looks like this:

```<code>package main.scala

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{ConnectionFactory,HTable,Put}
import org.apache.hadoop.hbase.util.Bytes

object Hi {

 def main(args: Array[String]) = {
 println("Hi!")
 val conf:Configuration = HBaseConfiguration.create()
 val table:HTable = new HTable(conf, "emp1")
 val put1:Put = new Put(Bytes.toBytes("row1"))
 put1.add(Bytes.toBytes("personal_data"),Bytes.toBytes("qual1"),Bytes.toBytes("val1"))
 table.put(put1)
 println("Success")
 }
}
</code>```

Body:
I am trying to connect HBase from a Scala code but getting below error.

17/03/28 11:40:53 INFO client.RpcRetryingCaller: Call exception, tries=30, retries=35, started=450502 ms ago, cancelled=false, msg=
17/03/28 11:41:13 INFO client.RpcRetryingCaller: Call exception, tries=31, retries=35, started=470659 ms ago, cancelled=false, msg=
17/03/28 11:41:33 INFO client.RpcRetryingCaller: Call exception, tries=32, retries=35, started=490824 ms ago, cancelled=false, msg=
17/03/28 11:41:53 INFO client.RpcRetryingCaller: Call exception, tries=33, retries=35, started=510834 ms ago, cancelled=false, msg=
17/03/28 11:42:13 INFO client.RpcRetryingCaller: Call exception, tries=34, retries=35, started=530956 ms ago, cancelled=false, msg=
[error] (run-main-0) org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=35, exceptions:
[error] Tue Mar 28 11:33:22 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
[error] Tue Mar 28 11:33:23 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
[error] Tue Mar 28 11:33:23 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
[error] Tue Mar 28 11:33:24 PDT 2017, RpcRetryingCaller{globalStartTime=1490726002560, pause=100, retries=35}, org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
.
.
.
.
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:147)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1560)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: com.google.protobuf.ServiceException: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:239)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:331)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:58383)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1591)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1529)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/net/SocketInputWrapper
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.createConnection(RpcClientImpl.java:138)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.getConnection(RpcClientImpl.java:1316)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1224)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:226)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:331)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:58383)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1591)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1529)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.net.SocketInputWrapper
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.createConnection(RpcClientImpl.java:138)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.getConnection(RpcClientImpl.java:1316)
    at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1224)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:226)
    at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:331)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:58383)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(ConnectionManager.java:1591)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(ConnectionManager.java:1529)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1551)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1580)
    at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1737)
    at org.apache.hadoop.hbase.client.MasterCallable.prepare(MasterCallable.java:38)
    at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:124)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4117)
    at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:4110)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:427)
    at org.apache.hadoop.hbase.client.HBaseAdmin.listTables(HBaseAdmin.java:411)
    at Hi$.main(hw.scala:12)
    at Hi.main(hw.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
[trace] Stack trace suppressed: run last compile:run for the full output.
17/03/28 07:56:55 ERROR zookeeper.ClientCnxn: Event thread exiting due to interruption
java.lang.InterruptedException
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2017)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2052)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
    at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:494)
17/03/28 07:56:55 INFO zookeeper.ClientCnxn: EventThread shut down
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 544 s, completed Mar 28, 2017 7:56:56 AM

•   Host OS is Windows 7 with 8 GB RAM and 64 bit arch. Intel core i5.

•   I am using Cloudera Quick start VM CDH 5.8.0. on my Wndows.

•   VM is using 6GB RAM, 2 processors & 64 GB Harddisk.

•   Services running in Cloudera Manager:

    Hbase
    HDFS
    YARN
    Zookeeper
    Key-Value Indexer

•   Services stopped in Cloudera Manager:

    Hive
    Hue
    Impala
    Oozie
    Solar
    Spark
    Sqoop 1 Client
    Sqoop 2

•   Hbase version 1.2.0-cdh5.8.0

•   My client code is in VM only.

•   Created the sbt project.

•   I referred this url https://hbase.apache.org/book.html#scala  for Hbase connectivity with Scala.

•   Setting the CLASSPATH. I did't mention the "/path/to/scala-library.jar" in the CLASSPATH as mentiond in the link.

$ export CLASSPATH=$CLASSPATH:/usr/lib/hadoop/lib/native:/usr/lib/hbase/lib/native/Linux-amd64-64

•   Project root directory = /home/cloudera/Desktop/play-sbt-project

•   My /home/cloudera/Desktop/play-sbt-project/build.sbt looks like this. I changed the dependent library version as per my environment. I added few more dependencies like "hbase-client", "hbase-common" & "hbase-server" as part of error troubleshoot but still didn't got success.

name := "play-sbt-project"
version := "1.0"
scalaVersion := "2.10.2"
resolvers += "Apache HBase" at "https://repository.apache.org/content/repositories/releases"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-core" % "1.2.1",
"org.apache.hbase" % "hbase" % "1.2.0",
"org.apache.hbase" % "hbase-client" % "1.2.0",
"org.apache.hbase" % "hbase-common" % "1.2.0",
"org.apache.hbase" % "hbase-server" % "1.2.0"
)

•   My main code for Hbase connectivity /home/cloudera/Desktop/play-sbt-project/src/main/scala/pw.scala looks like this

import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{ConnectionFactory,HBaseAdmin,HTable,Put,Get}
import org.apache.hadoop.hbase.util.Bytes

object Hi {
def main(args: Array[String]) = {
println("Hi!")
val conf = new HBaseConfiguration()
val connection = ConnectionFactory.createConnection(conf);
val admin = connection.getAdmin();

// list the tables
val listtables=admin.listTables()
listtables.foreach(println)
}
}

•   My /etc/hbase/conf/hbase-site.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://quickstart.cloudera:8020/hbase</value>
  </property>
  <property>
    <name>hbase.replication</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.client.write.buffer</name>
    <value>2097152</value>
  </property>
  <property>
    <name>hbase.client.pause</name>
    <value>100</value>
  </property>
  <property>
    <name>hbase.client.retries.number</name>
    <value>35</value>
  </property>
  <property>
    <name>hbase.client.scanner.caching</name>
    <value>100</value>
  </property>
  <property>
    <name>hbase.client.keyvalue.maxsize</name>
    <value>10485760</value>
  </property>
  <property>
    <name>hbase.ipc.client.allowsInterrupt</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.client.primaryCallTimeout.get</name>
    <value>10</value>
  </property>
  <property>
    <name>hbase.client.primaryCallTimeout.multiget</name>
    <value>10</value>
  </property>
  <property>
    <name>hbase.coprocessor.region.classes</name>
    <value>org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint</value>
  </property>
  <property>
    <name>hbase.regionserver.thrift.http</name>
    <value>false</value>
  </property>
  <property>
    <name>hbase.thrift.support.proxyuser</name>
    <value>false</value>
  </property>
  <property>
    <name>hbase.rpc.timeout</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.snapshot.enabled</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.snapshot.master.timeoutMillis</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.snapshot.region.timeout</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.snapshot.master.timeout.millis</name>
    <value>60000</value>
  </property>
  <property>
    <name>hbase.security.authentication</name>
    <value>simple</value>
  </property>
  <property>
    <name>hbase.rpc.protection</name>
    <value>authentication</value>
  </property>
  <property>
    <name>zookeeper.session.timeout</name>
    <value>60000</value>
  </property>
  <property>
    <name>zookeeper.znode.parent</name>
    <value>/hbase</value>
  </property>
  <property>
    <name>zookeeper.znode.rootserver</name>
    <value>root-region-server</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>

    <value>127.0.0.1</value>
  </property>
  <property>
    <name>hbase.zookeeper.property.clientPort</name>
    <value>2181</value>
  </property>
  <property>
    <name>hbase.rest.ssl.enabled</name>
    <value>false</value>
  </property>
</configuration>

I googled alot to solve this issue but didn't got sucess. In the process of solving this issue I have done below changes:

•   Changed the Dependent libraries version in build.sbt file as per my environment

•   Added few more dependent libraries "hbase-client", "hbase-common" & "hbase-server".

•   Chaned the "hbase.zookeeper.quorum" value from "quickstart.cloudera" to "127.0.0.1" in "hbase-site.xml" file.

Please help me solving this issue. Thank you.

Body:
Resolved the issue. There are following changes need to be done:

Change "hadoop-core" to "hadoop-common" inside build.sbt file. Since in latest CDH versions 'hadoop-core' is only supported by code running for MapReduce 1.

Change all the dependecy version as per cloudera 5.8.0 compatibility in build.sbt. Updated build.sbt looks like this:

name := "play-sbt-project"
version := "1.0"
scalaVersion := "2.10.2"
resolvers += "Thrift" at "http://people.apache.org/~rawson/repo/"
resolvers += "Cloudera Repository" at "https://repository.cloudera.com/artifactory/cloudera-repos/"

libraryDependencies ++= Seq(
 "org.apache.hadoop" % "hadoop-common" % "2.6.0-cdh5.8.0",
 "org.apache.hbase" % "hbase" % "1.2.0-cdh5.8.0",
 "org.apache.hbase" % "hbase-client" % "1.2.0-cdh5.8.0",
 "org.apache.hbase" % "hbase-common" % "1.2.0-cdh5.8.0",
 "org.apache.hbase" % "hbase-server" % "1.2.0-cdh5.8.0"
)

HBaseConfiguration() class is depricated. Instead use create() method. Also I changed some logic in the main code. Earlier I was getting the tables present in HBase (Since this was giving some issues so I dropped this but I will try this next time), Since my moto is to establish Scala to HBase connectivity so now I am trying to insert new row to the already existing HBase table. New code looks like this:

package main.scala

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{ConnectionFactory,HTable,Put}
import org.apache.hadoop.hbase.util.Bytes

object Hi {

 def main(args: Array[String]) = {
 println("Hi!")
 val conf:Configuration = HBaseConfiguration.create()
 val table:HTable = new HTable(conf, "emp1")
 val put1:Put = new Put(Bytes.toBytes("row1"))
 put1.add(Bytes.toBytes("personal_data"),Bytes.toBytes("qual1"),Bytes.toBytes("val1"))
 table.put(put1)
 println("Success")
 }
}


问:
SQLite: Database location or iosDatabaseLocation value is now mandatory in openDatabase call
I am using SQLite plugin for my ionic application for both android and iOS

Plugin: cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git

ionic version: 2.1.18

cordova version: 6.4.0

node version: 4.5.0

Here is my code to open and create database

```<code>var db;
db = $cordovaSQLite.openDB({ name: "test.db", iosDatabaseLocation:'default'});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS OfflineData (id integer primary key, imageUrl text, videoUrl text, head text, title text, descr text)");
</code>```

But I am getting an issue while running this in my android device like

```<code>ionic.bundle.min.js:150 Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call
at newSQLError (plugins/cordova-sqlite-storage/www/SQLitePlugin.js:26)
at Object.<anonymous> (plugins/cordova-sqlite-storage/www/SQLitePlugin.js:565)
at Object.openDatabase (plugins/cordova-sqlite-storage/www/SQLitePlugin.js:59)
at Object.openDB (ng-cordova.js:5176)
</code>```

Can any one help me out for this.

答:
You are only specifying the iOS location, but are running on Android.

You need to detect which platform you are running on (using Ionic's Platform class) and use the location property for Android and iosDatabaseLocation for iOS.

Body:
I am using SQLite plugin for my ionic application for both android and iOS

Plugin: cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git

ionic version: 2.1.18

cordova version: 6.4.0

node version: 4.5.0

Here is my code to open and create database

var db;
db = $cordovaSQLite.openDB({ name: "test.db", iosDatabaseLocation:'default'});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS OfflineData (id integer primary key, imageUrl text, videoUrl text, head text, title text, descr text)");

But I am getting an issue while running this in my android device like

ionic.bundle.min.js:150 Error: Database location or iosDatabaseLocation value is now mandatory in openDatabase call
at newSQLError (plugins/cordova-sqlite-storage/www/SQLitePlugin.js:26)
at Object.<anonymous> (plugins/cordova-sqlite-storage/www/SQLitePlugin.js:565)
at Object.openDatabase (plugins/cordova-sqlite-storage/www/SQLitePlugin.js:59)
at Object.openDB (ng-cordova.js:5176)

Can any one help me out for this.


答:
try this</p>

```<code>var matches = MovieList.Where(m => SelCat.Except(
    m.Categories.Intersect(SelCat)).Count() == 0);
</code>```

Title: Linq to objects List in list

Body:
I have a list of movies

List<Movie> MovieList

and I have a list of selected categories

List<string> SelCat

And say I want to select from the movie list where it matches 2 categories, like the SQL statement below:

SELECT * FROM MovieList WHERE MovieList.Category = 'Action' AND MovieList.Category = 'Drama'

I can get kinda close with linq like so:

var q = (from b in MovieList where b.Categories.Any(p=> SelCat.Contains(p)) select b);

But it acts like an OR query, not an AND. I want it to select all movies that have a category of action and drama.

BTW: Movie.Categories is a List of string. AND Movie.Categories must contain items in the SelCat.

How do I achieve this with Linq to Objects?

Body:
try this

var matches = MovieList.Where(m => SelCat.Except(
    m.Categories.Intersect(SelCat)).Count() == 0);