问:
Why this code block showing stack smashing detection?
So I am not able run the code which I have attached below. The program is about multiplication of 2 matrices. I am getting stack smashing detection. I am new to this problem. My OS is Ubuntu 18.04 </p>

```<code>    #include<stdio.h>
#define R1 3
#define C1 4
#define R2 C1
#define C2 2
void main()
{
        int i,j,k,mat1[R1][C1],mat2[R2][C2],mat3[R1][C2];
        printf("Enter 1st matrix(%dX%d) :",R1,C1);
        for(i=0;i<R1;i++)
        {
                for(j=0;j<C1;j++)
                {
                        scanf("%d",&mat1[R1][C2]);
                }
        }
        printf("Enter 2nd matrix(%dX%d) :",R2,C2);
        for(i=0;i<R2;i++)
        {
                for(j=0;j<C2;j++)
                {
                        scanf("%d",&mat1[R1][C2]);
                }
        }
        for(i=0;i<R1;i++)
        {
                for(j=0;j<C2;j++)
                {
                         mat3[i][j]=0;
                        for(k=0;k<C1;k++)
                        {
                                mat3[i][j] += mat1[i][k] * mat2[k][j];
                        }
                }
        }
        printf("The resultant matrices are :");
        for(i=0;i<R1;i++)
        {
                for(j=0;j<C2;j++)
                {
                        printf("%5d",mat3[i][j]);
                }
                printf("\n");

        }
}
</code>```

答:
IN

```<code>   for(i=0;i<R1;i++)
   {
           for(j=0;j<C1;j++)
           {
                   scanf("%d",&mat1[R1][C2]);
           }
   }
   printf("Enter 2nd matrix(%dX%d) :",R2,C2);
   for(i=0;i<R2;i++)
   {
           for(j=0;j<C2;j++)
           {
                   scanf("%d",&mat1[R1][C2]);
           }
   }
</code>```

you do not set the indexes and matrix you want, must be

```<code>    for(i=0;i<R1;i++)
    {
            for(j=0;j<C1;j++)
            {
                    scanf("%d",&mat1[i][j]); /* correct indexes */
            }
    }
    printf("Enter 2nd matrix(%dX%d) :",R2,C2);
    for(i=0;i<R2;i++)
    {
            for(j=0;j<C2;j++)
            {
                    scanf("%d",&mat2[i][j]); /* correct matrix and indexes */
            }
    }
</code>```

I also encourage you to verify your scanf returns 1 to check the use enter valid inputs

Body:
So I am not able run the code which I have attached below. The program is about multiplication of 2 matrices. I am getting stack smashing detection. I am new to this problem. My OS is Ubuntu 18.04

    #include<stdio.h>
#define R1 3
#define C1 4
#define R2 C1
#define C2 2
void main()
{
        int i,j,k,mat1[R1][C1],mat2[R2][C2],mat3[R1][C2];
        printf("Enter 1st matrix(%dX%d) :",R1,C1);
        for(i=0;i<R1;i++)
        {
                for(j=0;j<C1;j++)
                {
                        scanf("%d",&mat1[R1][C2]);
                }
        }
        printf("Enter 2nd matrix(%dX%d) :",R2,C2);
        for(i=0;i<R2;i++)
        {
                for(j=0;j<C2;j++)
                {
                        scanf("%d",&mat1[R1][C2]);
                }
        }
        for(i=0;i<R1;i++)
        {
                for(j=0;j<C2;j++)
                {
                         mat3[i][j]=0;
                        for(k=0;k<C1;k++)
                        {
                                mat3[i][j] += mat1[i][k] * mat2[k][j];
                        }
                }
        }
        printf("The resultant matrices are :");
        for(i=0;i<R1;i++)
        {
                for(j=0;j<C2;j++)
                {
                        printf("%5d",mat3[i][j]);
                }
                printf("\n");

        }
}

Body:
IN

   for(i=0;i<R1;i++)
   {
           for(j=0;j<C1;j++)
           {
                   scanf("%d",&mat1[R1][C2]);
           }
   }
   printf("Enter 2nd matrix(%dX%d) :",R2,C2);
   for(i=0;i<R2;i++)
   {
           for(j=0;j<C2;j++)
           {
                   scanf("%d",&mat1[R1][C2]);
           }
   }

you do not set the indexes and matrix you want, must be

    for(i=0;i<R1;i++)
    {
            for(j=0;j<C1;j++)
            {
                    scanf("%d",&mat1[i][j]); /* correct indexes */
            }
    }
    printf("Enter 2nd matrix(%dX%d) :",R2,C2);
    for(i=0;i<R2;i++)
    {
            for(j=0;j<C2;j++)
            {
                    scanf("%d",&mat2[i][j]); /* correct matrix and indexes */
            }
    }

I also encourage you to verify your scanf returns 1 to check the use enter valid inputs


来源: stackexchange

问:
Missing units (IcePack, Generics.Collections)
Hi where i can find these units: (IcePack, Generics.Collections)?
i have delphi 2006, i think Generics.Collection is only on delphi 2010/XE</p>

答:
The Generics units were added in Delphi 2009 and could be of no use to you since your Delphi doesn't support generics.

IcePack is not part of Delphi and no doubt can be located with a web search.

ContentLicense: CC BY-SA 3.0


问:
How to fix 'ValueError: math domain error' in python?
I am trying to write a program which calculates formula y=√x*x + 3*x - 500,
Interval is [x1;x2] and f.e x1=15, x2=25.

I tried to use Exception Handling but it didn't help.
And the code I try to use now gives me: ValueError: math domain error

```<code>import math

x1 = int(input("Enter first number:"))
x2 = int(input("Enter second number:"))
print(" x", "   y")
for x in range(x1, x2):
    formula = math.sqrt(x * x + 3 * x - 500)
    if formula < 0:
        print("square root cant be negative")
    print(x, round(formula, 2))
</code>```

The output should look like this:

```<code>x   y
15 ***
16 ***
17 ***
18 ***
19 ***
20 ***
21 2.00
22 7.07
23 9.90
24 12.17
25 14.14
</code>```

答:
The argument of square root mustn't be negative. It's perfectly fine to use exception handling here, see below:

Playground: https://ideone.com/vMcewP

import math

x1 = int(input("Enter first number:\n"))
x2 = int(input("Enter second number:\n"))

print(" x\ty")
for x in range(x1, x2 + 1):
    try:
        formula = math.sqrt(x**2 + 3*x - 500)
        print("%d\t%.2f" % (x, formula))
    except ValueError:  # Square root of a negative number.
        print("%d\txxx" % x)

```

Resources:

wiki.python.org: Handling Exceptions

ContentLicense: CC BY-SA 4.0

Body:
I am trying to write a program which calculates formula y=√x*x + 3*x - 500,
Interval is [x1;x2] and f.e x1=15, x2=25.

I tried to use Exception Handling but it didn't help.
And the code I try to use now gives me: ValueError: math domain error

import math

x1 = int(input("Enter first number:"))
x2 = int(input("Enter second number:"))
print(" x", "   y")
for x in range(x1, x2):
    formula = math.sqrt(x * x + 3 * x - 500)
    if formula < 0:
        print("square root cant be negative")
    print(x, round(formula, 2))

The output should look like this:

x   y
15 ***
16 ***
17 ***
18 ***
19 ***
20 ***
21 2.00
22 7.07
23 9.90
24 12.17
25 14.14

Body:
The argument of square root mustn't be negative. It's perfectly fine to use exception handling here, see below:

Playground: https://ideone.com/vMcewP

import math

x1 = int(input("Enter first number:\n"))
x2 = int(input("Enter second number:\n"))

print(" x\ty")
for x in range(x1, x2 + 1):
    try:
        formula = math.sqrt(x**2 + 3*x - 500)
        print("%d\t%.2f" % (x, formula))
    except ValueError:  # Square root of a negative number.
        print("%d\txxx" % x)

Resources:

wiki.python.org: Handling Exceptions


问:
How to get Reddit submission by fullname using Redd gem?
I'm trying to get submission by fullname using Redd gem (https://github.com/avinashbot/redd):

```<code>r = Redd.it(:userless, 'client_id', 'secret_id', user_agent: 'comment streamer')
r.from_fullname('t3_52jtld')
</code>```

But get error:

NameError: uninitialized constant Redd::Response::ParseJson::JSONError

How should I do this?

答: You need to call r.authorize! before r.from_fullname

Body:
I'm trying to get submission by fullname using Redd gem (https://github.com/avinashbot/redd):

r = Redd.it(:userless, 'client_id', 'secret_id', user_agent: 'comment streamer')
r.from_fullname('t3_52jtld')

But get error:

NameError: uninitialized constant Redd::Response::ParseJson::JSONError

How should I do this?


问:
D3.js - load csv file from chrome
I 've got a webProject with dc.js (d3.js+crossfilter.js) and ndx.csv file. When i run project into chrome from visual studio, everythings is Ok. Now after build project and copy in other computers, Run that.

The problem is here. When i try to run webProject [html file] in other computers with Chrome, this browser has error "XMLHttpRequest cannot load file:///C:/Users/9901/Desktop/WebSite1/ndx.csv. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource." I search about this problem, but haven't found solution.
Hints:

I want just use browser "Chrome Portable", Otherwise no problrm with IE and FireFox

My addressbar in run: "file:///C:/Users/User-1/Desktop/WebSite1/Index.html".

I don't have web server in other computers.

答:
I had a similar issue before and I resolved it with an easy approach.
You can't get data from .csv file because host and protocol are different.

To fix this issue, you should run a simple web server.
The following example would work.

npm install -g http-server

http-server

Title: D3.js - load csv file from chrome


问:
File not found exception in android with correct file path and persmission
I am trying to read an already created CSV file. The path variable shows the correct path as in the android app folder. Also, I have added the read and write external storage permission but still I get file not found exception as in Volley Error toast message.

Read CSV code:-

```<code>    String path = String.valueOf(this.getExternalFilesDir(null));
    Log.d("Path",path+"/Final.csv");
    File csvFILE = new File(path+"/","Final.csv");
    try {
        CSVReader csvREAD = new CSVReader(new
                FileReader(path));
        String[] csvLINE;
        int skip = 0;
        try {
            Log.d("I was here","kk");
            while((csvLINE = csvREAD.readNext())!=null)
            {
                if(skip > 0)//becasue first line is column headers
                {
                    String PARAM_DISTRICT = csvLINE[0];
                    String PARAM_TALUKA = csvLINE[1];
                    String PARAM_VILLAGE = csvLINE[2];
                    String PARAM_FARMER_NAME = csvLINE[3];
                    String PARAM_CONTACT_NUMBER = csvLINE[4];
                    String PARAM_GAT_NUMBER = csvLINE[5];
                    String PARAM_CROP_NAME = csvLINE[6];
                    String PARAM_LANDUSE = csvLINE[7];
                    String PARAM_SOIL_TYPE = csvLINE[8];
                    int PARAM_SOIL_DEPTH = Integer.parseInt(csvLINE[9]);
                    double PARAM_LATITUDE = Double.parseDouble(csvLINE[10]);
                    double PARAM_LONGITUDE = Double.parseDouble(csvLINE[11]);
                    String PARAM_TIMESTAMP = csvLINE[12];

                    Data STUD_OBJECT = new Data(PARAM_DISTRICT,PARAM_TALUKA,PARAM_VILLAGE,
                            PARAM_FARMER_NAME,PARAM_CONTACT_NUMBER,PARAM_GAT_NUMBER,
                            PARAM_CROP_NAME,PARAM_LANDUSE,PARAM_SOIL_TYPE,PARAM_SOIL_DEPTH,
                            PARAM_LATITUDE,PARAM_LONGITUDE,PARAM_TIMESTAMP
                    );
                    dataArray.add(STUD_OBJECT);
                }
                else
                {
                    skip ++;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        Toast.makeText(this, "Volley Error", Toast.LENGTH_SHORT).show();
    }
</code>```

The CSV file was created with the below code:

```<code>    String Testfile_name="Final";
    Testfile_name=Testfile_name+".csv";
    File logFile = new File(this.getExternalFilesDir(null), Testfile_name);
    if (!logFile.exists())
    {
        try
        {
            logFile.createNewFile();
            String header= "District,Taluka,Village,Farmer_name,Contact_Number,Gat_Number,Crop_name,Landuse,Soil_Type,Soil_Depth,Latitude,Longitude,Timestamp";
            appendLog(header);
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
</code>```

答:
The problem is how you are accessing the file

```<code>String path = String.valueOf(this.getExternalFilesDir(null));
</code>```

needs to change to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

Check the example below, it works

AndroidManifest.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zackdawood.csvreadwrite">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <provider
            android:name=".GenericFileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/external_files"/>
        </provider>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
</code>```

Data.java

```<code>package com.zackdawood.csvreadwrite;

public class Data {

    private String PARAM_DISTRICT = "";
    private String PARAM_TALUKA = "";
    private String PARAM_VILLAGE = "";
    private String PARAM_FARMER_NAME = "";
    private String PARAM_CONTACT_NUMBER = "";
    private String PARAM_GAT_NUMBER = "";
    private String PARAM_CROP_NAME = "";
    private String PARAM_LANDUSE = "";
    private String PARAM_SOIL_TYPE = "";
    private String PARAM_TIMESTAMP = "";
    private int PARAM_SOIL_DEPTH = 0;
    private double PARAM_LATITUDE = 0;
    private double PARAM_LONGITUDE = 0;

    public Data(String PARAM_DISTRICT, String PARAM_TALUKA, String PARAM_VILLAGE, String PARAM_FARMER_NAME, String PARAM_CONTACT_NUMBER, String PARAM_GAT_NUMBER, String PARAM_CROP_NAME, String PARAM_LANDUSE, String PARAM_SOIL_TYPE, int PARAM_SOIL_DEPTH, double PARAM_LATITUDE, double PARAM_LONGITUDE, String PARAM_TIMESTAMP) {
        this.PARAM_DISTRICT = PARAM_DISTRICT;
        this.PARAM_TALUKA = PARAM_TALUKA;
        this.PARAM_VILLAGE = PARAM_VILLAGE;
        this.PARAM_FARMER_NAME = PARAM_FARMER_NAME;
        this.PARAM_CONTACT_NUMBER = PARAM_CONTACT_NUMBER;
        this.PARAM_GAT_NUMBER = PARAM_GAT_NUMBER;
        this.PARAM_CROP_NAME = PARAM_CROP_NAME;
        this.PARAM_LANDUSE = PARAM_LANDUSE;
        this.PARAM_SOIL_TYPE = PARAM_SOIL_TYPE;
        this.PARAM_SOIL_DEPTH = PARAM_SOIL_DEPTH;
        this.PARAM_LATITUDE = PARAM_LATITUDE;
        this.PARAM_LONGITUDE = PARAM_LONGITUDE;
        this.PARAM_TIMESTAMP = PARAM_TIMESTAMP;
    }

    @Override
    public String toString() {
        return "Data{" +
                "PARAM_DISTRICT='" + PARAM_DISTRICT + '\'' +
                ", PARAM_TALUKA='" + PARAM_TALUKA + '\'' +
                ", PARAM_VILLAGE='" + PARAM_VILLAGE + '\'' +
                ", PARAM_FARMER_NAME='" + PARAM_FARMER_NAME + '\'' +
                ", PARAM_CONTACT_NUMBER='" + PARAM_CONTACT_NUMBER + '\'' +
                ", PARAM_GAT_NUMBER='" + PARAM_GAT_NUMBER + '\'' +
                ", PARAM_CROP_NAME='" + PARAM_CROP_NAME + '\'' +
                ", PARAM_LANDUSE='" + PARAM_LANDUSE + '\'' +
                ", PARAM_SOIL_TYPE='" + PARAM_SOIL_TYPE + '\'' +
                ", PARAM_TIMESTAMP='" + PARAM_TIMESTAMP + '\'' +
                ", PARAM_SOIL_DEPTH=" + PARAM_SOIL_DEPTH +
                ", PARAM_LATITUDE=" + PARAM_LATITUDE +
                ", PARAM_LONGITUDE=" + PARAM_LONGITUDE +
                '}';
    }

    public String getPARAM_DISTRICT() {
        return PARAM_DISTRICT;
    }

    public void setPARAM_DISTRICT(String PARAM_DISTRICT) {
        this.PARAM_DISTRICT = PARAM_DISTRICT;
    }

    public String getPARAM_TALUKA() {
        return PARAM_TALUKA;
    }

    public void setPARAM_TALUKA(String PARAM_TALUKA) {
        this.PARAM_TALUKA = PARAM_TALUKA;
    }

    public String getPARAM_VILLAGE() {
        return PARAM_VILLAGE;
    }

    public void setPARAM_VILLAGE(String PARAM_VILLAGE) {
        this.PARAM_VILLAGE = PARAM_VILLAGE;
    }

    public String getPARAM_FARMER_NAME() {
        return PARAM_FARMER_NAME;
    }

    public void setPARAM_FARMER_NAME(String PARAM_FARMER_NAME) {
        this.PARAM_FARMER_NAME = PARAM_FARMER_NAME;
    }

    public String getPARAM_CONTACT_NUMBER() {
        return PARAM_CONTACT_NUMBER;
    }

    public void setPARAM_CONTACT_NUMBER(String PARAM_CONTACT_NUMBER) {
        this.PARAM_CONTACT_NUMBER = PARAM_CONTACT_NUMBER;
    }

    public String getPARAM_GAT_NUMBER() {
        return PARAM_GAT_NUMBER;
    }

    public void setPARAM_GAT_NUMBER(String PARAM_GAT_NUMBER) {
        this.PARAM_GAT_NUMBER = PARAM_GAT_NUMBER;
    }

    public String getPARAM_CROP_NAME() {
        return PARAM_CROP_NAME;
    }

    public void setPARAM_CROP_NAME(String PARAM_CROP_NAME) {
        this.PARAM_CROP_NAME = PARAM_CROP_NAME;
    }

    public String getPARAM_LANDUSE() {
        return PARAM_LANDUSE;
    }

    public void setPARAM_LANDUSE(String PARAM_LANDUSE) {
        this.PARAM_LANDUSE = PARAM_LANDUSE;
    }

    public String getPARAM_SOIL_TYPE() {
        return PARAM_SOIL_TYPE;
    }

    public void setPARAM_SOIL_TYPE(String PARAM_SOIL_TYPE) {
        this.PARAM_SOIL_TYPE = PARAM_SOIL_TYPE;
    }

    public int getPARAM_SOIL_DEPTH() {
        return PARAM_SOIL_DEPTH;
    }

    public void setPARAM_SOIL_DEPTH(int PARAM_SOIL_DEPTH) {
        this.PARAM_SOIL_DEPTH = PARAM_SOIL_DEPTH;
    }

    public double getPARAM_LATITUDE() {
        return PARAM_LATITUDE;
    }

    public void setPARAM_LATITUDE(double PARAM_LATITUDE) {
        this.PARAM_LATITUDE = PARAM_LATITUDE;
    }

    public double getPARAM_LONGITUDE() {
        return PARAM_LONGITUDE;
    }

    public void setPARAM_LONGITUDE(double PARAM_LONGITUDE) {
        this.PARAM_LONGITUDE = PARAM_LONGITUDE;
    }

    public String getPARAM_TIMESTAMP() {
        return PARAM_TIMESTAMP;
    }

    public void setPARAM_TIMESTAMP(String PARAM_TIMESTAMP) {
        this.PARAM_TIMESTAMP = PARAM_TIMESTAMP;
    }

}
</code>```

GenericFileProvider.java

```<code>package com.zackdawood.csvreadwrite;

import android.support.v4.content.FileProvider;

public class GenericFileProvider extends FileProvider {
}
</code>```

strings.xml

```<code><resources>
    <string name="app_name">CSVReadWrite</string>
    <string name="write_button">Write CSV</string>
    <string name="read_button">Read CSV</string>
    <string name="request_access">Request Access</string>
</resources>
</code>```

external_files.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>
</code>```

MainActivity.java

```<code>package com.zackdawood.csvreadwrite;

import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private static final String[] PERMISSIONS = {android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE};

    private static boolean hasPermissions(Context context, String... permissions) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
            for (String permission : permissions) {
                if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                    return false;
                }
            }
        }
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS, 112);
        Log.v(TAG, "onCreate() Method invoked ");

    }

    public void read(View view) {
        File csvFILE = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Final.csv");
        Log.d(TAG, csvFILE.getAbsolutePath());
        Uri path = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider", csvFILE);

        try {
            CSVReader csvREAD = new CSVReader(new
                    FileReader(csvFILE));
            String[] csvLINE;
            int skip = 0;
            try {
                Log.d("I was here", "kk");
                while ((csvLINE = csvREAD.readNext()) != null) {
                    if (skip >= 0)//becasue first line is column headers
                    {
                        String PARAM_DISTRICT = csvLINE[0];
                        String PARAM_TALUKA = csvLINE[1];
                        String PARAM_VILLAGE = csvLINE[2];
                        String PARAM_FARMER_NAME = csvLINE[3];
                        String PARAM_CONTACT_NUMBER = csvLINE[4];
                        String PARAM_GAT_NUMBER = csvLINE[5];
                        String PARAM_CROP_NAME = csvLINE[6];
                        String PARAM_LANDUSE = csvLINE[7];
                        String PARAM_SOIL_TYPE = csvLINE[8];
                        int PARAM_SOIL_DEPTH = Integer.parseInt(csvLINE[9]);
                        double PARAM_LATITUDE = Double.parseDouble(csvLINE[10]);
                        double PARAM_LONGITUDE = Double.parseDouble(csvLINE[11]);
                        String PARAM_TIMESTAMP = csvLINE[12];

                        Data STUD_OBJECT = new Data(PARAM_DISTRICT, PARAM_TALUKA, PARAM_VILLAGE,
                                PARAM_FARMER_NAME, PARAM_CONTACT_NUMBER, PARAM_GAT_NUMBER,
                                PARAM_CROP_NAME, PARAM_LANDUSE, PARAM_SOIL_TYPE, PARAM_SOIL_DEPTH,
                                PARAM_LATITUDE, PARAM_LONGITUDE, PARAM_TIMESTAMP
                        );
                        //dataArray.add(STUD_OBJECT);
                        Toast.makeText(this, STUD_OBJECT.toString(), Toast.LENGTH_LONG).show();

                    } else {
                        skip++;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, "read() error" + e.getMessage());
                Log.e(TAG, "read() error" + e.getStackTrace());
            }

        } catch (FileNotFoundException e) {
            Log.e(TAG, "read() error" + e.getMessage());
            Log.e(TAG, "read() error" + e.getStackTrace());
            Toast.makeText(this, "Volley Error", Toast.LENGTH_SHORT).show();
        }
    }

    public void write(View view) {
        String Testfile_name = "Final";
        Testfile_name = Testfile_name + ".csv";
        File logFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), Testfile_name);
        if (!logFile.exists()) {
            try {
                logFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e(TAG, "write() error" + e.getMessage());
                Log.e(TAG, "write() error" + e.getStackTrace());
            }
        }

        try {
            String header = "District,Taluka,Village,Farmer_name,Contact_Number,Gat_Number,Crop_name,Landuse,Soil_Type,Soil_Depth,Latitude,Longitude,Timestamp";
            String[] stringList = new String[13];
            stringList[0] = "District";
            stringList[1] = "Taluka";
            stringList[2] = "Village";
            stringList[3] = "Farmer_name";
            stringList[4] = "Contact_Number";
            stringList[5] = "Gat_Number";
            stringList[6] = "Crop_name";
            stringList[7] = "Landuse";
            stringList[8] = "Soil_Type";
            stringList[9] = "1";
            stringList[10] = "2";
            stringList[11] = "2";
            stringList[12] = "2007-11-11 12:13:14";
            FileWriter fw = new FileWriter(logFile);
            CSVWriter writer = new CSVWriter(fw, ',');
            writer.writeNext(stringList);
            writer.close();
            fw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.e(TAG, "write() error" + e.getMessage());
            Log.e(TAG, "write() error" + e.getStackTrace());
        }

    }

    public void request(View view) {
        ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS, 112);
    }
}
</code>```

build.gradle

```<code>apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.zackdawood.csvreadwrite"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.opencsv:opencsv:4.0"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}
</code>```

activity_main.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="395dp"
        android:layout_height="715dp"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/write_button"
            android:onClick="write"/>

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/read_button"
            android:onClick="read"/>

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/request_access"
            android:onClick="request"/>
    </LinearLayout>
</android.support.constraint.ConstraintLayout>
</code>```

