问题描述
- 在Fragment中添加了一个按钮跳转到activity,但是一按按钮就闪退,求大神指点!!!
-
这是错误日志:
我已经在网络请求的部分新建了一个子线程了,那为什么还是点击按钮就闪退呢,下面是新建的子线程,求大神指点迷津!!!
public abstract class MyTimerCheck {private int mCount = 0;
private int mTimeOutCount = 1;
private int mSleepTime = 1000; // 1s
private boolean mExitFlag = false;
private Thread mThread = null;
/** * Do not process UI work in this. */ public abstract void doTimerCheckWork(); public abstract void doTimeOutWork(); public MyTimerCheck() { mThread = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub while (!mExitFlag) { mCount++; if (mCount < mTimeOutCount) { doTimerCheckWork(); try { mThread.sleep(mSleepTime); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); exit(); } } else { doTimeOutWork(); } } } }); } /** * start * @param times How many times will check? * @param sleepTime ms, Every check sleep time. */ public void start(int timeOutCount, int sleepTime) { mTimeOutCount = timeOutCount; mSleepTime = sleepTime; mThread.start(); } public void exit() { mExitFlag = true; }
}
解决方案
多数是你线程和ui交互搞得,你还是看下日志吧,应该更清楚显示是吗什么错误
解决方案二:
网络访问不能在主线程
解决方案三:
是网络请求在MainThread中产生的异常. 可以看下这个链接http://blog.csdn.net/mad1989/article/details/25964495
解决方案四:
你是不是在thread里更新ui了?
时间: 2024-12-08 17:42:33