2017-01-31 2 views
0

を行うとき、私はあなたがこのための解決策を見つけるcrashed.canそれは私のアプリケーションが取得しているに数字を入力した後、私のEditTextフィールドはnullを作るこのerror.While背後にある理由が何であるか混乱しています停止取得します状況 ??ここアプリケーションは、残念ながら私のEditTextフィールドがnull

は、私にはそれがようだが、一見私のコード

javaファイル

public class CSLActivity extends AppCompatActivity { 

    private Common mApp; 
    private AutoCompleteTextView clgName, conCent, loc; 
    private MultiAutoCompleteTextView skill; 
    private String[] qulify = new String[]{"Select Highest Qualification", "PG", "UG", "DIPLOMA"}; 
    public String abc, abcd; 
    public ScrollView scrollView; 
    public ProgressBar progressBar; 
    private String q; 
    private Spinner level; 
    private int ab = 1990; 
    public EditText fullName, frm_yr, to_yr; 
    private boolean ins = false; 
    private boolean cIns = false; 
    private Button next; 
    private TextfieldValidator textfieldValidator; 
    private AlphabetValidator alphabetValidator; 
    private int i = 0, j = 0; 
    private boolean exit = false; 
    private String get; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_csl); 

     scrollView = (ScrollView) findViewById(R.id.scroll_view); 
     progressBar = (ProgressBar) findViewById(R.id.progress_bar); 
     fullName = (EditText) findViewById(R.id.fullName); 
     level = (Spinner) findViewById(R.id.level); 
     clgName = (AutoCompleteTextView) findViewById(R.id.clg_name); 
     conCent = (AutoCompleteTextView) findViewById(R.id.concent); 
     frm_yr = (EditText) findViewById(R.id.frm_yr); 
     to_yr = (EditText) findViewById(R.id.to_yr); 
     skill = (MultiAutoCompleteTextView) findViewById(R.id.skill); 
     loc = (AutoCompleteTextView) findViewById(R.id.location); 
     textfieldValidator = new TextfieldValidator(); 
     alphabetValidator = new AlphabetValidator(); 
     next = (Button) findViewById(R.id.next); 

     frm_yr.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       //abc = frm_yr.getText().toString(); 

      } 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       //i = Integer.parseInt(frm_yr.getText().toString()); 
       //i = Integer.parseInt(abc.toString()); 
       i = Integer.parseInt(frm_yr.getText().toString()); 

      } 
     }); 


     to_yr.addTextChangedListener(new TextWatcher() { 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void afterTextChanged(Editable s) { 
       //j = Integer.parseInt(to_yr.getText().toString()); 
       //j = Integer.parseInt(abcd.toString()); 
       j = Integer.parseInt(to_yr.getText().toString()); 
      } 
     }); 


     new GetCollege(CSLActivity.this, progressBar, scrollView, clgName).execute(); 
     new GetCourse(CSLActivity.this, conCent).execute(); 
     new GetSkillSet(CSLActivity.this, scrollView, progressBar, skill).execute(); 
     new GetLocation(CSLActivity.this, scrollView, loc, progressBar).execute(); 


     ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_item, qulify); 
     level.setAdapter(adapter1); 
     level.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
       get = level.getSelectedItem().toString(); 
       if (get.equalsIgnoreCase("PG")) { 
        q = "1"; 
       } else if (get.equalsIgnoreCase("UG")) { 
        q = "2"; 
       } else { 
        q = "3"; 
       } 
      } 

      @Override 
      public void onNothingSelected(AdapterView<?> parent) { 

      } 
     }); 


     clgName.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       TextView txt = (TextView) view.findViewById(R.id.ins_name); 
       clgName.setText(txt.getText().toString()); 
       conCent.requestFocus(); 
       ins = true; 

      } 
     }); 

     conCent.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       TextView txt = (TextView) view.findViewById(R.id.display); 
       conCent.setText(txt.getText().toString()); 
       cIns = true; 
       frm_yr.requestFocus(); 
      } 
     }); 

     loc.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       TextView txt1 = (TextView) view.findViewById(R.id.ins_name); 
       loc.setText(txt1.getText().toString()); 
       InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       imm.hideSoftInputFromInputMethod(view.getWindowToken(), 0); 
      } 
     }); 

     next.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       switch (v.getId()) { 
        case R.id.next: 

         if (fullName.getText().toString().length() == 0) { 
          fullName.setError("Field Mandatory"); 
          fullName.requestFocus(); 
         } else if (!alphabetValidator.validate(fullName.getText().toString())) { 
          fullName.setError("Enter a Valid Name"); 
          fullName.requestFocus(); 
         } else if (get.equalsIgnoreCase("Select Highest Qualification")) { 
          level.requestFocus(); 
          Toast.makeText(getApplicationContext(), "select Qualification", Toast.LENGTH_SHORT).show(); 
         } else if (clgName.getText().toString().length() == 0) { 
          clgName.setError("Field Mandatory"); 
          clgName.requestFocus(); 
         } else if (conCent.getText().toString().length() == 0) { 
          conCent.setError("Field Mandatory"); 
          conCent.requestFocus(); 
         } else if (frm_yr.getText().toString().length() == 0) { 
          frm_yr.setError("Field Mandatory"); 
          frm_yr.requestFocus(); 
         } else if (to_yr.getText().toString().length() == 0) { 
          to_yr.setError("Field Mandatory"); 
          to_yr.requestFocus(); 
         } else if (i > j) { 
          to_yr.setError("Passed out year less than join year"); 
          to_yr.requestFocus(); 
         } else if (i == j) { 
          to_yr.setError("Check the year entered"); 
          to_yr.requestFocus(); 
         } else if (i <= ab) { 
          frm_yr.setError("Enter a valid Year"); 
          frm_yr.requestFocus(); 
         } else if (j <= ab) { 
          to_yr.setError("Enter a valid Year"); 
          to_yr.requestFocus(); 
         } else if (skill.getText().toString().length() == 0) { 
          skill.setError("Field Mandatory"); 
          skill.requestFocus(); 
         } else if (!textfieldValidator.validate(skill.getText().toString())) { 
          skill.setError("Enter a Valid Skill"); 
          skill.requestFocus(); 
         } else if (loc.getText().toString().length() == 0) { 
          loc.setError("Field Mandatory"); 
          loc.requestFocus(); 
         } else if (!textfieldValidator.validate(loc.getText().toString())) { 
          loc.setError("Enter a Valid Location"); 
         } else { 
          next.setEnabled(false); 
          new CslIns(CSLActivity.this, mApp.getPreference().getString(Common.u_id, ""), fullName.getText().toString(), q, 
            clgName.getText().toString(), conCent.getText().toString(), frm_yr.getText().toString(), to_yr.getText().toString(), 
            skill.getText().toString(), loc.getText().toString(), ins, cIns).execute(); 
            /*startActivity(new Intent(getApplicationContext(), MailVerify.class)); 
          finish();*/ 
         } 
         break; 
       } 
      } 
     }); 
    } 

    @Override 
    public void onBackPressed() { 
     if (exit) { 
      mApp.getPreference().edit().putBoolean(Common.PAGE1, false).commit(); 
      super.onBackPressed(); 
      return; 
     } else { 
      Toast.makeText(this, "Press Back again to Cancel Signup Process.", Toast.LENGTH_SHORT).show(); 
      exit = true; 
      new Handler().postDelayed(new Runnable() { 
       @Override 
       public void run() { 
        exit = false; 
       } 
      }, 2000); 
     } 
    } 
} 