Code Layout

Code Output

Body:
I am trying to read an already created CSV file. The path variable shows the correct path as in the android app folder. Also, I have added the read and write external storage permission but still I get file not found exception as in Volley Error toast message.

Read CSV code:-

    String path = String.valueOf(this.getExternalFilesDir(null));
    Log.d("Path",path+"/Final.csv");
    File csvFILE = new File(path+"/","Final.csv");
    try {
        CSVReader csvREAD = new CSVReader(new
                FileReader(path));
        String[] csvLINE;
        int skip = 0;
        try {
            Log.d("I was here","kk");
            while((csvLINE = csvREAD.readNext())!=null)
            {
                if(skip > 0)//becasue first line is column headers
                {
                    String PARAM_DISTRICT = csvLINE[0];
                    String PARAM_TALUKA = csvLINE[1];
                    String PARAM_VILLAGE = csvLINE[2];
                    String PARAM_FARMER_NAME = csvLINE[3];
                    String PARAM_CONTACT_NUMBER = csvLINE[4];
                    String PARAM_GAT_NUMBER = csvLINE[5];
                    String PARAM_CROP_NAME = csvLINE[6];
                    String PARAM_LANDUSE = csvLINE[7];
                    String PARAM_SOIL_TYPE = csvLINE[8];
                    int PARAM_SOIL_DEPTH = Integer.parseInt(csvLINE[9]);
                    double PARAM_LATITUDE = Double.parseDouble(csvLINE[10]);
                    double PARAM_LONGITUDE = Double.parseDouble(csvLINE[11]);
                    String PARAM_TIMESTAMP = csvLINE[12];

                    Data STUD_OBJECT = new Data(PARAM_DISTRICT,PARAM_TALUKA,PARAM_VILLAGE,
                            PARAM_FARMER_NAME,PARAM_CONTACT_NUMBER,PARAM_GAT_NUMBER,
                            PARAM_CROP_NAME,PARAM_LANDUSE,PARAM_SOIL_TYPE,PARAM_SOIL_DEPTH,
                            PARAM_LATITUDE,PARAM_LONGITUDE,PARAM_TIMESTAMP
                    );
                    dataArray.add(STUD_OBJECT);
                }
                else
                {
                    skip ++;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (FileNotFoundException e) {
        Toast.makeText(this, "Volley Error", Toast.LENGTH_SHORT).show();
    }

The CSV file was created with the below code:

    String Testfile_name="Final";
    Testfile_name=Testfile_name+".csv";
    File logFile = new File(this.getExternalFilesDir(null), Testfile_name);
    if (!logFile.exists())
    {
        try
        {
            logFile.createNewFile();
            String header= "District,Taluka,Village,Farmer_name,Contact_Number,Gat_Number,Crop_name,Landuse,Soil_Type,Soil_Depth,Latitude,Longitude,Timestamp";
            appendLog(header);
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

Body:
The problem is how you are accessing the file

String path = String.valueOf(this.getExternalFilesDir(null));

needs to change to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

Check the example below, it works

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zackdawood.csvreadwrite">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <provider
            android:name=".GenericFileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/external_files"/>
        </provider>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Data.java

package com.zackdawood.csvreadwrite;

public class Data {

    private String PARAM_DISTRICT = "";
    private String PARAM_TALUKA = "";
    private String PARAM_VILLAGE = "";
    private String PARAM_FARMER_NAME = "";
    private String PARAM_CONTACT_NUMBER = "";
    private String PARAM_GAT_NUMBER = "";
    private String PARAM_CROP_NAME = "";
    private String PARAM_LANDUSE = "";
    private String PARAM_SOIL_TYPE = "";
    private String PARAM_TIMESTAMP = "";
    private int PARAM_SOIL_DEPTH = 0;
    private double PARAM_LATITUDE = 0;
    private double PARAM_LONGITUDE = 0;

    public Data(String PARAM_DISTRICT, String PARAM_TALUKA, String PARAM_VILLAGE, String PARAM_FARMER_NAME, String PARAM_CONTACT_NUMBER, String PARAM_GAT_NUMBER, String PARAM_CROP_NAME, String PARAM_LANDUSE, String PARAM_SOIL_TYPE, int PARAM_SOIL_DEPTH, double PARAM_LATITUDE, double PARAM_LONGITUDE, String PARAM_TIMESTAMP) {
        this.PARAM_DISTRICT = PARAM_DISTRICT;
        this.PARAM_TALUKA = PARAM_TALUKA;
        this.PARAM_VILLAGE = PARAM_VILLAGE;
        this.PARAM_FARMER_NAME = PARAM_FARMER_NAME;
        this.PARAM_CONTACT_NUMBER = PARAM_CONTACT_NUMBER;
        this.PARAM_GAT_NUMBER = PARAM_GAT_NUMBER;
        this.PARAM_CROP_NAME = PARAM_CROP_NAME;
        this.PARAM_LANDUSE = PARAM_LANDUSE;
        this.PARAM_SOIL_TYPE = PARAM_SOIL_TYPE;
        this.PARAM_SOIL_DEPTH = PARAM_SOIL_DEPTH;
        this.PARAM_LATITUDE = PARAM_LATITUDE;
        this.PARAM_LONGITUDE = PARAM_LONGITUDE;
        this.PARAM_TIMESTAMP = PARAM_TIMESTAMP;
    }

    @Override
    public String toString() {
        return "Data{" +
                "PARAM_DISTRICT='" + PARAM_DISTRICT + '\'' +
                ", PARAM_TALUKA='" + PARAM_TALUKA + '\'' +
                ", PARAM_VILLAGE='" + PARAM_VILLAGE + '\'' +
                ", PARAM_FARMER_NAME='" + PARAM_FARMER_NAME + '\'' +
                ", PARAM_CONTACT_NUMBER='" + PARAM_CONTACT_NUMBER + '\'' +
                ", PARAM_GAT_NUMBER='" + PARAM_GAT_NUMBER + '\'' +
                ", PARAM_CROP_NAME='" + PARAM_CROP_NAME + '\'' +
                ", PARAM_LANDUSE='" + PARAM_LANDUSE + '\'' +
                ", PARAM_SOIL_TYPE='" + PARAM_SOIL_TYPE + '\'' +
                ", PARAM_TIMESTAMP='" + PARAM_TIMESTAMP + '\'' +
                ", PARAM_SOIL_DEPTH=" + PARAM_SOIL_DEPTH +
                ", PARAM_LATITUDE=" + PARAM_LATITUDE +
                ", PARAM_LONGITUDE=" + PARAM_LONGITUDE +
                '}';
    }

    public String getPARAM_DISTRICT() {
        return PARAM_DISTRICT;
    }

    public void setPARAM_DISTRICT(String PARAM_DISTRICT) {
        this.PARAM_DISTRICT = PARAM_DISTRICT;
    }

    public String getPARAM_TALUKA() {
        return PARAM_TALUKA;
    }

    public void setPARAM_TALUKA(String PARAM_TALUKA) {
        this.PARAM_TALUKA = PARAM_TALUKA;
    }

    public String getPARAM_VILLAGE() {
        return PARAM_VILLAGE;
    }

    public void setPARAM_VILLAGE(String PARAM_VILLAGE) {
        this.PARAM_VILLAGE = PARAM_VILLAGE;
    }

    public String getPARAM_FARMER_NAME() {
        return PARAM_FARMER_NAME;
    }

    public void setPARAM_FARMER_NAME(String PARAM_FARMER_NAME) {
        this.PARAM_FARMER_NAME = PARAM_FARMER_NAME;
    }

    public String getPARAM_CONTACT_NUMBER() {
        return PARAM_CONTACT_NUMBER;
    }

    public void setPARAM_CONTACT_NUMBER(String PARAM_CONTACT_NUMBER) {
        this.PARAM_CONTACT_NUMBER = PARAM_CONTACT_NUMBER;
    }

    public String getPARAM_GAT_NUMBER() {
        return PARAM_GAT_NUMBER;
    }

    public void setPARAM_GAT_NUMBER(String PARAM_GAT_NUMBER) {
        this.PARAM_GAT_NUMBER = PARAM_GAT_NUMBER;
    }

    public String getPARAM_CROP_NAME() {
        return PARAM_CROP_NAME;
    }

    public void setPARAM_CROP_NAME(String PARAM_CROP_NAME) {
        this.PARAM_CROP_NAME = PARAM_CROP_NAME;
    }

    public String getPARAM_LANDUSE() {
        return PARAM_LANDUSE;
    }

    public void setPARAM_LANDUSE(String PARAM_LANDUSE) {
        this.PARAM_LANDUSE = PARAM_LANDUSE;
    }

    public String getPARAM_SOIL_TYPE() {
        return PARAM_SOIL_TYPE;
    }

    public void setPARAM_SOIL_TYPE(String PARAM_SOIL_TYPE) {
        this.PARAM_SOIL_TYPE = PARAM_SOIL_TYPE;
    }

    public int getPARAM_SOIL_DEPTH() {
        return PARAM_SOIL_DEPTH;
    }

    public void setPARAM_SOIL_DEPTH(int PARAM_SOIL_DEPTH) {
        this.PARAM_SOIL_DEPTH = PARAM_SOIL_DEPTH;
    }

    public double getPARAM_LATITUDE() {
        return PARAM_LATITUDE;
    }

    public void setPARAM_LATITUDE(double PARAM_LATITUDE) {
        this.PARAM_LATITUDE = PARAM_LATITUDE;
    }

    public double getPARAM_LONGITUDE() {
        return PARAM_LONGITUDE;
    }

    public void setPARAM_LONGITUDE(double PARAM_LONGITUDE) {
        this.PARAM_LONGITUDE = PARAM_LONGITUDE;
    }

    public String getPARAM_TIMESTAMP() {
        return PARAM_TIMESTAMP;
    }

    public void setPARAM_TIMESTAMP(String PARAM_TIMESTAMP) {
        this.PARAM_TIMESTAMP = PARAM_TIMESTAMP;
    }

}

GenericFileProvider.java

package com.zackdawood.csvreadwrite;

import android.support.v4.content.FileProvider;

public class GenericFileProvider extends FileProvider {
}

strings.xml

<resources>
    <string name="app_name">CSVReadWrite</string>
    <string name="write_button">Write CSV</string>
    <string name="read_button">Read CSV</string>
    <string name="request_access">Request Access</string>
</resources>

external_files.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

MainActivity.java

package com.zackdawood.csvreadwrite;

import android.content.Context;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private static final String[] PERMISSIONS = {android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE};

    private static boolean hasPermissions(Context context, String... permissions) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
            for (String permission : permissions) {
                if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                    return false;
                }
            }
        }
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS, 112);
        Log.v(TAG, "onCreate() Method invoked ");

    }

    public void read(View view) {
        File csvFILE = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Final.csv");
        Log.d(TAG, csvFILE.getAbsolutePath());
        Uri path = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider", csvFILE);

        try {
            CSVReader csvREAD = new CSVReader(new
                    FileReader(csvFILE));
            String[] csvLINE;
            int skip = 0;
            try {
                Log.d("I was here", "kk");
                while ((csvLINE = csvREAD.readNext()) != null) {
                    if (skip >= 0)//becasue first line is column headers
                    {
                        String PARAM_DISTRICT = csvLINE[0];
                        String PARAM_TALUKA = csvLINE[1];
                        String PARAM_VILLAGE = csvLINE[2];
                        String PARAM_FARMER_NAME = csvLINE[3];
                        String PARAM_CONTACT_NUMBER = csvLINE[4];
                        String PARAM_GAT_NUMBER = csvLINE[5];
                        String PARAM_CROP_NAME = csvLINE[6];
                        String PARAM_LANDUSE = csvLINE[7];
                        String PARAM_SOIL_TYPE = csvLINE[8];
                        int PARAM_SOIL_DEPTH = Integer.parseInt(csvLINE[9]);
                        double PARAM_LATITUDE = Double.parseDouble(csvLINE[10]);
                        double PARAM_LONGITUDE = Double.parseDouble(csvLINE[11]);
                        String PARAM_TIMESTAMP = csvLINE[12];

                        Data STUD_OBJECT = new Data(PARAM_DISTRICT, PARAM_TALUKA, PARAM_VILLAGE,
                                PARAM_FARMER_NAME, PARAM_CONTACT_NUMBER, PARAM_GAT_NUMBER,
                                PARAM_CROP_NAME, PARAM_LANDUSE, PARAM_SOIL_TYPE, PARAM_SOIL_DEPTH,
                                PARAM_LATITUDE, PARAM_LONGITUDE, PARAM_TIMESTAMP
                        );
                        //dataArray.add(STUD_OBJECT);
                        Toast.makeText(this, STUD_OBJECT.toString(), Toast.LENGTH_LONG).show();

                    } else {
                        skip++;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, "read() error" + e.getMessage());
                Log.e(TAG, "read() error" + e.getStackTrace());
            }

        } catch (FileNotFoundException e) {
            Log.e(TAG, "read() error" + e.getMessage());
            Log.e(TAG, "read() error" + e.getStackTrace());
            Toast.makeText(this, "Volley Error", Toast.LENGTH_SHORT).show();
        }
    }

    public void write(View view) {
        String Testfile_name = "Final";
        Testfile_name = Testfile_name + ".csv";
        File logFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), Testfile_name);
        if (!logFile.exists()) {
            try {
                logFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.e(TAG, "write() error" + e.getMessage());
                Log.e(TAG, "write() error" + e.getStackTrace());
            }
        }

        try {
            String header = "District,Taluka,Village,Farmer_name,Contact_Number,Gat_Number,Crop_name,Landuse,Soil_Type,Soil_Depth,Latitude,Longitude,Timestamp";
            String[] stringList = new String[13];
            stringList[0] = "District";
            stringList[1] = "Taluka";
            stringList[2] = "Village";
            stringList[3] = "Farmer_name";
            stringList[4] = "Contact_Number";
            stringList[5] = "Gat_Number";
            stringList[6] = "Crop_name";
            stringList[7] = "Landuse";
            stringList[8] = "Soil_Type";
            stringList[9] = "1";
            stringList[10] = "2";
            stringList[11] = "2";
            stringList[12] = "2007-11-11 12:13:14";
            FileWriter fw = new FileWriter(logFile);
            CSVWriter writer = new CSVWriter(fw, ',');
            writer.writeNext(stringList);
            writer.close();
            fw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.e(TAG, "write() error" + e.getMessage());
            Log.e(TAG, "write() error" + e.getStackTrace());
        }

    }

    public void request(View view) {
        ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS, 112);
    }
}

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.zackdawood.csvreadwrite"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.opencsv:opencsv:4.0"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="395dp"
        android:layout_height="715dp"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/write_button"
            android:onClick="write"/>

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/read_button"
            android:onClick="read"/>

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/request_access"
            android:onClick="request"/>
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

