我制作了一个新应用来检查SSID。代码很好,但是当我运行模拟并尝试运行应用程序时,他会停止工作。任何的想法?抱歉我的英文。
这是我的日志:
03-11 15:45:22.580: D/AndroidRuntime(867): Shutting down VM
03-11 15:45:22.580: W/dalvikvm(867): threadid=1: thread exiting with uncaught exception (group=0xb1a45ba8)
03-11 15:45:22.590: E/AndroidRuntime(867): FATAL EXCEPTION: main
03-11 15:45:22.590: E/AndroidRuntime(867): Process: com.example.wifiscanner, PID: 867
03-11 15:45:22.590: E/AndroidRuntime(867): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.wifiscanner/com.example.wifiscanner.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.wifiscanner.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.wifiscanner-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.wifiscanner-2, /system/lib]]
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.os.Handler.dispatchMessage(Handler.java:102)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.os.Looper.loop(Looper.java:136)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-11 15:45:22.590: E/AndroidRuntime(867): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 15:45:22.590: E/AndroidRuntime(867): at java.lang.reflect.Method.invoke(Method.java:515)
03-11 15:45:22.590: E/AndroidRuntime(867): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-11 15:45:22.590: E/AndroidRuntime(867): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-11 15:45:22.590: E/AndroidRuntime(867): at dalvik.system.NativeStart.main(Native Method)
03-11 15:45:22.590: E/AndroidRuntime(867): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.wifiscanner.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.wifiscanner-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.wifiscanner-2, /system/lib]]
03-11 15:45:22.590: E/AndroidRuntime(867): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-11 15:45:22.590: E/AndroidRuntime(867): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-11 15:45:22.590: E/AndroidRuntime(867): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
03-11 15:45:22.590: E/AndroidRuntime(867): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
03-11 15:45:22.590: E/AndroidRuntime(867): ... 11 more
03-11 15:45:25.940: I/Process(867): Sending signal. PID: 867 SIG: 9
我改变了我的ClassHeader.java的活动,我正在使用Eclipse。
我解决了这个问题。我重命名并对代码进行了更改:
package com.example.wifiscanner;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void getWifiInfo( Context ctxt ) {
int speed = 0;
String ssid = null;
String bssid = null;
String mac = "00:00:00:00:00:00";
String netmask = "255.255.255.255";
String gateway = "0.0.0.0";
WifiInfo info;
WifiManager wifi = (WifiManager) ctxt.getSystemService(Context.WIFI_SERVICE);{
if (wifi != null) {
info = wifi.getConnectionInfo();
speed = info.getLinkSpeed();
ssid = info.getSSID();
bssid = info.getBSSID();
mac = info.getMacAddress();
gateway = getSigned( wifi.getDhcpInfo().gateway );
netmask = getSigned( wifi.getDhcpInfo().netmask );
System.out.println( "Speed : " + speed
+ "ssid : " + ssid
+ "bssid :" + bssid
+ "macAddress :" + mac
+ "netmaskIp :" + netmask
+ "gatewayIp :" + gateway );
}else{
System.out.println( "Wi-fi is Null");
}
}
}
public static String getSigned(int ips ) {
String ip = "";
for (int k = 0; k < 4; k++) {
ip = ips + (( ips >> k * 8) & 0xFF) + ".";
}
return ip.substring(0, ip.length() - 1);
}
}
现在我可以在模拟器上运行应用程序了,但它不显示按钮而没有任何内容。只是一个白色的屏幕。任何的想法?并请求帮助!再次抱歉...
答案 0 :(得分:0)
您错过了将其称为Activity
及其标准方法。
public class ClassHeader extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_xml);
}
}
请花些时间阅读有关活动生命周期原则的内容,在开始使用Android进行编程之前,这些原则非常重要。
http://developer.android.com/training/basics/activity-lifecycle/index.html