Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)

今天做了一个手机查询归属地的小程序,遇到了一个疑惑,纠结了好久。。后来发现是低级错误,吐血。。。。所以把它写出来分享,希望大家不要犯如此低级的错误


报错提示:Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)

11-13 08:26:17.002: W/System.err(4828):  at android.app.ActivityThread.main(ActivityThread.java:4340)
11-13 08:26:17.002: W/System.err(4828):  at java.lang.reflect.Method.invokeNative(Native Method)
11-13 08:26:17.012: W/System.err(4828):  at java.lang.reflect.Method.invoke(Method.java:511)
11-13 08:26:17.062: W/System.err(4828):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-13 08:26:17.062: W/System.err(4828):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-13 08:26:17.062: W/System.err(4828):  at dalvik.system.NativeStart.main(Native Method)
11-13 08:26:17.161: I/WindowManager(114): createSurface Window{4160d2c0 Toast paused=false}: DRAW NOW PENDING
11-13 08:26:17.261: D/dalvikvm(4828): GC_CONCURRENT freed 276K, 4% free 10034K/10439K, paused 11ms+26ms
11-13 08:28:40.201: W/ThrottleService(114): unable to find stats for iface rmnet0
11-13 08:31:19.921: A/NetworkStats(114): problem reading network stats
11-13 08:31:19.921: A/NetworkStats(114): java.lang.IllegalStateException: problem parsing line: null
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:313)
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.server.NetworkManagementService.getNetworkStatsUidDetail(NetworkManagementService.java:1271)
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.server.net.NetworkStatsService.performPollLocked(NetworkStatsService.java:810)
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.server.net.NetworkStatsService.performPoll(NetworkStatsService.java:771)
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.server.net.NetworkStatsService.access$100(NetworkStatsService.java:128)
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.server.net.NetworkStatsService$3.onReceive(NetworkStatsService.java:610)
11-13 08:31:19.921: A/NetworkStats(114):  at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
11-13 08:31:19.921: A/NetworkStats(114):  at android.os.Handler.handleCallback(Handler.java:605)
11-13 08:31:19.921: A/NetworkStats(114):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-13 08:31:19.921: A/NetworkStats(114):  at android.os.Looper.loop(Looper.java:137)
11-13 08:31:19.921: A/NetworkStats(114):  at android.os.HandlerThread.run(HandlerThread.java:60)
11-13 08:31:19.921: A/NetworkStats(114): Caused by: java.io.FileNotFoundException: /proc/net/xt_qtaguid/stats: open failed: ENOENT (No such file or directory)
11-13 08:31:19.921: A/NetworkStats(114):  at libcore.io.IoBridge.open(IoBridge.java:406)
11-13 08:31:19.921: A/NetworkStats(114):  at java.io.FileInputStream.(FileInputStream.java:78)
11-13 08:31:19.921: A/NetworkStats(114):  at java.io.FileReader.(FileReader.java:42)
11-13 08:31:19.921: A/NetworkStats(114):  at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:272)
11-13 08:31:19.921: A/NetworkStats(114):  ... 10 more
11-13 08:31:19.921: A/NetworkStats(114): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
11-13 08:31:19.921: A/NetworkStats(114):  at libcore.io.Posix.open(Native Method)
11-13 08:31:19.921: A/NetworkStats(114):  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:98)
11-13 08:31:19.921: A/NetworkStats(114):  at libcore.io.IoBridge.open(IoBridge.java:390)
11-13 08:31:19.921: A/NetworkStats(114):  ... 13 more
11-13 08:31:20.211: D/dalvikvm(114): GC_CONCURRENT freed 394K, 10% free 12112K/13383K, paused 26ms+11ms
: E/(): Device disconnected: 1
: E/(): Device disconnected



上网百度了一下,说什么网络断开连接没连接,什么内存不足等等。。。我一一检查了自己的程序,都不是这些问题。

纠结好久之后,才想起这是连接网络的程序,连接网络都是耗时的。在主线程上面运行耗时的操作时不行的,后来换了2.3的模拟器去运行(2.3模拟器没有在主线程做是否耗时判断),结果成功运行了。这样就确定了问题所在了。


解决办法 一:

在AndroidManifest.xml中修改uses-sdk
            android:minSdkVersion="8"/>


解决办法二:把耗时操作放进子线程中


package com.example.webservice;


import com.webservice.service.WebServiceRequestFromAndroid;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
 private Button button = null;
 private EditText phone = null;
 private static TextView resultText = null;
 
 private final int SUCCESS=1;
 private final int ERROR=1;
 private String result;
 
 private Handler handler = new Handler(){

  @Override
  public void handleMessage(Message msg) {
   if(msg.what==SUCCESS){
    String r = (String) msg.obj;
    resultText.setText(r);
   }else if(msg.what==ERROR){
    Toast.makeText(MainActivity.this, "服务器繁忙", 2).show();
   }
  }
  
 };

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  button=(Button) findViewById(R.id.button);
  phone=(EditText) findViewById(R.id.phonenum);
  resultText = (TextView) findViewById(R.id.result);
  
  button.setOnClickListener(new OnClickListener() {
   
   @Override
   public void onClick(View v) {
    final String phoneNum = phone.getText().toString();
    if(!phoneNum.equals("")){
     new Thread(){
      public void run(){
       try {
        result = WebServiceRequestFromAndroid.getAddress(phoneNum); //这代码访问了网络,是耗时操作。所以把它放进子线程中
        Message msg = new Message();
        msg.what=SUCCESS;
        msg.obj=result;
        handler.sendMessage(msg);
       } catch (Exception e) {
        Message msg = new Message();
        msg.what=ERROR;
        handler.sendMessage(msg);
        
       }
      }
     }.start();
    }else{
     Toast.makeText(MainActivity.this, "请输入手机号", 2).show();
    }
    
   }
  });
 }


}




你可能感兴趣的:(问题记录)