Code Layout

Code Output


问:
Convert pythonecode into c#
I have to integrate to some device that needs to generate some id
this device has no SDK or API but, I have found some project in python that works fine.

for now, iv tested the option to run the python script as a process
but it's not good option.

Code :

TRANSID_PREFIX = 'web'
def genTransId(self, trans_type=TRANSID_PREFIX):
        def float2hex(f):
            MAXHEXADECIMALS = 15
            w = f // 1
            d = f % 1

            # Do the whole:
            if w == 0: result = '0'
            else: result = ''
            while w:
                w, r = divmod(w, 16)
                r = int(r)
                if r > 9: r = chr(r+55)
                else: r = str(r)
                result =  r + result

            # And now the part:
            if d == 0: return result

            result += '.'
            count = 0
            while d:
                d = d * 16
                w, d = divmod(d, 1)
                w = int(w)
                if w > 9: w = chr(w+55)
                else: w = str(w)
                result +=  w
                count += 1
                if count > MAXHEXADECIMALS: break

            return result

        now = datetime.today()
        return trans_type+"!" + float2hex(random.random() * math.pow(2, 32)).lower() + "!" + str(int((time.mktime(now.timetuple())*1e3 + now.microsecond/1e3)))
```

答:
Tool to convert python to c#
and
https://github.com/uxmal/pytocs

But, can you give some more info on your statement:
"iv tested the option to run the python script as a process but it's not good option" ?

Title: Convert pythonecode into c#


问:
Need help with openURL:[NSURL URLWithString:@"tel:+91 (number)"]] from an iPhone app
I need to call a number +91 (number),but if i use tel:// url it does not make a call from a iphone app.
How to call a number coming in any format.</p>

答:
The iphone will dial a number using either of the formats listed below.

```<code>[[UIApplication sharedApplication]
                    openURL:[NSURL URLWithString:@"tel://15415551234"]];

