2017-07-04 78 views
-1

這是我使用AlertDialog的代碼,它說符號無法解析?如何解決這個錯誤?這是什麼選擇? 任何人都可以提出一個很好的和工作教程的MySQL PHP的Android? 在此先感謝!無法解析符號AlertDialog

public class BackgroundWorker extends AsyncTask<String,Void,String> { 
Context context; 
AlertDialog alertDialog; 
BackgroundWorker (Context ctx) { 
    context = ctx; 
} 
@Override 
protected String doInBackground(String... params) { 
    String type = params[0]; 
    String login_url = "http://192.168.1.6/login.php"; 
    if(type.equals("login")) { 
     try { 
      String user_name = params[1]; 
      String password = params[2]; 
      URL url = new URL(login_url); 
      HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection(); 
      httpURLConnection.setRequestMethod("POST"); 
      httpURLConnection.setDoOutput(true); 
      httpURLConnection.setDoInput(true); 
      OutputStream outputStream = httpURLConnection.getOutputStream(); 
      BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); 
      String post_data = URLEncoder.encode("user_name","UTF-8")+"="+URLEncoder.encode(user_name,"UTF-8")+"&" 
        +URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8"); 
      bufferedWriter.write(post_data); 
      bufferedWriter.flush(); 
      bufferedWriter.close(); 
      outputStream.close(); 
      InputStream inputStream = httpURLConnection.getInputStream(); 
      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1")); 
      String result=""; 
      String line=""; 
      while((line = bufferedReader.readLine())!= null) { 
       result += line; 
      } 
      bufferedReader.close(); 
      inputStream.close(); 
      httpURLConnection.disconnect(); 
      return result; 
     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
    return null; 
} 

@Override 
protected void onPreExecute() { 
    alertDialog = new AlertDialog.Builder(context).create(); 
    alertDialog.setTitle("Login Status"); 
} 

@Override 
protected void onPostExecute(String result) { 
    alertDialog.setMessage(result); 
    alertDialog.show(); 
} 

@Override 
protected void onProgressUpdate(Void... values) { 
    super.onProgressUpdate(values); 
} 

}

+0

普萊斯發表您的登錄錯誤輸出 –

+1

得到了答案。感謝名單。 –

回答

1

你必須導入此

import android.app.AlertDialog; 
1

進口該類AlertDialog

import android.app.AlertDialog;