gpt4 book ai didi

java - 线程ID=1 : thread exiting with uncaught exception (group=0x41cd1700)

转载 作者:行者123 更新时间:2023-12-02 06:11:03 24 4
gpt4 key购买 nike

我试图在单击按钮时运行线程,但它强制关闭,

这是代码,

package kulkarni.darpan.vtc;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

Button btnRegister;
EditText emailRegister;
CheckBox enDisTracking;
Handler hand;
GPSTracker gps;
AsyncPostRequest asp;
AsyncRegisterDevice ard;
DeviceInfo di;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

gps = new GPSTracker(MainActivity.this);
di = new DeviceInfo(MainActivity.this);
asp = new AsyncPostRequest();
ard = new AsyncRegisterDevice();

btnRegister = (Button) findViewById(R.id.regButton);
emailRegister = (EditText)findViewById(R.id.regEmail);
enDisTracking = (CheckBox)findViewById(R.id.startTracking);
btnRegister.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
//registerDevice();
hand.postDelayed(run, 1000);
}
});
}

Runnable run = new Runnable() {

public void run()
{
sendLocation();
}

};

public void registerDevice(){

String regEmail = emailRegister.getText().toString();
String regUniqueID = di.getDeviceInfo();
String regObj[] = new String[2];
regObj[0] = regEmail;
regObj[1] = regUniqueID;
ard.execute(regObj);
}

public void sendLocation(){

if(gps.canGetLocation()){

double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
String uniq = di.getDeviceInfo();
String aobj[] = new String[3];
aobj[0]=Double.toString(latitude);
aobj[1]=Double.toString(longitude);
aobj[2]=uniq;
asp.execute(aobj);

Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude +"\nIMEI: "+uniq, Toast.LENGTH_LONG).show();

}else{
gps.showSettingsAlert();
}
hand.postDelayed(run, 20000);
}
}

这是日志文件,

02-19 17:57:29.115: D/Network(29198): Network
02-19 17:57:29.275: D/libEGL(29198): loaded /system/lib/egl/libEGL_mali.so
02-19 17:57:29.305: D/libEGL(29198): loaded /system/lib/egl/libGLESv1_CM_mali.so
02-19 17:57:29.310: D/libEGL(29198): loaded /system/lib/egl/libGLESv2_mali.so
02-19 17:57:29.315: E/(29198): Device driver API match
02-19 17:57:29.315: E/(29198): Device driver API version: 23
02-19 17:57:29.315: E/(29198): User space API version: 23
02-19 17:57:29.315: E/(29198): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Wed Oct 9 21:05:57 KST 2013
02-19 17:57:29.425: D/OpenGLRenderer(29198): Enabling debug mode 0
02-19 17:57:38.575: D/AndroidRuntime(29198): Shutting down VM
02-19 17:57:38.575: W/dalvikvm(29198): threadid=1: thread exiting with uncaught exception (group=0x41cd1700)
02-19 17:57:38.580: E/AndroidRuntime(29198): FATAL EXCEPTION: main
02-19 17:57:38.580: E/AndroidRuntime(29198): java.lang.NullPointerException
02-19 17:57:38.580: E/AndroidRuntime(29198): at kulkarni.darpan.vtc.MainActivity$2.onClick(MainActivity.java:41)
02-19 17:57:38.580: E/AndroidRuntime(29198): at android.view.View.performClick(View.java:4475)
02-19 17:57:38.580: E/AndroidRuntime(29198): at android.view.View$PerformClick.run(View.java:18786)
02-19 17:57:38.580: E/AndroidRuntime(29198): at android.os.Handler.handleCallback(Handler.java:730)
02-19 17:57:38.580: E/AndroidRuntime(29198): at android.os.Handler.dispatchMessage(Handler.java:92)
02-19 17:57:38.580: E/AndroidRuntime(29198): at android.os.Looper.loop(Looper.java:176)
02-19 17:57:38.580: E/AndroidRuntime(29198): at android.app.ActivityThread.main(ActivityThread.java:5419)
02-19 17:57:38.580: E/AndroidRuntime(29198): at java.lang.reflect.Method.invokeNative(Native Method)
02-19 17:57:38.580: E/AndroidRuntime(29198): at java.lang.reflect.Method.invoke(Method.java:525)
02-19 17:57:38.580: E/AndroidRuntime(29198): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-19 17:57:38.580: E/AndroidRuntime(29198): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-19 17:57:38.580: E/AndroidRuntime(29198): at dalvik.system.NativeStart.main(Native Method)

这个问题有什么解决办法吗?

最佳答案

您尚未初始化Handler hand。你只需声明它。确保在使用处理程序之前对其进行初始化。

hand = new Handler();

看看@

http://developer.android.com/reference/android/os/Handler.html

关于java - 线程ID=1 : thread exiting with uncaught exception (group=0x41cd1700),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21880577/

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