[[UIApplication sharedApplication]
                    openURL:[NSURL URLWithString:@"tel:15415551234"]];

[[UIApplication sharedApplication]
                    openURL:[NSURL URLWithString:@"tel:1-541-555-1234"]];
</code>```

Link for Apple documentation on the tel: url scheme

Body:
The iphone will dial a number using either of the formats listed below.

[[UIApplication sharedApplication]
                    openURL:[NSURL URLWithString:@"tel://15415551234"]];

[[UIApplication sharedApplication]
                    openURL:[NSURL URLWithString:@"tel:15415551234"]];

[[UIApplication sharedApplication]
                    openURL:[NSURL URLWithString:@"tel:1-541-555-1234"]];

Link for Apple documentation on the tel: url scheme


问:
Kubernetes 1.14.2 HA Master NGINX load balancer log.go:172] http: TLS handshake error from 192.168.5.32:43148: remote error: tls: bad certificate
This is driving me crazy, I am NO Kubernetes expert but I am also not a novice.

I have tried unsuccessfully for three days to get past this issue but I can't and I am at the end of my rope.

I can query the cluster from my desktop after I copied the certificates from (kube-apiserver-1:/etc/kubernetes/pki/*) to my desktop.

```<code>$ kubectl -n kube-system get nodes
NAME               STATUS   ROLES    AGE   VERSION
kube-apiserver-1   Ready    master   71m   v1.14.2
</code>```

The Kubernetes cluster appears healthy when I query the kube-system pods:

```<code>$ kubectl -n kube-system get pods
NAME                                       READY   STATUS    RESTARTS   AGE
coredns-fb8b8dccf-6c85q                    1/1     Running   3          65m
coredns-fb8b8dccf-qwxlp                    1/1     Running   3          65m
kube-apiserver-kube-apiserver-1            1/1     Running   2          72m
kube-controller-manager-kube-apiserver-1   1/1     Running   2          72m
kube-flannel-ds-amd64-phntk                1/1     Running   2          62m
kube-proxy-swxrz                           1/1     Running   2          65m
kube-scheduler-kube-apiserver-1            1/1     Running   1          54m
</code>```

but when I query the api kubelet:

```<code>$ kubectl -n kube-system logs kube-apiserver-kube-apiserver-1
...
I0526 04:33:51.523828       1 log.go:172] http: TLS handshake error from 192.168.5.32:43122: remote error: tls: bad certificate
I0526 04:33:51.537258       1 log.go:172] http: TLS handshake error from 192.168.5.32:43124: remote error: tls: bad certificate
I0526 04:33:51.540617       1 log.go:172] http: TLS handshake error from 192.168.5.32:43126: remote error: tls: bad certificate
I0526 04:33:52.333817       1 log.go:172] http: TLS handshake error from 192.168.5.32:43130: remote error: tls: bad certificate
I0526 04:33:52.334354       1 log.go:172] http: TLS handshake error from 192.168.5.32:43128: remote error: tls: bad certificate
I0526 04:33:52.335570       1 log.go:172] http: TLS handshake error from 192.168.5.32:43132: remote error: tls: bad certificate
I0526 04:33:52.336703       1 log.go:172] http: TLS handshake error from 192.168.5.32:43134: remote error: tls: bad certificate
I0526 04:33:52.338792       1 log.go:172] http: TLS handshake error from 192.168.5.32:43136: remote error: tls: bad certificate
I0526 04:33:52.391557       1 log.go:172] http: TLS handshake error from 192.168.5.32:43138: remote error: tls: bad certificate
I0526 04:33:52.396566       1 log.go:172] http: TLS handshake error from 192.168.5.32:43140: remote error: tls: bad certificate
I0526 04:33:52.519666       1 log.go:172] http: TLS handshake error from 192.168.5.32:43142: remote error: tls: bad certificate
I0526 04:33:52.524702       1 log.go:172] http: TLS handshake error from 192.168.5.32:43144: remote error: tls: bad certificate
I0526 04:33:52.537127       1 log.go:172] http: TLS handshake error from 192.168.5.32:43146: remote error: tls: bad certificate
I0526 04:33:52.550177       1 log.go:172] http: TLS handshake error from 192.168.5.32:43150: remote error: tls: bad certificate
I0526 04:33:52.550613       1 log.go:172] http: TLS handshake error from 192.168.5.32:43148: remote error: tls: bad certificate
</code>```

On the NGINX load balancer (IP: 192.168.5.32) I have configured the TCP passthrough option as specified in the Kubernetes documentation:

```<code>upstream kubernetes-api-cluster {
   server 192.168.5.19:6443;
   server 192.168.5.29:6443;
}
server {
   listen 6443;
   ssl_certificate /etc/nginx/ssl/kube-apiserver.pem;
   ssl_certificate_key /etc/nginx/ssl/private/kube-apiserver.key;
   ssl_prefer_server_ciphers on;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
   proxy_pass kubernetes-api-cluster;
}
</code>```

I can query the API server directly from the NGINX LB (IP: 192.168.5.32):

```<code>$ curl -v https://192.168.5.29:6443
* Rebuilt URL to: https://192.168.5.29:6443/
*   Trying 192.168.5.29...
* TCP_NODELAY set
* Connected to 192.168.5.29 (192.168.5.29) port 6443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=kube-apiserver
*  start date: May 26 03:39:36 2019 GMT
*  expire date: May 25 03:39:36 2020 GMT
*  subjectAltName: host "192.168.5.29" matched cert's IP address!
*  issuer: CN=kubernetes
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55840f1d9900)
> GET / HTTP/2
> Host: 192.168.5.29:6443
> User-Agent: curl/7.58.0
> Accept: */*
</code>```

I can also query the api using the DNS entry to the api as specified in the documents:

```<code>curl -v https://kube-apiserver.mydomain.com:6443
* Rebuilt URL to: https://kube-apiserver.mydomain.com:6443/
*   Trying 10.50.1.50...
* TCP_NODELAY set
* Connected to kube-apiserver.mydomain.com (10.50.1.50) port 6443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=kube-apiserver
*  start date: May 26 03:39:36 2019 GMT
*  expire date: May 25 03:39:36 2020 GMT
*  subjectAltName: host "kube-apiserver.mydomain.com" matched cert's "kube-apiserver.mydomain.com"
*  issuer: CN=kubernetes
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x564287cbd900)
> GET / HTTP/2
> Host: kube-apiserver.mydomain.com:6443
> User-Agent: curl/7.58.0
> Accept: */*
</code>```

I can query the api server using curl as well on the API server:

```<code>curl -v https://kube-apiserver.mydomain.com:6443
* Rebuilt URL to: https://kube-apiserver.mydomain.com:6443/
*   Trying 10.50.1.50...
* TCP_NODELAY set
* Connected to kube-apiserver.epc-instore.com (10.50.1.50) port 6443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=kube-apiserver
*  start date: May 26 03:39:36 2019 GMT
*  expire date: May 25 03:39:36 2020 GMT
*  subjectAltName: host "kube-apiserver.mydomain.com" matched cert's "kube-apiserver.mydomain.com"
*  issuer: CN=kubernetes
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5628b9dbc900)
> GET / HTTP/2
> Host: kube-apiserver.mydomain.com:6443
> User-Agent: curl/7.58.0
> Accept: */*
</code>```

The manifest on the api server contains:

```<code>cat /etc/kubernetes/manifest/kube-apiserver.yaml
...
  - command:
    - kube-apiserver
    - --advertise-address=192.168.5.29
    - --allow-privileged=true
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction
    - --enable-bootstrap-token-auth=true
    - --etcd-servers=http://etcd-cluster.mydomain.com:2379
    - --insecure-port=0
    - --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
    - --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
    - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
    - --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
    - --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
    - --requestheader-allowed-names=front-proxy-client
    - --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
    - --requestheader-extra-headers-prefix=X-Remote-Extra-
    - --requestheader-group-headers=X-Remote-Group
    - --requestheader-username-headers=X-Remote-User
    - --secure-port=6443
    - --service-account-key-file=/etc/kubernetes/pki/sa.pub
    - --service-cluster-ip-range=10.96.0.0/12
    - --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
    - --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
    image: k8s.gcr.io/kube-apiserver:v1.14.2
    imagePullPolicy: IfNotPresent
...
</code>```

If you have any idea or hints on how to fix this I am all ears.  I am so frustrated with this issue, it really has gotten to me at this point.  I will continue to work on it but if anyone has a clue about this issue and can help it will be great.

Thank you.

答:
Your current nginx config isn't setting up a client cert. ssl_certificate is the server cert, if you want it to present a client cert to kubernetes-api-cluster you'll have to configure nginx to forward the incoming client certificate. I've previously done this using proxy_set_header X-SSL-CERT $ssl_client_escaped_cert (documentation)

```<code>upstream kubernetes-api-cluster {
    server 192.168.5.19:6443;
    server 192.168.5.29:6443;
}

server {
    listen 6443;
    ssl_certificate /etc/nginx/ssl/kube-apiserver.pem;
    ssl_certificate_key /etc/nginx/ssl/private/kube-apiserver.key;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
    proxy_pass kubernetes-api-cluster;

    #forward incoming client certificate
    ssl_verify_client optional; #requests the client certificate and verifies it if the certificate is present
    proxy_set_header X-SSL-CERT $ssl_client_escaped_cert;
}
</code>```

Body:
This is driving me crazy, I am NO Kubernetes expert but I am also not a novice.

I have tried unsuccessfully for three days to get past this issue but I can't and I am at the end of my rope.

I can query the cluster from my desktop after I copied the certificates from (kube-apiserver-1:/etc/kubernetes/pki/*) to my desktop.

$ kubectl -n kube-system get nodes
NAME               STATUS   ROLES    AGE   VERSION
kube-apiserver-1   Ready    master   71m   v1.14.2

The Kubernetes cluster appears healthy when I query the kube-system pods:

$ kubectl -n kube-system get pods
NAME                                       READY   STATUS    RESTARTS   AGE
coredns-fb8b8dccf-6c85q                    1/1     Running   3          65m
coredns-fb8b8dccf-qwxlp                    1/1     Running   3          65m
kube-apiserver-kube-apiserver-1            1/1     Running   2          72m
kube-controller-manager-kube-apiserver-1   1/1     Running   2          72m
kube-flannel-ds-amd64-phntk                1/1     Running   2          62m
kube-proxy-swxrz                           1/1     Running   2          65m
kube-scheduler-kube-apiserver-1            1/1     Running   1          54m

but when I query the api kubelet:

$ kubectl -n kube-system logs kube-apiserver-kube-apiserver-1
...
I0526 04:33:51.523828       1 log.go:172] http: TLS handshake error from 192.168.5.32:43122: remote error: tls: bad certificate
I0526 04:33:51.537258       1 log.go:172] http: TLS handshake error from 192.168.5.32:43124: remote error: tls: bad certificate
I0526 04:33:51.540617       1 log.go:172] http: TLS handshake error from 192.168.5.32:43126: remote error: tls: bad certificate
I0526 04:33:52.333817       1 log.go:172] http: TLS handshake error from 192.168.5.32:43130: remote error: tls: bad certificate
I0526 04:33:52.334354       1 log.go:172] http: TLS handshake error from 192.168.5.32:43128: remote error: tls: bad certificate
I0526 04:33:52.335570       1 log.go:172] http: TLS handshake error from 192.168.5.32:43132: remote error: tls: bad certificate
I0526 04:33:52.336703       1 log.go:172] http: TLS handshake error from 192.168.5.32:43134: remote error: tls: bad certificate
I0526 04:33:52.338792       1 log.go:172] http: TLS handshake error from 192.168.5.32:43136: remote error: tls: bad certificate
I0526 04:33:52.391557       1 log.go:172] http: TLS handshake error from 192.168.5.32:43138: remote error: tls: bad certificate
I0526 04:33:52.396566       1 log.go:172] http: TLS handshake error from 192.168.5.32:43140: remote error: tls: bad certificate
I0526 04:33:52.519666       1 log.go:172] http: TLS handshake error from 192.168.5.32:43142: remote error: tls: bad certificate
I0526 04:33:52.524702       1 log.go:172] http: TLS handshake error from 192.168.5.32:43144: remote error: tls: bad certificate
I0526 04:33:52.537127       1 log.go:172] http: TLS handshake error from 192.168.5.32:43146: remote error: tls: bad certificate
I0526 04:33:52.550177       1 log.go:172] http: TLS handshake error from 192.168.5.32:43150: remote error: tls: bad certificate
I0526 04:33:52.550613       1 log.go:172] http: TLS handshake error from 192.168.5.32:43148: remote error: tls: bad certificate

On the NGINX load balancer (IP: 192.168.5.32) I have configured the TCP passthrough option as specified in the Kubernetes documentation:

upstream kubernetes-api-cluster {
   server 192.168.5.19:6443;
   server 192.168.5.29:6443;
}
server {
   listen 6443;
   ssl_certificate /etc/nginx/ssl/kube-apiserver.pem;
   ssl_certificate_key /etc/nginx/ssl/private/kube-apiserver.key;
   ssl_prefer_server_ciphers on;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
   proxy_pass kubernetes-api-cluster;
}

I can query the API server directly from the NGINX LB (IP: 192.168.5.32):

$ curl -v https://192.168.5.29:6443
* Rebuilt URL to: https://192.168.5.29:6443/
*   Trying 192.168.5.29...
* TCP_NODELAY set
* Connected to 192.168.5.29 (192.168.5.29) port 6443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=kube-apiserver
*  start date: May 26 03:39:36 2019 GMT
*  expire date: May 25 03:39:36 2020 GMT
*  subjectAltName: host "192.168.5.29" matched cert's IP address!
*  issuer: CN=kubernetes
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x55840f1d9900)
> GET / HTTP/2
> Host: 192.168.5.29:6443
> User-Agent: curl/7.58.0
> Accept: */*

