在类型转换时需要.class

时间:2017-03-21 11:37:52

标签: java casting

我收到错误,

  • “错误:'。class'预期”
  • “错误:不是声明”
  • “错误:';'预期“

尝试在以下代码中将double类型转换为int。

double area = 4.33333;
int areaM = int(area);

错误全部发生在第二行。我环顾四周,找不到我错的地方。任何帮助将不胜感激

3 个答案:

答案 0 :(得分:3)

你需要像这样进行类型转换。

// We pass through session ID's, request dates etc through in body
app.post("/getPayslipURL", function(client_request, res) {

    // create request, which will simply pass on the data to the database (In order to get the NI number we need for the pay API)
    const NI_NUMBER_REQUEST = db_api.createRequestTemplate({
        body: JSON.stringify(client_request.body)
    });

    // Create a chain of HTTPS Requests, Starting with our call to the DB
    requestPromise(NI_NUMBER_REQUEST)
        .then((db_response) => {   
            const PAY_API_OPTIONS = /*Code to generate options based on furhter DB info (Includes dates etc)*/
            return requestPromise(PAY_API_OPTIONS); // Call pay API
        })
        .then((pay_pdf_data) => { 

            console.log(typeof pay_pdf_data); // It's a string
            // At this point I can log pay_pdf_data, But if I try to save it to file it's always empty
            // No matter how I encode it etc

            fs.writeFile("./test.pdf", pay_pdf_data, 'binary', function(err) {
                if(err) {
                    return console.log(err);
                }
                console.log("The file was saved!");
            }); 

        })
        .catch(err => `Error caught: ${console.log}`) // Catch any errors on our request chain
    });
}

答案 1 :(得分:2)

试试这个;

public class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            if (url.equals(""YOUR URL)) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            } else {
                return false;
            }

        }

    }

答案 2 :(得分:1)

这样:

int areaM = ((Number)area).intValue();