我有一个例外,我读到了一条关于这个的帖子,它似乎令人困惑:如何修复android.os.networkOnMainThreadException?我已经在我的舱单上加上了这一行:<uses-permission android:name="android.permission.INTERNET" />在那次讨论中,他们谈到了应用程序的主要执行线程无法进行联网。我想知道的是如何重构我的代码,使其与Android良好实践相一致。以下是我的活动课:package com.problemio;import java.io.InputStream;import java.util.ArrayList;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.EditText;public class LoginActivity extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// Show form for login_email
final EditText loginEmail = (EditText) findViewById(R.id.login_email);
String name = loginEmail.getText().toString();
// Show field for password
final EditText password = (EditText) findViewById(R.id.password);
String text = password.getText().toString();
// Show button for submit
Button submit = (Button)findViewById(R.id.submit);
// Show options for create-profile and forgot-password
submit.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
String email = loginEmail.getText().toString();
String pass = password.getText().toString();
sendFeedback(pass, email);
}
});
}我在这里做错了什么,我怎样才能解决它?:)谢谢!android-android.os.networkOnMainThreadException
- 3 回答
- 0 关注
- 461 浏览
添加回答
举报
0/150
提交
取消