I can also query the api using the DNS entry to the api as specified in the documents:

curl -v https://kube-apiserver.mydomain.com:6443
* Rebuilt URL to: https://kube-apiserver.mydomain.com:6443/
*   Trying 10.50.1.50...
* TCP_NODELAY set
* Connected to kube-apiserver.mydomain.com (10.50.1.50) port 6443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=kube-apiserver
*  start date: May 26 03:39:36 2019 GMT
*  expire date: May 25 03:39:36 2020 GMT
*  subjectAltName: host "kube-apiserver.mydomain.com" matched cert's "kube-apiserver.mydomain.com"
*  issuer: CN=kubernetes
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x564287cbd900)
> GET / HTTP/2
> Host: kube-apiserver.mydomain.com:6443
> User-Agent: curl/7.58.0
> Accept: */*

I can query the api server using curl as well on the API server:

curl -v https://kube-apiserver.mydomain.com:6443
* Rebuilt URL to: https://kube-apiserver.mydomain.com:6443/
*   Trying 10.50.1.50...
* TCP_NODELAY set
* Connected to kube-apiserver.epc-instore.com (10.50.1.50) port 6443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=kube-apiserver
*  start date: May 26 03:39:36 2019 GMT
*  expire date: May 25 03:39:36 2020 GMT
*  subjectAltName: host "kube-apiserver.mydomain.com" matched cert's "kube-apiserver.mydomain.com"
*  issuer: CN=kubernetes
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5628b9dbc900)
> GET / HTTP/2
> Host: kube-apiserver.mydomain.com:6443
> User-Agent: curl/7.58.0
> Accept: */*

