我正在尝试列出一些在我的Android应用程序中发现的JmDNS服务,每当我调用此方法时,我的应用程序就会在模拟器中崩溃?我试图注释掉代码块和方法内部的代码,但它仍然在模拟器上崩溃。有人有什么想法吗?
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
/**
* The main activity, which list the available services in the local network.
*
*/
public class ConnectActivity extends Activity {
private final static String LOG_TAG = ConnectActivity.class.getSimpleName();
// ===================View Models===================
// The view model of the service info list
private List<ServiceInfoViewModel> serviceInfoList = new ArrayList<ServiceInfoViewModel>();
private ServiceServer server = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.connect);
this.initViewModels();
this.initEventHandlers();
this.initMockData();
if (!checkWifiStatus()) {
// this.showToast("No wifi network!");
}
server = new ServiceServer("Whooznear");
int startedPort = server.start();
Log.i(LOG_TAG, "Started at " + startedPort);
ScheduledExecutorService scheduleTaskExecutor = Executors.newScheduledThreadPool(5);
// This schedule a runnable task every second
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
public void run() {
//Put Thread Code Here
//refreshServices();
}
}, 0, 1, TimeUnit.SECONDS);
}
private void refreshServices() {
new Thread(new Runnable() {
public void run() {
Log.i(LOG_TAG, "refresh services...");
testUpdateService();
JmDNS registry = null;
try {
registry = JmDNS.create();
List<String> enabledServices = LocalEnvironment
.getEnabledServices(ConnectActivity.this);
for (String serviceName : enabledServices) {
String serviceType = LocalEnvironment
.getServiceTypeByTitle(serviceName);
Log.i(LOG_TAG, "Register service..." + serviceType);
String text = "Test service";
Map<String, byte[]> properties = new HashMap<String, byte[]>();
properties.put("srvname", text.getBytes());
ServiceInfo service = ServiceInfo.create(serviceType,
"apache-someuniqueid", 80, 0, 0, true,
properties);
registry.registerService(service);
Log.i(LOG_TAG, "List service..." + service.getType());
final ServiceInfo[] services = registry.list(service
.getType());
Log.i(LOG_TAG, services.length + " services ("
+ serviceType + ") is found.");
ConnectActivity.this.runOnUiThread(new Runnable() {
public void run() {
for (ServiceInfo service : services) {
serviceInfoList
.add(new ServiceInfoViewModel(service));
}
notifyServiceListChanged();
}
});
}
} catch (Exception ex) {
ex.printStackTrace();
Log.e(LOG_TAG, ex.toString());
}
}
}).start();
}
private void onRefreshButtonClicked(View source) {
this.showToast("Clicked " + ((Button) source).getText());
this.refreshServices();
}
/*private void onSettingsButtonClicked(View source) {
Intent intent = new Intent();
intent.setClass(this, SettingsActivity.class);
this.startActivityForResult(intent, RESULT_OK);
}*/
private void onServiceListItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
ServiceInfoViewModel selectedService = serviceInfoList.get(arg2);
Log.i(LOG_TAG, "Selected service at " + selectedService.getServiceIp());
Intent intent = new Intent();
intent.putExtra("ServiceName", selectedService.getServiceName());
intent.putExtra("ServiceAddress", selectedService.getServiceIp());
intent.setClass(this, ProfileActivity.class);
this.startActivityForResult(intent, RESULT_OK);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch (resultCode) {
case RESULT_OK:
break;
default:
break;
}
}
private void initViewModels() {
ListView servicesListView = (ListView) this
.findViewById(R.id.servicesListView);
ListAdapter servicesListAdapter = new SimpleAdapter(this,
serviceInfoList, android.R.layout.simple_list_item_2,
new String[] { "serviceName", "serviceDesc" }, new int[] {
android.R.id.text1, android.R.id.text2 });
servicesListView.setAdapter(servicesListAdapter);
}
/**
* Initialize the event handlers
*/
private void initEventHandlers() {
// Service List View
ListView servicesListView = (ListView) this
.findViewById(R.id.servicesListView);
servicesListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
onServiceListItemSelected(arg0, arg1, arg2, arg3);
}
});
// Refresh Button
/*Button refreshButton = (Button) this
.findViewById(R.id.refreshServiceButton);
refreshButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View source) {
onRefreshButtonClicked(source);
}
});*/
// Settings Button
/*Button settingsButton = (Button) this
.findViewById(R.id.appSettingsButton);
settingsButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View source) {
onSettingsButtonClicked(source);
}
});*/
}
private void initMockData() {
}
private boolean checkWifiStatus() {
try {
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); // Network
State wifiState = conMan.getNetworkInfo(
ConnectivityManager.TYPE_WIFI).getState();
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
Log.i(LOG_TAG, "IP Address:" + info.getIpAddress());
LocalEnvironment.LocalIPAddress = info.getIpAddress();
LocalEnvironment.LocalIdentity = info.getMacAddress();
return wifiState == State.CONNECTED;
} catch (Exception ex) {
Log.e(this.getClass().getName(), "Check Wifi Status Failed!", ex);
this.showToast(ex.toString());
return false;
}
}
private void notifyServiceListChanged() {
ListView servicesListView = (ListView) this
.findViewById(R.id.servicesListView);
((SimpleAdapter) servicesListView.getAdapter()).notifyDataSetChanged();
}
private void testUpdateService() {
String text = "Test hypothetical web server";
Map<String, byte[]> properties = new HashMap<String, byte[]>();
properties.put("srvname", text.getBytes());
ServiceInfo service = ServiceInfo.create("_html._tcp.local.",
"apache-someuniqueid", 80, 0, 0, true, properties);
JmDNS registry = null;
Exception occuredEx = null;
int serviceCount = 0;
try {
registry = JmDNS.create();
registry.registerService(service);
ServiceInfo[] services = registry.list(service.getType());
serviceCount = services.length;
Log.d(LOG_TAG, serviceCount + " services found");
} catch (IOException ex) {
this.showToast(ex.toString());
occuredEx = ex;
} finally {
if (registry != null) {
try {
registry.close();
} catch (IOException ex) {
this.showToast(ex.toString());
occuredEx = ex;
}
}
}
}
private void showToast(String text) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
private void showToast(int id) {
ListView servicesListView = (ListView) this
.findViewById(R.id.servicesListView);
Toast.makeText(this, servicesListView.getItemAtPosition(id).toString(),
Toast.LENGTH_SHORT).show();
}
}
这是我用来调用上述方法的代码:
Intent myIntent = new Intent(ProfileActivity.this, ConnectActivity.class);
ProfileActivity.this.startActivity(myIntent);
这是堆栈跟踪:
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): Check Wifi Status Failed!
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): java.lang.SecurityException: ConnectivityService: Neither user 10036 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.os.Parcel.readException(Parcel.java:1321)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.os.Parcel.readException(Parcel.java:1275)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfo(IConnectivityManager.java:469)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:264)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at com.whooznear.android.ConnectActivity.checkWifiStatus(ConnectActivity.java:214)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at com.whooznear.android.ConnectActivity.onCreate(ConnectActivity.java:60)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.Activity.performCreate(Activity.java:4397)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.access$500(ActivityThread.java:122)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.os.Looper.loop(Looper.java:132)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.main(ActivityThread.java:4123)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at java.lang.reflect.Method.invoke(Method.java:491)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at dalvik.system.NativeStart.main(Native Method)
01-09 23:42:39.991: I/ServiceServer(1532): java.net.SocketException: Permission denied
01-09 23:42:40.032: I/ConnectActivity(1532): Started at -1
01-09 23:42:40.041: W/dalvikvm(1532): threadid=9: thread exiting with uncaught exception (group=0x40 014760)
01-09 23:42:40.071: E/AndroidRuntime(1532): FATAL EXCEPTION: Thread-12
01-09 23:42:40.071: E/AndroidRuntime(1532): java.lang.NullPointerException
01-09 23:42:40.071: E/AndroidRuntime(1532): at com.whooznear.android.ServiceServer.serverThreadProc(ServiceServer.java:61)
01-09 23:42:40.071: E/AndroidRuntime(1532): at com.whooznear.android.ServiceServer.access$0(ServiceServer.java:57)
01-09 23:42:40.071: E/AndroidRuntime(1532): at com.whooznear.android.ServiceServer$1.run(ServiceServer.java:52)
01-09 23:42:40.693: D/dalvikvm(1532): GC_CONCURRENT freed 416K, 7% free 7200K/7687K, paused 6ms+27ms
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): Check Wifi Status Failed!
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): java.lang.SecurityException: ConnectivityService: Neither user 10036 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.os.Parcel.readException(Parcel.java:1321)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.os.Parcel.readException(Parcel.java:1275)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfo(IConnectivityManager.java:469)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:264)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at com.whooznear.android.ConnectActivity.checkWifiStatus(ConnectActivity.java:214)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at com.whooznear.android.ConnectActivity.onCreate(ConnectActivity.java:60)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.Activity.performCreate(Activity.java:4397)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.access$500(ActivityThread.java:122)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.os.Looper.loop(Looper.java:132)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at android.app.ActivityThread.main(ActivityThread.java:4123)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at java.lang.reflect.Method.invoke(Method.java:491)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-09 23:42:41.041: E/com.whooznear.android.ConnectActivity(1532): at dalvik.system.NativeStart.main(Native Method)
01-09 23:42:41.151: I/ServiceServer(1532): java.net.SocketException: Permission denied
01-09 23:44:09.541: I/ActivityThread(1575): Pub com.whooznear.android: com.whooznear.android.ProfileProvider
01-09 23:44:10.054: D/dalvikvm(1575): GC_FOR_ALLOC freed 40K, 4% free 6337K/6595K, paused 247ms
01-09 23:44:10.112: I/dalvikvm-heap(1575): Grow heap (frag case) to 6.805MB for 588816-byte allocation
01-09 23:44:10.422: D/dalvikvm(1575): GC_FOR_ALLOC freed 8K, 4% free 6903K/7175K, paused 265ms
01-09 23:44:10.791: D/dalvikvm(1575): GC_CONCURRENT freed <1K, 4% free 6903K/7175K, paused 72ms+3ms
01-09 23:44:14.162: D/dalvikvm(1575): GC_FOR_ALLOC freed 603K, 11% free 6667K/7431K, paused 68ms
01-09 23:44:14.334: D/dalvikvm(1575): GC_CONCURRENT freed <1K, 4% free 7168K/7431K, paused 6ms+16ms
01-09 23:44:14.673: W/Profile(1575): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): Check Wifi Status Failed!
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): java.lang.SecurityException: ConnectivityService: Neither user 10036 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.os.Parcel.readException(Parcel.java:1321)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.os.Parcel.readException(Parcel.java:1275)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfo(IConnectivityManager.java:469)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:264)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at com.whooznear.android.ConnectActivity.checkWifiStatus(ConnectActivity.java:214)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at com.whooznear.android.ConnectActivity.onCreate(ConnectActivity.java:60)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.Activity.performCreate(Activity.java:4397)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.ActivityThread.access$500(ActivityThread.java:122)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.os.Looper.loop(Looper.java:132)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at android.app.ActivityThread.main(ActivityThread.java:4123)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at java.lang.reflect.Method.invoke(Method.java:491)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-09 23:44:19.782: E/com.whooznear.android.ConnectActivity(1575): at dalvik.system.NativeStart.main(Native Method)
01-09 23:44:19.831: I/ServiceServer(1575): java.net.SocketException: Permission denied
01-09 23:44:19.861: I/ConnectActivity(1575): Started at -1
01-09 23:44:19.872: W/dalvikvm(1575): threadid=10: thread exiting with uncaught exception (group=0x40 014760)
01-09 23:44:19.872: E/AndroidRuntime(1575): FATAL EXCEPTION: Thread-13
01-09 23:44:19.872: E/AndroidRuntime(1575): java.lang.NullPointerException
01-09 23:44:19.872: E/AndroidRuntime(1575): at com.whooznear.android.ServiceServer.serverThreadProc(ServiceServer.java:61)
01-09 23:44:19.872: E/AndroidRuntime(1575): at com.whooznear.android.ServiceServer.access$0(ServiceServer.java:57)
01-09 23:44:19.872: E/AndroidRuntime(1575): at com.whooznear.android.ServiceServer$1.run(ServiceServer.java:52)
01-09 23:44:20.242: D/dalvikvm(1575): GC_CONCURRENT freed 415K, 7% free 7200K/7687K, paused 6ms+18ms
01-09 23:44:23.991: I/Process(1575): Sending signal. PID: 1575 SIG: 9
01-09 23:45:38.371: I/ActivityThread(1619): Pub com.whooznear.android: com.whooznear.android.ProfileProvider
01-09 23:45:38.651: D/dalvikvm(1619): GC_FOR_ALLOC freed 41K, 4% free 6337K/6595K, paused 91ms
01-09 23:45:38.671: I/dalvikvm-heap(1619): Grow heap (frag case) to 6.805MB for 588816-byte allocation
01-09 23:45:38.9 01: D/dalvikvm(1619): GC_FOR_ALLOC freed 8K, 4% free 6903K/7175K, paused 168ms
01-09 23:45:39.182: D/dalvikvm(1619): GC_CONCURRENT freed <1K, 4% free 6903K/7175K, paused 6ms+27ms
01-09 23:45:42.671: D/dalvikvm(1619): GC_FOR_ALLOC freed 603K, 11% free 6667K/7431K, paused 71ms
01-09 23:45:42.831: D/dalvikvm(1619): GC_CONCURRENT freed <1K, 4% free 7168K/7431K, paused 6ms+4ms
01-09 23:45:43.192: W/Profile(1619): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-09 23:45:49.541: W/Profile(1619): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-09 23:45:49.821: D/dalvikvm(1619): GC_CONCURRENT freed 389K, 7% free 7214K/7687K, paused 6ms+6ms
01-09 23:45:55.831: W/Profile(1619): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-09 23:45:57.022: D/dalvikvm(1619): GC_CONCURRENT freed 115K, 3% free 7549K/7751K, paused 8ms+21ms
01-09 23:50:58.672: W/Profile(1619): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-09 23:57:17.532: W/Profile(1619): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-09 23:57:18.632: D/dalvikvm(1619): GC_CONCURRENT freed 130K, 3% free 7857K/8071K, paused 10ms+7ms
01-10 00:08:48.752: I/ActivityThread(1662): Pub com.whooznear.android: com.whooznear.android.ProfileProvider
01-10 00:08:49.2 01: D/dalvikvm(1662): GC_FOR_ALLOC freed 42K, 4% free 6336K/6595K, paused 198ms
01-10 00:08:49.241: I/dalvikvm-heap(1662): Grow heap (frag case) to 6.805MB for 588816-byte allocation
01-10 00:08:49.471: D/dalvikvm(1662): GC_FOR_ALLOC freed 8K, 4% free 6903K/7175K, paused 196ms
01-10 00:08:49.712: D/dalvikvm(1662): GC_CONCURRENT freed <1K, 4% free 6903K/7175K, paused 7ms+3ms
01-10 00:08:53.211: D/dalvikvm(1662): GC_FOR_ALLOC freed 603K, 11% free 6666K/7431K, paused 69ms
01-10 00:08:53.391: D/dalvikvm(1662): GC_CONCURRENT freed <1K, 4% free 7167K/7431K, paused 6ms+26ms
01-10 00:08:53.732: W/Profile(1662): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): Check Wifi Status Failed!
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): java.lang.SecurityException: ConnectivityService: Neither user 10036 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.os.Parcel.readException(Parcel.java:1321)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.os.Parcel.readException(Parcel.java:1275)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfo(IConnectivityManager.java:469)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:264)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at com.whooznear.android.ConnectActivity.checkWifiStatus(ConnectActivity.java:214)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at com.whooznear.android.ConnectActivity.onCreate(ConnectActivity.java:60)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.Activity.performCreate(Activity.java:4397)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.ActivityThread.access$500(ActivityThread.java:122)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.os.Looper.loop(Looper.java:132)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at android.app.ActivityThread.main(ActivityThread.java:4123)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at java.lang.reflect.Method.invoke(Method.java:491)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-10 00:09:34.981: E/com.whooznear.android.ConnectActivity(1662): at dalvik.system.NativeStart.main(Native Method)
01-10 00:09:35.051: I/ServiceServer(1662): java.net.SocketException: Permission denied
01-10 00:09:35.051: I/ConnectActivity(1662): Started at -1
01-10 00:09:35.081: W/dalvikvm(1662): threadid=9: thread exiting with uncaught exception (group=0x40 014760)
01-10 00:09:35.081: E/AndroidRuntime(1662): FATAL EXCEPTION: Thread-12
01-10 00:09:35.081: E/AndroidRuntime(1662): java.lang.NullPointerException
01-10 00:09:35.081: E/AndroidRuntime(1662): at com.whooznear.android.ServiceServer.serverThreadProc(ServiceServer.java:61)
01-10 00:09:35.081: E/AndroidRuntime(1662): at com.whooznear.android.ServiceServer.access$0(ServiceServer.java:57)
01-10 00:09:35.081: E/AndroidRuntime(1662): at com.whooznear.android.ServiceServer$1.run(ServiceServer.java:52)
01-10 00:09:35.732: D/dalvikvm(1662): GC_CONCURRENT freed 416K, 7% free 72 01K/7687K, paused 7ms+278ms
01-10 00:09:52.712: I/ActivityThread(1699): Pub com.whooznear.android: com.whooznear.android.ProfileProvider
01-10 00:09:53.031: D/dalvikvm(1699): GC_FOR_ALLOC freed 42K, 4% free 6336K/6595K, paused 93ms
01-10 00:09:53.051: I/dalvikvm-heap(1699): Grow heap (frag case) to 6.805MB for 588816-byte allocation
01-10 00:09:53.171: D/dalvikvm(1699): GC_FOR_ALLOC freed 8K, 4% free 6903K/7175K, paused 79ms
01-10 00:09:53.431: D/dalvikvm(1699): GC_CONCURRENT freed <1K, 4% free 6903K/7175K, paused 5ms+3ms
01-10 00:09:56.832: D/dalvikvm(1699): GC_FOR_ALLOC freed 603K, 11% free 6666K/7431K, paused 82ms
01-10 00:09:57.031: D/dalvikvm(1699): GC_CONCURRENT freed <1K, 4% free 7167K/7431K, paused 12ms+14ms
01-10 00:09:57.381: W/Profile(1699): Invalid profile, java.lang.ArrayIndexOutOfBoundsException: index=1 length=1
最佳答案
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): Check Wifi Status Failed!
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): java.lang.SecurityException: ConnectivityService: Neither user 10036 nor current process has android.permission.ACCESS_NETWORK_STATE.
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.os.Parcel.readException(Parcel.java:1321)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.os.Parcel.readException(Parcel.java:1275)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.net.IConnectivityManager$Stub$Proxy.getNetworkInfo(IConnectivityManager.java:469)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at android.net.ConnectivityManager.getNetworkInfo(ConnectivityManager.java:264)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at com.whooznear.android.ConnectActivity.checkWifiStatus(ConnectActivity.java:214)
01-09 23:42:39.951: E/com.whooznear.android.ConnectActivity(1532): at com.whooznear.android.ConnectActivity.onCreate(ConnectActivity.java:60)
您需要相应的用户权限才能检查wifi状态(更具体地说是ConnectivityManager API),将以下权限添加到应用的AndroidManifest.xml中:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Note that to us JmDNS, you also need the following permissions -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
试试看,通过阅读代码,您可能还会遇到其他问题。