0
Android 앱을 사용하여 만든 웹 사이트의 콘텐츠를 가져 오려고합니다. 번역기 앱은 URL 변수를 기반으로 문자열을 반환합니다.Android Java : URL에서 콘텐츠 가져 오기
그러나 URL을 가져올 때마다 기대되는 번역 된 문자열 대신 [email protected]이 변형됩니다. .
어디로 잘못 가고 있습니까?
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText et = (EditText) findViewById(R.id.editText1);
final EditText et2 = (EditText) findViewById(R.id.editText2);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Toast.makeText(getBaseContext(), "click", Toast.LENGTH_LONG).show();
String english = et.getText().toString();
String revian = et2.getText().toString();
if (!english.isEmpty() && revian.isEmpty()) {
String[] words = english.split(" ");
for (int i = 0; i < words.length; i++) {
try {
revian = revian + queryDB(words[i], false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
et2.setText(revian);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public String queryDB(String word, boolean revian) throws IOException {
String variab = "le";
if (revian) {
variab = "lr";
}
String fullurl = "http://maereti.com/p/Revian/revian.php?"+variab+"="+word;
RetrieveFeedTask RTF = new RetrieveFeedTask();
AsyncTask<String, String, String> out = RTF.execute(fullurl);
String output = out.toString();
return output;
}
public void ToastThis(String words) {
Toast.makeText(getBaseContext(), "toast function "+words, Toast.LENGTH_LONG).show();
}
}
그리고 RetrieveFeedTask 클래스 :
public class RetrieveFeedTask extends AsyncTask<String, String, String> {
URL url;
@Override
protected String doInBackground(String... urls) {
String outputLine = "";
Looper.prepare();
MainActivity MA = new MainActivity();
try {
URL url = new URL(urls[0]);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
outputLine = outputLine + inputLine;
}
MA.ToastThis(outputLine);
in.close();
return outputLine;
} catch (Exception e) {
e.printStackTrace();
return "!! I am error !!";
}
}
protected void onPostExecute(String feed) {
// TODO: check this.exception
// TODO: do something with the feed
}
}
에
을 변경해보십시오. 정말 고맙습니다! – AtlasOnEarth