The manifest on the api server contains:

cat /etc/kubernetes/manifest/kube-apiserver.yaml
...
  - command:
    - kube-apiserver
    - --advertise-address=192.168.5.29
    - --allow-privileged=true
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction
    - --enable-bootstrap-token-auth=true
    - --etcd-servers=http://etcd-cluster.mydomain.com:2379
    - --insecure-port=0
    - --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
    - --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
    - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
    - --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
    - --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
    - --requestheader-allowed-names=front-proxy-client
    - --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
    - --requestheader-extra-headers-prefix=X-Remote-Extra-
    - --requestheader-group-headers=X-Remote-Group
    - --requestheader-username-headers=X-Remote-User
    - --secure-port=6443
    - --service-account-key-file=/etc/kubernetes/pki/sa.pub
    - --service-cluster-ip-range=10.96.0.0/12
    - --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
    - --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
    image: k8s.gcr.io/kube-apiserver:v1.14.2
    imagePullPolicy: IfNotPresent
...

If you have any idea or hints on how to fix this I am all ears.  I am so frustrated with this issue, it really has gotten to me at this point.  I will continue to work on it but if anyone has a clue about this issue and can help it will be great.

Thank you.

Body:
Your current nginx config isn't setting up a client cert. ssl_certificate is the server cert, if you want it to present a client cert to kubernetes-api-cluster you'll have to configure nginx to forward the incoming client certificate. I've previously done this using proxy_set_header X-SSL-CERT $ssl_client_escaped_cert (documentation)

upstream kubernetes-api-cluster {
    server 192.168.5.19:6443;
    server 192.168.5.29:6443;
}

server {
    listen 6443;
    ssl_certificate /etc/nginx/ssl/kube-apiserver.pem;
    ssl_certificate_key /etc/nginx/ssl/private/kube-apiserver.key;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
    proxy_pass kubernetes-api-cluster;

    #forward incoming client certificate
    ssl_verify_client optional; #requests the client certificate and verifies it if the certificate is present
    proxy_set_header X-SSL-CERT $ssl_client_escaped_cert;
}


问:
Using state from other class
I'm creating my university project. Some kind of tracker using ReactJS as frontend and I wan't to have global variable, used in any class I want to. This variable gonna be responsible for things shown at the screen. Let's say there are 10 users. I'm on first and after I use button, variable increases, I'm sending web request with other ID and next user loads. Is there any way to have such variable? Can I use "globalID" like that? I want to go step by step. At this moment I just want to have such global variable. I'm gonna think about rendering and web request later.

Untill now I've tried to extend from App, so I can maybe use this state value. Still, nothing worked. Idk, maybe there is method for that.

```<code>class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      globalID: "",
      ...
    };
  }

  ...
}

class Proteges extends App {
  constructor(props) {
    super(props);
    this.state = {
      ...
      userResponse: []
    };
    ...
  }

  ...

  getUserByID() {
    fetch(`http://localhost:9000/proteges/${HERE I WANT TO USE globalID}`)
      .then(res => res.json())
      .then(res => this.setState({ userResponse: res }))
      .catch(err => err);
  }

  ...

  componentDidMount() {
    ...
    this.getUserByID();
  }

  increaseID() {
        // FUNCTION TO INCREASE ID
        console.log(...)
  }

  decreaseID() {
        // FUNCTION TO DECREASE ID
        console.log(...)
  }
 ...

  render() {
    return (
      <div id="proteges">
        <div>
          <span>
          <!-- THIS BUTTON SHOULD DECREASE globalID by 1 and reload #proteges div -->
            <Button
            variant="success"
            size="md"
            onClick={this.increaseID}
            active>
              <strong> « </strong>
            </Button>
          </span>
          ...
          <span>
          <!-- THIS BUTTON SHOULD INCREASE globalID by 1 and reload #proteges div -->
            <Button
            variant="success"
            size="md"
            onClick={this.decreaseID}
            active>
              <strong> » </strong>
            </Button>
          </span>
        </div>
        ...
    );
  }
}

...

export default App;
```
```

答: You could try experimenting with window.globalID = '<id_here>' and/or localStorage.setItem('GlobalID', '<id_here>') and localStorage.getItem('GlobalID').

Title: Using state from other class

Body:
I'm creating my university project. Some kind of tracker using ReactJS as frontend and I wan't to have global variable, used in any class I want to. This variable gonna be responsible for things shown at the screen. Let's say there are 10 users. I'm on first and after I use button, variable increases, I'm sending web request with other ID and next user loads. Is there any way to have such variable? Can I use "globalID" like that? I want to go step by step. At this moment I just want to have such global variable. I'm gonna think about rendering and web request later.

Untill now I've tried to extend from App, so I can maybe use this state value. Still, nothing worked. Idk, maybe there is method for that.

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      globalID: "",
      ...
    };
  }

  ...
}

class Proteges extends App {
  constructor(props) {
    super(props);
    this.state = {
      ...
      userResponse: []
    };
    ...
  }

  ...

  getUserByID() {
    fetch(`http://localhost:9000/proteges/${HERE I WANT TO USE globalID}`)
      .then(res => res.json())
      .then(res => this.setState({ userResponse: res }))
      .catch(err => err);
  }

  ...

  componentDidMount() {
    ...
    this.getUserByID();
  }

  increaseID() {
        // FUNCTION TO INCREASE ID
        console.log(...)
  }

  decreaseID() {
        // FUNCTION TO DECREASE ID
        console.log(...)
  }
 ...

  render() {
    return (

            <Button
            variant="success"
            size="md"
            onClick={this.increaseID}
            active>
               «
            </Button>

          ...

            <Button
            variant="success"
            size="md"
            onClick={this.decreaseID}
            active>
               »
            </Button>

        ...
    );
  }
}

...

