11-10 13:32:47.398:E/AndroidRuntime(2155):致命异常:main 11-10 13:32:47.398:E/AndroidRuntime(2155):android。操作系统。NetworkOnMainThreadException 11-10 13:32:47.398:E/AndroidRuntime(2155):在android上。操作系统。StrictMode$AndroidBlockGuardPolicy。onNetwork(StrictMode.java:1117)11-10 13:32:47.398:E/AndroidRuntime(2155):在java。网InetAddress。lookupHostByName(InetAddress.java:385)11-10 13:32:47.398:E/AndroidRuntime(2155):在java。网InetAddress。getAllByNameImpl(InetAddress.java:236)11-10 13:32:47.398:E/AndroidRuntime(2155):在java。网InetAddress。getAllByName(InetAddress.java:214)
公共类UpdatingDatabase扩展AsyncTask时出错
package com.nikhil.svs;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Register extends MainActivity {
EditText reg,pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
reg=(EditText) findViewById(R.id.editusername);
pwd=(EditText) findViewById(R.id.editpassword);
Button register=(Button) findViewById(R.id.register);
register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new UpdatingDatabase().execute();
}
public class UpdatingDatabase extends AsyncTask<String, String, String>
{
protected String doInBackground(String... arg0) { //add this line
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://nikhilvaddepati.tk.hostinghood.com/test.php");
String a=reg.getText().toString();
String b=pwd.getText().toString();
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("regno", ""+a));
nameValuePairs.add(new BasicNameValuePair("pwd",""+b));
httppost.setEntity((HttpEntity) new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
public void execute() {
// TODO Auto-generated method stub
}
}// and this brackets
});
}
}
正如我在评论中所说的,您需要使用线程来获取网络,并确保不在UI线程上进行任何网络访问,而是在异步任务中进行
您必须将onClick按钮中的代码移动到AsynTask。。。
它应该如下所示。
编辑!
public void onClick(View v) {
new UpdatingDatabase().execute();
}
public class UpdatingDatabase extends AsyncTask<String, String, String>
{
protected String doInBackground(String... arg0) { //add this line
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://nikhilvaddepati.tk.hostinghood.com/test.php");
String a=reg.getText().toString();
String b=pwd.getText().toString();
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("regno", ""+a));
nameValuePairs.add(new BasicNameValuePair("pwd",""+b));
httppost.setEntity((HttpEntity) new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}// and this brackets
}
现在假设是这样,它将修复您的错误。如果有效,请通知我
编辑:
final EditText reg, pwd;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
reg=(EditText) findViewById(R.id.editusername);
pwd=(EditText) findViewById(R.id.editpassword);
...// complete with the code
编辑2:
package com.nikhil.svs;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
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.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Register extends MainActivity {
EditText reg,pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
reg=(EditText) findViewById(R.id.editusername);
pwd=(EditText) findViewById(R.id.editpassword);
Button register=(Button) findViewById(R.id.register);
register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new UpdatingDatabase().execute();
}
});
}
public class UpdatingDatabase extends AsyncTask<String, String, String>
{
protected String doInBackground(String... arg0) { //add this line
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://nikhilvaddepati.tk.hostinghood.com/test.php");
String a=reg.getText().toString();
String b=pwd.getText().toString();
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("regno", ""+a));
nameValuePairs.add(new BasicNameValuePair("pwd",""+b));
httppost.setEntity((HttpEntity) new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
}
错误:任务“:app:ProcessDebugResources”执行失败。 com.android.ide.common.Process.processException:org.gradle.Process.internal.exeception:Process“command”c:\users\mohamed sallam\appdata\local\android\sdk\build-to
我的控制台出现以下错误,请帮助我,在发布到应用商店有什么问题吗?(我为我的英语道歉&这是我第一个使用android studio的应用程序)更多信息
在我的项目中,我使用了带有okta验证的reactjs程序。当我运行reactjs程序时,输出变得很好。 但是,当我使用capacitorjs将reactjs网页转换为移动应用程序时,该网页不会显示在手机中 我已经按照以下url中的步骤将网页转换为移动应用程序 https://medium.com/how-to-react/convert-your-existing-react-js-app-to
无法使用“ADB反向”连接到开发服务器:spawnSync/home/sumit/android/platform-tools/ADB ENOENT 我还尝试使用$adb反向tcp:8081tcp:8081,但没有成功。
org.springframework.beans.factory.beanCreationException:创建名为“student controller”的bean时出错:注入autowired依赖项失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连接字段:public edu.java.spring.d
在设置好我的尤里卡服务器后。我转到我想要注册的服务,并在主类中添加了注释@EnableDiscoveryClient。之后,我转到application.properties并添加这个配置