私の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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.shuan.Project.signup.employee.CSLActivity"> 

    <ProgressBar 
     android:id="@+id/progress_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 

    <ScrollView 
     android:id="@+id/scroll_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="visible"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/activity_horizontal_margin" 
      android:orientation="vertical"> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <EditText 
        android:id="@+id/fullName" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="@dimen/standard_margin" 
        android:hint="Full Name" 
        android:imeOptions="actionNext" 
        android:inputType="textPersonName" /> 

      </android.support.design.widget.TextInputLayout> 

      <Spinner 
       android:id="@+id/level" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/standard_margin" /> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/standard_margin"> 

       <AutoCompleteTextView 
        android:id="@+id/clg_name" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/clg_name" 
        android:imeOptions="actionNext" /> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/standard_margin"> 

       <AutoCompleteTextView 
        android:id="@+id/concent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/concent" 
        android:imeOptions="actionNext" 
        android:singleLine="true" /> 
      </android.support.design.widget.TextInputLayout> 

      <LinearLayout 
       android:id="@+id/yr" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/standard_margin" 
       android:orientation="horizontal"> 

       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Joined" 
         android:textColor="#000" 
         android:textStyle="bold" /> 

        <EditText 
         android:id="@+id/frm_yr" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/small_margin" 
         android:hint="Year" 
         android:imeOptions="actionNext" 
         android:inputType="numberDecimal" 
         android:maxLength="4" 
         android:singleLine="true" /> 

       </LinearLayout> 

       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="horizontal"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Passed :" 
         android:textColor="#000" 
         android:textStyle="bold" /> 

        <EditText 
         android:id="@+id/to_yr" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="@dimen/small_margin" 
         android:hint="Year" 
         android:imeOptions="actionNext" 
         android:inputType="numberDecimal" 
         android:maxLength="4" 
         android:singleLine="true" /> 

       </LinearLayout> 

      </LinearLayout> 

      <android.support.design.widget.TextInputLayout 
       android:id="@+id/layout_skill" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/standard_margin"> 

       <MultiAutoCompleteTextView 
        android:id="@+id/skill" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="Enter Your Skills" 
        android:imeOptions="actionNext" 
        android:inputType="text" /> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:id="@+id/layout_location" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/standard_margin"> 

       <AutoCompleteTextView 
        android:id="@+id/location" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/location" 
        android:imeOptions="actionDone" 
        android:inputType="textAutoComplete" /> 
      </android.support.design.widget.TextInputLayout> 

      <Button 
       android:id="@+id/next" 
       android:layout_width="150dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:layout_marginTop="@dimen/activity_horizontal_margin" 
       android:background="@drawable/signin_border" 
       android:text="START" 
       android:textAppearance="?android:textAppearanceMedium" 
       android:textColor="#fff" 
       android:textStyle="bold" /> 

     </LinearLayout> 


    </ScrollView> 