export default App;
```


问:
Exporting php data in a loop to CSV file
I have written a code which uses the API of fantasypremierleague.com to extract data. The data is being extracted for 38 gameweeks using a for loop. I print the data using echo to verify that it is correct.
I am having a problem converting the data into CSV files using a script since its in a loop.
After printing information each gameweek i have added a button (in total 38 buttons) which should convert the information of each gameweek to a CSV file.

Currently, all the buttons are printing the information of gameweek 1 even though the script is part of the loop.

```<code>ini_set('max_execution_time', 300);
for ($i=1; $i <39 ; $i++) {

$json=file_get_contents("https://fantasy.premierleague.com/drf/entry/1224012/event/".$i."/picks");
$data = json_decode($json, true);
$json1=file_get_contents("https://fantasy.premierleague.com/drf/elements/");
$data1 = json_decode($json1, true);

?>

<table id ="gameweek_history">
<tr>
 <th>Average Gameweek Score</th>
 <th>Highest Score</th>
 <th>Highest Scorer ID</th>
</tr>
</br>
</br>

<td><?PHP echo $data['event']['average_entry_score']; ?></td>
<td><?PHP echo $data['event']['highest_score']; ?></td>
<td><?PHP echo $data['event']['highest_scoring_entry']; ?></td>

</table>

<table id ="gameweek_info">
<tr>
 <th>Gameweek</th>
 <th>Active Chip</th>
 <th>ID</th>
 <th>Points</th>
 <th>Total Points</th>
 <th>Rank</th>
 <th>Overall Rank</th>
 <th>Gameweek Transfers</th>
 <th>Gameweek Transfer Cost</th>
 <th>Points on Bench</th>
 <th>Bank</th>
 </tr>
 </br>
 </br>

<td><?PHP echo $data['entry_history']['event']; ?></td>
<td><?PHP echo $data['active_chip']; ?></td>
<td><?PHP echo $data['entry_history']['id']; ?></td>
<td><?PHP echo $data['entry_history']['points']; ?></td>
<td><?PHP echo $data['entry_history']['total_points']; ?></td>
<td><?PHP echo $data['entry_history']['rank']; ?></td>
<td><?PHP echo $data['entry_history']['overall_rank']; ?></td>
<td><?PHP echo $data['entry_history']['event_transfers']; ?></td>
<td><?PHP echo $data['entry_history']['event_transfers_cost']; ?></td>
<td><?PHP echo $data['entry_history']['points_on_bench']; ?></td>
<td><?PHP echo $data['entry_history']['bank']; ?></td>

</table>

</br>
</br>
</br>

<script>function doCSV() {
 var table1 = document.getElementById("gameweek_history").innerHTML;
 var data1 = table1.replace(/<thead>/g, '')
 .replace(/<\/thead>/g, '')
 .replace(/<tbody>/g, '')
 .replace(/<\/tbody>/g, '')
 .replace(/<tr>/g, '')
 .replace(/<\/tr>/g, '\r\n')
 .replace(/<th>/g, '')
 .replace(/<\/th>/g, ',')
 .replace(/<td>/g, '')
 .replace(/<\/td>/g, ',')
 .replace(/\t/g, '')
 .replace(/\n/g, '');
 var table2 = document.getElementById("gameweek_info").innerHTML;
 var data2 = table2.replace(/<thead>/g, '')
 .replace(/<\/thead>/g, '')
 .replace(/<tbody>/g, '')
 .replace(/<\/tbody>/g, '')
 .replace(/<tr>/g, '')
 .replace(/<\/tr>/g, '\r\n')
 .replace(/<th>/g, '')
 .replace(/<\/th>/g, ',')
 .replace(/<td>/g, '')
 .replace(/<\/td>/g, ',')
 .replace(/\t/g, '')
 .replace(/\n/g, '');
 var data= data1.concat(data2);
 var mylink = document.createElement('a');
 mylink.download = "Gameweek.csv";
 mylink.href = "data:application/csv," + escape(data);
 mylink.click();
}</script>

<button onclick="doCSV()">Export HTML Table To CSV File</button>

<?PHP
}
?>
</code>```

I expect each button to convert the information of the particular gameweek which the loop is currently on (for e.g. i i=1 then gameweek 1 team should be exported, if i=2 then gameweek2 team should be exported)

答:
You'll need to add unique ids to every table like:

```<code><table id ="gameweek_history<? echo $i; ?>">
</code>```

Then you'll need to have your javascript refer to the id. Your existing code creates a new script for every table, so to keep doing that, each function will need a unique name that has refers to that table.

```<code><script>function doCSV<? echo $i; ?>() {
var table1 = document.getElementById("gameweek_history<? echo $i; ?>").innerHTML;
</code>```

It would probably be better to just have one function declared outside the loop with a variable passed into it.

```<code><script>function doCSV(table_number) {
var table1 = document.getElementById("gameweek_history" + table_number).innerHTML;
</code>```

Then add the table number to each event handler.

```<code><button onclick="doCSV(<? echo $i; ?>)">Export HTML Table To CSV File</button>
</code>```

Body:
I have written a code which uses the API of fantasypremierleague.com to extract data. The data is being extracted for 38 gameweeks using a for loop. I print the data using echo to verify that it is correct.
I am having a problem converting the data into CSV files using a script since its in a loop.
After printing information each gameweek i have added a button (in total 38 buttons) which should convert the information of each gameweek to a CSV file.

Currently, all the buttons are printing the information of gameweek 1 even though the script is part of the loop.

ini_set('max_execution_time', 300);
for ($i=1; $i <39 ; $i++) {

$json=file_get_contents("https://fantasy.premierleague.com/drf/entry/1224012/event/".$i."/picks");
$data = json_decode($json, true);
$json1=file_get_contents("https://fantasy.premierleague.com/drf/elements/");
$data1 = json_decode($json1, true);

?>

 Average Gameweek Score
 Highest Score
 Highest Scorer ID

<?PHP echo $data['event']['average_entry_score']; ?>
<?PHP echo $data['event']['highest_score']; ?>
<?PHP echo $data['event']['highest_scoring_entry']; ?>

 Gameweek
 Active Chip
 ID
 Points
 Total Points
 Rank
 Overall Rank
 Gameweek Transfers
 Gameweek Transfer Cost
 Points on Bench
 Bank

<?PHP echo $data['entry_history']['event']; ?>
<?PHP echo $data['active_chip']; ?>
<?PHP echo $data['entry_history']['id']; ?>
<?PHP echo $data['entry_history']['points']; ?>
<?PHP echo $data['entry_history']['total_points']; ?>
<?PHP echo $data['entry_history']['rank']; ?>
<?PHP echo $data['entry_history']['overall_rank']; ?>
<?PHP echo $data['entry_history']['event_transfers']; ?>
<?PHP echo $data['entry_history']['event_transfers_cost']; ?>
<?PHP echo $data['entry_history']['points_on_bench']; ?>
<?PHP echo $data['entry_history']['bank']; ?>

<button onclick="doCSV()">Export HTML Table To CSV File</button>

<?PHP
}
?>

I expect each button to convert the information of the particular gameweek which the loop is currently on (for e.g. i i=1 then gameweek 1 team should be exported, if i=2 then gameweek2 team should be exported)

Body:
You'll need to add unique ids to every table like:

<table id ="gameweek_history<? echo $i; ?>">

Then you'll need to have your javascript refer to the id. Your existing code creates a new script for every table, so to keep doing that, each function will need a unique name that has refers to that table.

<script>function doCSV<? echo $i; ?>() {
var table1 = document.getElementById("gameweek_history<? echo $i; ?>").innerHTML;

It would probably be better to just have one function declared outside the loop with a variable passed into it.

<script>function doCSV(table_number) {
var table1 = document.getElementById("gameweek_history" + table_number).innerHTML;

Then add the table number to each event handler.

<button onclick="doCSV(<? echo $i; ?>)">Export HTML Table To CSV File</button>


问:
get text area and text field data - jquery
I have 2 text areas in my page as;

```<code><input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>
</code>```

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

答:
dont use same id a1 for button and <input type="text" id="a1"/>

and you can use jquery val() function to get value

```<code>alert($('#a1').val());
alert($('#b2').val());
</code>```

Body:
I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
button

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

Body:
dont use same id a1 for <a id="button">button</a> and <input type="text" id="a1"/>

and you can use jquery val() function to get value

alert($('#a1').val());
alert($('#b2').val());


问:
Type mismatch in Geocoder Address
I am implementing a code in kotlin to show an address in google map. I have the address stored in Firebase. I am extracting the data and converting the address into a string and then trying to find the latitude and longitude from the same. Here is my code for getting the latitude and longitude:

```<code>   private fun getLocationFromAddress(context: Context, addkey: String?): LatLng? {

    val coder = Geocoder(context)
    val address: List<Address>
    var p1: LatLng? = null
    var strAddress = ""

    try {

        val user = FirebaseAuth.getInstance().currentUser
        val userid = user?.uid
        mRef = FirebaseDatabase.getInstance().reference.child("users").child(userid.toString()).child("users")

        mRef.child(addkey.toString()).addValueEventListener(object: ValueEventListener{
            override fun onCancelled(p0: DatabaseError) {
            }

            override fun onDataChange(p0: DataSnapshot) {
                strAddress = p0.child("****").child(addkey.toString()).child("***").getValue(String::class.java)

            }

        })
        address = coder.getFromLocationName(strAddress, 5)
        if (address == null) {
            return null
        }

        val location = address[0]
        p1 = LatLng(location.latitude, location.longitude)

    } catch (ex: IOException) {

        ex.printStackTrace()
    }

    return p1

}
</code>```

However, I am getting Type mismatch error at address = coder.getFromLocationName(strAddress, 5).

It says: "Type Mismatch.
          Required: List "My Project Name.com".Address
          Found: (Mutable)List android.location.Address!>!

答:
The reason for that error is likely to be a wrong import. The error message says it's expecting a list of xxx.com.Address objects (look at where you defined val address: List<Address>) while it found a list of android.location.Address (which is the type returned by the Geocoder API).

By changing the wrong import statement at the top of your file you should solve the issue. Or, even better, you could change your code so that you define the variable only where needed and let Kotlin's type inference do its "magic":

```<code>val address = coder.getFromLocationName(strAddress, 5)
</code>```

EDIT

In this specific case maybe you'd still may want to explicitly define the type because your Kotlin code is calling an API written in Java that doesn't use @Nullable/@NotNull (or similar annotations), so the compiler is not able to correctly infer nullity and the result type is a "platform type" (i.e., SomeType!). So if you know that something shouldn't be null you can force it to be non-null by explicitly typing your variable (or viceversa):

```<code>val address: List<Address> = coder.getFromLocationName(strAddress, 5)
</code>```

More info: Null-Safety and Platform Types.

Title: Type mismatch in Geocoder Address

Body:
I am implementing a code in kotlin to show an address in google map. I have the address stored in Firebase. I am extracting the data and converting the address into a string and then trying to find the latitude and longitude from the same. Here is my code for getting the latitude and longitude:

   private fun getLocationFromAddress(context: Context, addkey: String?): LatLng? {

    val coder = Geocoder(context)
    val address: List<Address>
    var p1: LatLng? = null
    var strAddress = ""

    try {

        val user = FirebaseAuth.getInstance().currentUser
        val userid = user?.uid
        mRef = FirebaseDatabase.getInstance().reference.child("users").child(userid.toString()).child("users")

        mRef.child(addkey.toString()).addValueEventListener(object: ValueEventListener{
            override fun onCancelled(p0: DatabaseError) {
            }

            override fun onDataChange(p0: DataSnapshot) {
                strAddress = p0.child("****").child(addkey.toString()).child("***").getValue(String::class.java)

            }

        })
        address = coder.getFromLocationName(strAddress, 5)
        if (address == null) {
            return null
        }

        val location = address[0]
        p1 = LatLng(location.latitude, location.longitude)

    } catch (ex: IOException) {

        ex.printStackTrace()
    }

    return p1

}

However, I am getting Type mismatch error at address = coder.getFromLocationName(strAddress, 5).

It says: "Type Mismatch.
          Required: List "My Project Name.com".Address
          Found: (Mutable)List android.location.Address!>!

Body:
The reason for that error is likely to be a wrong import. The error message says it's expecting a list of xxx.com.Address objects (look at where you defined val address: List<Address>) while it found a list of android.location.Address (which is the type returned by the Geocoder API).

By changing the wrong import statement at the top of your file you should solve the issue. Or, even better, you could change your code so that you define the variable only where needed and let Kotlin's type inference do its "magic":

val address = coder.getFromLocationName(strAddress, 5)

EDIT

In this specific case maybe you'd still may want to explicitly define the type because your Kotlin code is calling an API written in Java that doesn't use @Nullable/@NotNull (or similar annotations), so the compiler is not able to correctly infer nullity and the result type is a "platform type" (i.e., SomeType!). So if you know that something shouldn't be null you can force it to be non-null by explicitly typing your variable (or viceversa):

val address: List<Address> = coder.getFromLocationName(strAddress, 5)

More info: Null-Safety and Platform Types.