gpt4 book ai didi

java - 致命异常 : main , MainActivity.java

转载 作者:行者123 更新时间:2023-12-01 10:33:09 24 4
gpt4 key购买 nike

大家好,我正在开发一个简单的 Android 应用程序,当我向类添加一些参数并在移动设备上运行该应用程序时,问题如下所示。这是主类;

    package com.example.webserviceapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
EditText name,email,pass;
Button log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.name);
email=(EditText)findViewById(R.id.email);
pass=(EditText)findViewById(R.id.pass);
log = (Button)findViewById(R.id.btn);
log.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nm = name.getText().toString();
String em = email.getText().toString();
String pas = pass.getText().toString();
new Logindata().getdata(nm,em,pas);
}
});

}
}

这是输出

01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: FATAL EXCEPTION: main
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: Process: com.example.webserviceapp, PID: 16396
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: android.os.NetworkOnMainThreadException
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:110)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at libcore.io.IoBridge.connect(IoBridge.java:122)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at java.net.Socket.connect(Socket.java:882)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at com.example.webserviceapp.Loginparser.loginparse(Loginparser.java:26)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at com.example.webserviceapp.Logindata.getdata(Logindata.java:21)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at com.example.webserviceapp.MainActivity$1.onClick(MainActivity.java:26)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.view.View.performClick(View.java:4756)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19761)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5253)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
01-23 20:41:37.928 16396-16396/com.example.webserviceapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

无论如何,感谢您的帮助

最佳答案

您正在主应用程序线程上进行互联网 Activity 。在另一个线程上执行此操作。使用AsyncTask。

关于java - 致命异常 : main , MainActivity.java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34967734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com