我正在创建一个应用程序来向人们发送X数量的文本,在重新编写我的代码以包含线程之后,它就破了。还有," Thread.sleep(3000);"部分代码冻结了UI,或者我的所有代码都在线程中解决了这个问题?最后一个问题,我如何防止脚本在后台停止(继续发送)
public abstract class multisender2 extends Activity implements Runnable {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void csend(View view) {
EditText number = (EditText)findViewById(R.id.pnumber);
EditText message = (EditText)findViewById(R.id.pmessage);
EditText hmany = (EditText)findViewById(R.id.hmany);
String _hmany = hmany.getText().toString();
final String _number = number.getText().toString();
final String _message = message.getText().toString();
final int xtime = Integer.parseInt(_hmany);
final int count = 1;
Thread background = new Thread(new Runnable() {
@Override
public void run() {
try {
if (count > xtime == false){
SmsManager.getDefault().sendTextMessage(_number, null, _message, null, null);
Thread.sleep(3000);
}
} catch (InterruptedException e) {
}
}
});
background.start();
}
}
谢谢,这是LogCat
07-12 21:04:40.222:E / AndroidRuntime(13948):致命异常:主要 07-12 21:04:40.222:E / AndroidRuntime(13948):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.dillonregi.multisender / com.dillonregi.multisender.multisender2}:java.lang.InstantiationException:com .dillonregi.multisender.multisender2 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1580) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:942) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.os.Handler.dispatchMessage(Handler.java:99) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.os.Looper.loop(Looper.java:130) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.main(ActivityThread.java:3701) 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.reflect.Method.invokeNative(Native Method) 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.reflect.Method.invoke(Method.java:507) 07-12 21:04:40.222:E / AndroidRuntime(13948):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:895) 07-12 21:04:40.222:E / AndroidRuntime(13948):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653) 07-12 21:04:40.222:E / AndroidRuntime(13948):at dalvik.system.NativeStart.main(Native Method) 07-12 21:04:40.222:E / AndroidRuntime(13948):引起:java.lang.InstantiationException:com.dillonregi.multisender.multisender2 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.Class.newInstanceImpl(Native Method) 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.Class.newInstance(Class.java:1409) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1572) 07-12 21:04:40.222:E / AndroidRuntime(13948):......还有11个 07-12 21:04:40.222:E / AndroidRuntime(13948):[蓝色错误处理程序]为主要调试报告文件 07-12 21:04:40.222:E / AndroidRuntime(13948):java.lang.RuntimeException:无法实例化活动ComponentInfo {com.dillonregi.multisender / com.dillonregi.multisender.multisender2}:java.lang.InstantiationException:com .dillonregi.multisender.multisender2 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1580) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:942) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.os.Handler.dispatchMessage(Handler.java:99) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.os.Looper.loop(Looper.java:130) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.main(ActivityThread.java:3701) 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.reflect.Method.invokeNative(Native Method) 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.reflect.Method.invoke(Method.java:507) 07-12 21:04:40.222:E / AndroidRuntime(13948):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:895) 07-12 21:04:40.222:E / AndroidRuntime(13948):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653) 07-12 21:04:40.222:E / AndroidRuntime(13948):at dalvik.system.NativeStart.main(Native Method) 07-12 21:04:40.222:E / AndroidRuntime(13948):引起:java.lang.InstantiationException:com.dillonregi.multisender.multisender2 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.Class.newInstanceImpl(Native Method) 07-12 21:04:40.222:E / AndroidRuntime(13948):at java.lang.Class.newInstance(Class.java:1409) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.Instrumentation.newActivity(Instrumentation.java:1021) 07-12 21:04:40.222:E / AndroidRuntime(13948):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1572) 07-12 21:04:40.222:E / AndroidRuntime(13948):... 11更多