titi9000000 0 ارسال شده در ۲۹ خرداد ۱۳۹۶ گزارش اشتراک گذاری ارسال شده در ۲۹ خرداد ۱۳۹۶ سلام.دوستان.این برنامه نوشتم.چرا موقع اجرا ارور میده؟تو برنامه هیچ خطایی نمیده؟ android.app.ActivityThread.-wrap11(ActivityThread.java) android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) lkg من layout تعریف کردم. public class Form_Info implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private EditText inputName; private EditText inputPhone; private EditText inputEmail; private CheckBox cbSharePhone; private Button btnSubmit; private Activity activity; private LinearLayout layout_FormInfo; public Form_Info(Activity activity, int layoutId) { this.activity = activity; this. layout_FormInfo = (LinearLayout) activity.findViewById(layoutId); //inIt(); if (layout_FormInfo == null) { return; } } private void inIt() { inputName = (EditText) layout_FormInfo.findViewById(R.id.input_Name); inputEmail = (EditText) layout_FormInfo.findViewById(R.id.input_email); inputPhone = (EditText) layout_FormInfo.findViewById(R.id.input_phone); cbSharePhone = (CheckBox) layout_FormInfo.findViewById(R.id.Cb_Share_Phone); btnSubmit = (Button) layout_FormInfo.findViewById(R.id.btn_submit); btnSubmit.setOnClickListener(this); cbSharePhone.setOnCheckedChangeListener(this); } public EditText getInputName() { return inputName; } public EditText getInputPhone() { return inputPhone; } public EditText getInputEmail() { return inputEmail; } public CheckBox getCbSharePhone() { return cbSharePhone; } public Button getBtnSubmit() { return btnSubmit; } @Override public void onClick(View view) { if (view.getId() == btnSubmit.getId()) { String email = inputEmail.getText().toString().trim(); String phone = inputPhone.getText().toString().trim(); String name = inputName.getText().toString().trim(); if (isValidInput(name, phone, email)) { Intent intent =new Intent(activity,SecondActivity.class); if(cbSharePhone.isChecked()) { intent.putExtra("phone", phone); } intent.putExtra("name", name); intent.putExtra("email", email); activity.startActivity(intent); } } } @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (compoundButton.getId() == cbSharePhone.getId()) { inputPhone.setEnabled(isChecked); } } public boolean isValidInput(String name, String phone,String email) { if(name==null) name=inputName.getText().toString(); if(phone==null) phone=inputPhone.getText().toString(); if (email==null) email=inputEmail.getText().toString(); if (name.length() < 3) { Toast.makeText(activity, "name should be at least 3 characters", Toast.LENGTH_SHORT).show(); inputName.requestFocus(); return false; } if (! phone.isEmpty() &&(phone.length()!=11 || !phone .startsWith("09")) ){ Toast.makeText(activity, "wrong number", Toast.LENGTH_SHORT).show(); inputPhone.requestFocus(); return false; } if (!email.contains("@")||email.lastIndexOf('.')<email.lastIndexOf('@')){ Toast.makeText(activity, "wrong email address", Toast.LENGTH_SHORT).show(); inputPhone.requestFocus(); return false; } return true; } } public class MainActivity extends AppCompatActivity { public static final int REQ_Code=12; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Form_Info form=new Form_Info(this,R.id.layout_form_info); form.getBtnSubmit().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String name=form.getInputName().getText().toString().trim(); String email=form.getInputEmail().getText().toString().trim(); String phone=form.getInputPhone().getText().toString().trim(); if(form.isValidInput(name,email,phone)){ Intent intent=new Intent(MainActivity.this,SecondActivity.class); intent.putExtra("name",name); intent.putExtra("email",email); if(form.getCbSharePhone().isChecked()){ intent.putExtra("phone", phone); } startActivityForResult(intent,REQ_Code); } } }); } } نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
Farzad Sarseifi 575 ارسال شده در ۲۹ خرداد ۱۳۹۶ گزارش اشتراک گذاری ارسال شده در ۲۹ خرداد ۱۳۹۶ در ۱ ساعت قبل، titi9000000 گفته است : سلام.دوستان.این برنامه نوشتم.چرا موقع اجرا ارور میده؟تو برنامه هیچ خطایی نمیده؟ android.app.ActivityThread.-wrap11(ActivityThread.java) android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) lkg من layout تعریف کردم. public class Form_Info implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { private EditText inputName; private EditText inputPhone; private EditText inputEmail; private CheckBox cbSharePhone; private Button btnSubmit; private Activity activity; private LinearLayout layout_FormInfo; public Form_Info(Activity activity, int layoutId) { this.activity = activity; this. layout_FormInfo = (LinearLayout) activity.findViewById(layoutId); //inIt(); if (layout_FormInfo == null) { return; } } private void inIt() { inputName = (EditText) layout_FormInfo.findViewById(R.id.input_Name); inputEmail = (EditText) layout_FormInfo.findViewById(R.id.input_email); inputPhone = (EditText) layout_FormInfo.findViewById(R.id.input_phone); cbSharePhone = (CheckBox) layout_FormInfo.findViewById(R.id.Cb_Share_Phone); btnSubmit = (Button) layout_FormInfo.findViewById(R.id.btn_submit); btnSubmit.setOnClickListener(this); cbSharePhone.setOnCheckedChangeListener(this); } public EditText getInputName() { return inputName; } public EditText getInputPhone() { return inputPhone; } public EditText getInputEmail() { return inputEmail; } public CheckBox getCbSharePhone() { return cbSharePhone; } public Button getBtnSubmit() { return btnSubmit; } @Override public void onClick(View view) { if (view.getId() == btnSubmit.getId()) { String email = inputEmail.getText().toString().trim(); String phone = inputPhone.getText().toString().trim(); String name = inputName.getText().toString().trim(); if (isValidInput(name, phone, email)) { Intent intent =new Intent(activity,SecondActivity.class); if(cbSharePhone.isChecked()) { intent.putExtra("phone", phone); } intent.putExtra("name", name); intent.putExtra("email", email); activity.startActivity(intent); } } } @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (compoundButton.getId() == cbSharePhone.getId()) { inputPhone.setEnabled(isChecked); } } public boolean isValidInput(String name, String phone,String email) { if(name==null) name=inputName.getText().toString(); if(phone==null) phone=inputPhone.getText().toString(); if (email==null) email=inputEmail.getText().toString(); if (name.length() < 3) { Toast.makeText(activity, "name should be at least 3 characters", Toast.LENGTH_SHORT).show(); inputName.requestFocus(); return false; } if (! phone.isEmpty() &&(phone.length()!=11 || !phone .startsWith("09")) ){ Toast.makeText(activity, "wrong number", Toast.LENGTH_SHORT).show(); inputPhone.requestFocus(); return false; } if (!email.contains("@")||email.lastIndexOf('.')<email.lastIndexOf('@')){ Toast.makeText(activity, "wrong email address", Toast.LENGTH_SHORT).show(); inputPhone.requestFocus(); return false; } return true; } } public class MainActivity extends AppCompatActivity { public static final int REQ_Code=12; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Form_Info form=new Form_Info(this,R.id.layout_form_info); form.getBtnSubmit().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String name=form.getInputName().getText().toString().trim(); String email=form.getInputEmail().getText().toString().trim(); String phone=form.getInputPhone().getText().toString().trim(); if(form.isValidInput(name,email,phone)){ Intent intent=new Intent(MainActivity.this,SecondActivity.class); intent.putExtra("name",name); intent.putExtra("email",email); if(form.getCbSharePhone().isChecked()){ intent.putExtra("phone", phone); } startActivityForResult(intent,REQ_Code); } } }); } } لاگ خطا رو بزارید نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
titi9000000 0 ارسال شده در ۲۹ خرداد ۱۳۹۶ مالک گزارش اشتراک گذاری ارسال شده در ۲۹ خرداد ۱۳۹۶ 06-19 03:09:35.192 1819-1819/com.example.mostafa.myapplication E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.mostafa.myapplication, PID: 1819 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mostafa.myapplication/com.example.mostafa.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at com.example.mostafa.myapplication.MainActivity.onCreate(MainActivity.java:19) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
a.khosroabadi 100 ارسال شده در ۳۰ خرداد ۱۳۹۶ گزارش اشتراک گذاری ارسال شده در ۳۰ خرداد ۱۳۹۶ در 23 ساعت قبل، titi9000000 گفته است : 06-19 03:09:35.192 1819-1819/com.example.mostafa.myapplication E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.mostafa.myapplication, PID: 1819 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mostafa.myapplication/com.example.mostafa.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference at com.example.mostafa.myapplication.MainActivity.onCreate(MainActivity.java:19) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) سلام button که دارین براش onClick مینویسین null هستش نقل قول لینک ارسال به اشتراک گذاری در سایت های دیگر
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .