1、
Android:java.net.SocketException: socket failed: EACCES (Permission denied)
android程序在调试时出现了套接字异常“java.net.SocketException: Permission denied”该如何解决
这是一个经典错误, Socket不能对外连接,错误不会被报出,调试的时候,能看到Exception, 一般是抛出 java.net.socketexception permission denied这个异常。 只要你的程序想联网,就会抛出这个异常,最终联网失败。 原因是: 需要访问到网络必须要有权限, 在AndroidManifest.xml中,需要进行如下配置: <uses-permission android:name="android.permission.INTERNET" />
2、
android.os.NetworkOnMainThreadException
在android 2.3上设计的下载程序,在android 4.0上运行时报android.os.NetworkOnMainThreadException异常,原来在4.0中,访问网络不能在主程序中进行,
注意:造成这样的错误原因是代码不符合Android规范,如果把上面访问方式改为异步操作就不会出现在4.0上访问出现 android.os.NetworkOnMainThreadException异常
如:
new Thread(){
@Override
public void run(){
//你要执行的方法
//执行完毕后给handler发送一个空消息
handler.sendEmptyMessage(0);
}
}.start();
//定义Handler对象
private Handler handler =new Handler(){
@Override
//当有消息发送出来的时候就执行Handler的这个方法
public void handleMessage(Message msg){
super.handleMessage(msg);
//处理UI
}
};
3、
10-01 08:35:59.125: W/ActivityManager(297): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
10-01 08:35:59.175: E/ActivityThread(678): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d07088 that was originally bound here
10-01 08:35:59.175: E/ActivityThread(678): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d07088 that was originally bound here
10-01 08:35:59.175: E/ActivityThread(678): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
10-01 08:35:59.175: E/ActivityThread(678): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
10-01 08:35:59.175: E/ActivityThread(678): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
10-01 08:35:59.175: E/ActivityThread(678): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
10-01 08:35:59.175: E/ActivityThread(678): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
10-01 08:35:59.175: E/ActivityThread(678): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
10-01 08:35:59.175: E/ActivityThread(678): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
10-01 08:35:59.175: E/ActivityThread(678): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
10-01 08:35:59.175: E/ActivityThread(678): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
10-01 08:35:59.175: E/ActivityThread(678): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
10-01 08:35:59.175: E/ActivityThread(678): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
10-01 08:35:59.175: E/ActivityThread(678): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-01 08:35:59.175: E/ActivityThread(678): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-01 08:35:59.175: E/ActivityThread(678): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-01 08:35:59.175: E/ActivityThread(678): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-01 08:35:59.175: E/ActivityThread(678): at java.lang.Thread.run(Thread.java:856)
10-01 08:35:59.205: E/StrictMode(678): null
10-01 08:35:59.205: E/StrictMode(678): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d07088 that was originally bound here
上面的异常大概是报了启动service后,没有将service给unbound掉,但是事实上我写的应用里只是一个简单的activity,还没有涉及到service的东西,后来查阅以后该异常是因为android的模拟器上自带的邮件应用的问题,所以需要对模拟器进行一些设置,禁用此类无关的应用,具体操作为:
“设置”---->"所有应用"---->"Exchange Services"--->“disable”
4、error opening trace file: No such file or directory (2)
删除<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
添加<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
5、WARNING: Application does not specify an API level requirement!
Device API version is 17 (Android 4.2.2)
网上一查是由于没有指定users sdk的缘故,修改AndroidManifest.xml文件.
加入:
<uses-sdk android:minSdkVersion="17"></uses-sdk>
加在<manifest> </manifest> 之间.