Написал простенькое приложение вычисляющее функцию в зависимости от введенного значения(т.н. кусочно-заданная функция).
Проблема в том, что при компиляции и запуске на устройстве(планшет под управлением android 4.4, проект соответсвенно тоже создан под андроид 4.4) вылазит описанная ошибка со ссылкой на xml в котором описана форма приложения. Приложение переписывал с нуля, пересоздавал проект с копипастой содержимого, очищал и перестраивал, не помогает.
код прилагается: xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.lab02a2andr_.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:weightSum="1">
<TextView
android:text="введите Х:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:layout_weight="0.03" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="0.0"
android:ems="10"
android:id="@+id/editText" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:text="sin(x^2-3) x<=-1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton1" />
<RadioButton
android:text="(x+4)*x^2-3 -1<x<1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radioButton3" />
<RadioButton
android:text="cos(sqrt(x)) x>=1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2" />
</RadioGroup>
<CheckBox
android:text="Удвоить"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/checkBox"
android:layout_weight="0.03" />
<Button
android:text="Посчитать"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_weight="0.03" />
<TextView
android:text="Ответ:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.03"
android:id="@+id/textView2" />
</LinearLayout>
mainActivity:
package com.example.lab02a2andr_;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private CheckBox cb;
private TextView tv2;
private RadioButton rb1,rb2,rb3;
private EditText et1;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb=(CheckBox) findViewById(R.id.checkBox);
tv2=(TextView) findViewById(R.id.textView2);
rb1=(RadioButton) findViewById(R.id.radioButton1);
rb2=(RadioButton) findViewById(R.id.radioButton2);
rb3=(RadioButton) findViewById(R.id.radioButton3);
et1=(EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
et1.setOnFocusChangeListener(new View.OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus){
if(!hasFocus){
Calculate();
}
}
});
rb1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Calculate();
}
});
rb2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Calculate();
}
});
rb3.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Calculate();
}
});
cb.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Calculate();
}
});
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Calculate();
}
});
}
public void Calculate(){
String s1;
double x,y=0;
int var;
s1=et1.getText().toString();
x=Double.parseDouble(s1);
if(rb1.isChecked()==true){
var=1;
}else if(rb2.isChecked()==true){
var=2;
}else if(rb3.isChecked()==true){
var=3;
}else{
if(x<=-1) {
var = 1;
rb1.setChecked(true);
}else if(x>=1){
var=3;
rb3.setChecked(true);
}else{
var=2;
rb2.setChecked(true);
}
}
switch (var){
case 1:
y=Math.sin(x*x-3);
break;
case 2:
y=(x+4)*x*x-3;
break;
case 3:
y=Math.cos(Math.sqrt(x));
break;
}
if(cb.isChecked()==true){
y*=2;
}
s1="Ответ: "+Double.toString(y);
}
}