</RelativeLayout> 

ログ猫

FATAL EXCEPTION: main 
                  Process: com.shuan.Project, PID: 1432 
                  java.lang.NumberFormatException: Invalid int: "" 
                   at java.lang.Integer.invalidInt(Integer.java:138) 
                   at java.lang.Integer.parseInt(Integer.java:358) 
                   at java.lang.Integer.parseInt(Integer.java:334) 
                   at com.shuan.Project.signup.employee.CSLActivity$1.afterTextChanged(CSLActivity.java:95) 
                   at android.widget.TextView.sendAfterTextChanged(TextView.java:7998) 
                   at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:9814) 
                   at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:990) 
                   at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:529) 
                   at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:224) 
                   at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:38) 
                   at android.view.inputmethod.BaseInputConnection.deleteSurroundingText(BaseInputConnection.java:252) 
                   at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:389) 
                   at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78) 
                   at android.os.Handler.dispatchMessage(Handler.java:111) 
                   at android.os.Looper.loop(Looper.java:194) 
                   at android.app.ActivityThread.main(ActivityThread.java:5649) 
                   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:959) 
                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
+0

についてlogcatを投稿してください! –

+0

正確にどこがクラッシュするのか教えてください。 –

+0

NULLを作成している間にクラッシュし、各フィールドに1つの文字を入力した後、フィールドが年を繋ぎ、1年後に渡されました –

答えて

0

このコードを試してみては

public void afterTextChanged(Editable s) { 
      if(to_yr.getText().toString().length != 0){ 
      j =Integer.parseInt(to_yr.getText().toString()); 
     } 
    } 

それは私のため正常に動作

+0

それはうまく動作します:-) –

0

ですonAfterTextChangedをブロックすると、 eは、空のStringからintを解析しようとしているので、エラーを投げるだけです。 整数を解析する前にEditTextが ""かどうかを確認してください。それが ""でなければ、あなたのコードにnullがあり、nullであれば、0などのデフォルト値を与えます。

0

このクラッシュは、afterTextChangedコールバックのコードが原因です。 to_yr.getTextに整数値を解析する前に、有効な値があるかどうかを確認する必要があります。空文字列は解析しないでください。コードの下

用途:

public void afterTextChanged(Editable s) { 
    if(!TextUtils.isEmpty(to_yr.getText()){ 
     j = Integer.parseInt(to_yr.getText().toString()); 
    } 
} 
0

これが起こっているあなたは、空の文字列を解析し、整数クラスがスローされますので、例外名:

無効int型

java.lang.NumberFormatException

整数を解析する前にチェックを行います。例

String s; 

if(s != null && (!s.isEmpty())){ 
    Integer i = s.ParseInt(); 
} 
関連する問題