私はアンドロイドを初めて使用しています。新しいアクティビティを開くためにファブボタンをクリックするとアプリケーションがクラッシュする開発とアプリケーションです。ボタンはうまくいきますが、コードの最初の3行がアプリケーションとしてクラッシュします。私は、誰もが、検証の他の方法を知っていれば助けてくださいTextInputlayout宣言のためアプリケーションクラッシュが発生する
final TextInputLayout name12=(TextInputLayout)findViewById(R.id.NameWrapper);
final TextInputLayout payment12=(TextInputLayout)findViewById(R.id.PaymentWrapper);
final TextInputLayout leave12=(TextInputLayout)findViewById(R.id.LeaveWrapper);
final EditText Name1 = (EditText) findViewById(R.id.editText2);
final EditText PhoneNo = (EditText) findViewById(R.id.editText3);
final EditText JobDesc = (EditText) findViewById(R.id.editText4);
final EditText Payment = (EditText) findViewById(R.id.editText5);
final EditText Leave = (EditText) findViewById(R.id.editText6);
final EditText Adharno = (EditText) findViewById(R.id.editText7);
final TextView Start = (TextView) findViewById(R.id.textView);
final TextView End = (TextView) findViewById(R.id.textView2);
final RadioButton Daily = (RadioButton) findViewById(R.id.Rb1);
final RadioButton Monthly = (RadioButton) findViewById(R.id.Rb2);
final Button AddEmp=(Button)findViewById(R.id.b1);
final Button Cancel=(Button)findViewById(R.id.b2);
final RadioGroup myRadiogeoup=(RadioGroup)findViewById(Rbg);
//Add Employee Btn
AddEmp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
String name1=Name1.getText().toString();
String phone1=PhoneNo.getText().toString();
String jobdesc=JobDesc.getText().toString();
String payment=Payment.getText().toString();
String leave=Leave.getText().toString();
String ahdarno=Adharno.getText().toString();
int id=myRadiogeoup.getCheckedRadioButtonId();
final RadioButton mySelectedRadioButton=(RadioButton)findViewById(id);
String paymethod=mySelectedRadioButton.getText().toString();
String startd=Start.getText().toString();
String end=End.getText().toString();
//validation and data insertion
if (name12.getEditText().length() == 0) {
name12.setError("Enter Name");
name12.setErrorEnabled(true);
}
else{
name12.setErrorEnabled(false);
}
if (leave12.getEditText().length() == 0) {
leave12.setError("Enter date");
leave12.setErrorEnabled(true);
}
else
{
leave12.setErrorEnabled(false);
}
if (payment12.getEditText().length() == 0) {
payment12.setError("Enter Password");
payment12.setErrorEnabled(true);
}
else{
payment12.setErrorEnabled(false);
}
if(Start.getText().length()==0)
{
Toast.makeText(getApplicationContext(),"Enter Start Date",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(),"Data Entered",Toast.LENGTH_SHORT).show();
}
}
});
...私はTextInputLayoutためSETERRORを使用しますが、アプリケーションがクラッシュTextInputLayoutの宣言のためにフォームを検証したいです。 私の間違ったコードのためか、申し訳ありませんが私は
--logcat
24 12:11:06.725 20230-20230/com.navinkadlak.typroject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.navinkadlak.typroject, PID: 20230
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.navinkadlak.typroject/com.navinkadlak.typroject.addemployee}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.design.widget.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2555)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2629)
at android.app.ActivityThread.access$800(ActivityThread.java:182)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5706)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1033)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.support.design.widget.TextInputLayout
at com.navinkadlak.typroject.addemployee.onCreate(addemployee.java:33)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2502)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2629)
at android.app.ActivityThread.access$800(ActivityThread.java:182)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5706)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1033)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
クラッシュログを投稿できますか? –