마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

답변 감사드립니다. 추가로 여쭤볼게 있어요.. [closed]

0 추천

말씀하신 링크 확인해서 대략적인 감은 알게됐습니다. 감사드리고요.

말씀 해 주신대로 작성을 했는데 다른 부분에서 에러가 발생해서 문의 드립니다.

 

수정 내역은 아래와 같구요.

 @Override
    protected void onCreate( Bundle savedInstanceState ) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Spinner spinner = (Spinner) findViewById(R.id.num6);
        // Create an ArrayAdapter using the string array and a default spinner layout
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.numb6, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);
    }

        public void onItemSelected(AdapterView<?> parent, View view,
        int pos, long id) {
            // An item was selected. You can retrieve the selected item using
            // parent.getItemAtPosition(pos)
        }

        public void onNothingSelected(AdapterView<?> parent) {
            // Another interface callback
        }

        private void calculate(String a3) {



        num1 = (EditText) findViewById(R.id.num1); // RPM
        num2 = (EditText) findViewById(R.id.num2); // 풀리경
        num3 = (EditText) findViewById(R.id.num3); // 축간거리
        num4 = (EditText) findViewById(R.id.num4); // 모터마력
        num5 = (EditText) findViewById(R.id.num5); // 큰풀리경
        Spinner num6=(Spinner) findViewById(R.id.num6); // 보정계수

        sum = (EditText) findViewById(R.id.sum); // 첫째칸 출력물
        sum1 = (EditText) findViewById(R.id.sum1); // 둘째칸 출력물
        sum2 = (EditText) findViewById(R.id.sum2); // 둘째칸 출력물
        pls = (Button) findViewById(R.id.pls);


        cl = new View.OnClickListener() {

            public void onClick( View v ) {
                a = Double.parseDouble(num1.getText().toString()); // 작은풀리 RPM
                b = Double.parseDouble(num2.getText().toString()); // 작은풀리경
                a1 = Double.parseDouble(num3.getText().toString()); // 축간 거리
                b1 = Double.parseDouble(num4.getText().toString()); // 모터 마력
                a2 = Double.parseDouble(num5.getText().toString()); // 큰 풀리경
                Spinner spinner = (Spinner) findViewById(R.id.num6);
                String a3 = spinner.getSelectedItem().toString();

                c = 3.1416 * a * b / 60000;
                d = (1000 * b1 * a3) / c;
                h = (180 - (60 * (a2 - b) / a1)) * 3.1416 / 180; // 접촉각 계산
                f1 = 0.512 * h;
                f = Math.pow(2.7183, f1);
                e = d * (f / (f - 1));
                g = (d / 2) * ((f + 1) / (f - 1)) * 1.5;
                i = 2 * a1 + 1.57 * (b + a2) + Math.pow(a2 - b, 2) / (4 * a1);

                sum1.setText(String.format("%.2f", d));
                sum.setText(String.format("%.2f", g));
                sum2.setText(String.format("%.2f", i));
            }
        };
            pls.setOnClickListener(cl);
        };

여기서 에러 메시지가 다음과 같습니다.
 
C:\Users\hyeon\AndroidStudioProjects\PTBeltDesign\app\src\main\java\com\example\ptbeltdesign\MainActivity.java:107: error: bad operand types for binary operator '*'
                d = (1000 * b1 * a3) / c;
                               ^
  first type:  double
  second type: String
부족한 지식으로, 1.4를 대체하고자 선정한 a3가 숫자 타입이 아니라 에러가 난다고 하는 것 같은데요,
그렇다고 
a3 = Double.parseDouble(num6.getText().toString()); 이렇게 넣으니 또 다른 에러가 발생합니다.
상기 에러에 대한 의견을 여쭙고자 합니다.
 
감사합니다.
질문을 종료한 이유: 게시물이 이상하게 올라가서 다시 올리겠습니다.
우라에누스 (290 포인트) 님이 2022년 3월 23일 질문
우라에누스님이 2022년 3월 23일 closed
...