2016-10-06 4 views
1

私は、edittextに入力されたメールアドレスがユニークであるかどうかを確認するためにmysqlデータを格納するmailaddressをフェッチするアンドロイドアプリケーションを作成しています。私のJSONコードはjsonデータがURLからフェッチされていない

{"result":[{"mailId":"[email protected]"}]} 

私のアンドロイドコードがあるさ:

EditText et1,et2,et3,et4,et5; 
    Button bu1; 
    String mailCheck; 
    String mail; 
    // TextView alert; 
    String name,password,mailId,repass,number; 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     new AsyncTaskParse().execute(); 



     Toast.makeText(MainActivity.this,mailCheck,Toast.LENGTH_SHORT).show(); 
     et1=(EditText)findViewById(R.id.et1); 
     et2=(EditText)findViewById(R.id.et2); 
     et3=(EditText)findViewById(R.id.et3); 
     et4=(EditText)findViewById(R.id.et4); 
     et5=(EditText)findViewById(R.id.et5); 
     name=et1.getText().toString(); 
     password=et2.getText().toString(); 
     /// alert=(TextView)findViewById(R.id.alert);4 
     repass=et4.getText().toString(); 


      mailId=et3.getText().toString(); 
      number=et5.getText().toString(); 




     bu1=(Button)findViewById(R.id.bu1); 


     bu1.setOnClickListener(new View.OnClickListener() { 




      public void onClick(View v) { 
       String t = et1.getText().toString(); 
       String t5 = et5.getText().toString(); 
       String one = et2.getText().toString(); 
       String two = et4.getText().toString(); 
       mail = et3.getText().toString(); 




if(one.equals(two)){ 

        if (one.equals(two) && isEmailValid(mail,et3)) { 


          isInternetOn(); 



        } 
} else { 
         et4.setError(Html.fromHtml("<font color='#000'>Password not Match!</font>")); 
         focus(et4); 
        } 
       } 
      } 
     }); 

    } 








//////////////////////// 


    public class AsyncTaskParse extends AsyncTask<String, String, String> { 

     final String TAG = "AsyncTaskParseJson.java"; 

     // set your json string url here 

     String yourJsonStringUrl = "http://www.example.com/checkMail.php?mailId="+mailId; 

     // contacts JSONArray 
     JSONArray dataJsonArr = null; 
     @Override 
     protected void onPreExecute() {} 


     protected String doInBackground(String... arg0) { 

      try { 
       JSONParser jParser = new JSONParser(); 

       // get json string from url 

       JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl); 


       if(json!=null) { 
        // get the array of users 
        dataJsonArr = json.getJSONArray("result"); 
        JSONObject c = dataJsonArr.getJSONObject(0); 
        // na=c.getString("avg"); 

        mailCheck = c.getString("mailId"); 

       } 

      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 


      return null; 
     } 

    } 
+0

AsyncTaskParse().execute();を維持する必要があり

mail = et3.getText().toString();AsyncTaskParse().execute();あなたの新しいを入れて、あなたは、インターネットのアクセス許可を定義していますあなたのマニフェストファイルにありますか? – Anjali

+0

urlからjsonをロードしている場合は、jsonを次のリンクからチェックしてください。http://jsonviewer.stack.hu/ – Anjali

+0

@anjali私のマニフェストファイルにインターネットアクセス権を定義していますか? –

答えて

0

たぶん、あなたはあなたのonClick

+0

それはうまくいきません –

関連する問題