2013-05-16 144 views
4

我nubie在編程Android和我在這裏4米知道很多discrabing我的問題解決方案的網頁,但現在我失去了2天仍不要得到解決方案。請幫幫我!Android的致命異常MAIN:了java.lang.RuntimeException:無法啓動活動ComponentInfo

首先我所有的錯誤:

01-02 11:08:27.314: D/AndroidRuntime(1045): Shutting down VM 
01-02 11:08:27.314: W/dalvikvm(1045): threadid=1: thread exiting with uncaught exception (group=0x409e61f8) 
01-02 11:08:27.324: E/AndroidRuntime(1045): FATAL EXCEPTION: main 
01-02 11:08:27.324: E/AndroidRuntime(1045): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.wifiscan/com.example.wifiscan.activity_wifi_scan}: java.lang.ClassNotFoundException: com.example.wifiscan.activity_wifi_scan 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.ActivityThread.access$600(ActivityThread.java:123) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.os.Looper.loop(Looper.java:137) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.ActivityThread.main(ActivityThread.java:4424) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at java.lang.reflect.Method.invoke(Method.java:511) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at dalvik.system.NativeStart.main(Native Method) 
01-02 11:08:27.324: E/AndroidRuntime(1045): Caused by: java.lang.ClassNotFoundException: com.example.wifiscan.activity_wifi_scan 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871) 
01-02 11:08:27.324: E/AndroidRuntime(1045):  ... 11 more 

我WifiScan:

public class WifiScan extends Activity implements OnClickListener {  
    WifiManager wifi;  
    ListView lv; 
    TextView textStatus; 
    Button buttonScan; 
    int size = 0; 
    List<ScanResult> results; 

    String ITEM_KEY = "key"; 
    ArrayList<HashMap<String, String>> arraylist = new ArrayList<HashMap<String, String>>(); 
    SimpleAdapter adapter; 

    /* Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_wifi_scan); 

     buttonScan = (Button) findViewById(R.id.scan); 
     buttonScan.setOnClickListener(this); 
     lv = (ListView)findViewById(R.id.list); 

     wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
     if (wifi.isWifiEnabled() == false) 
     { 
      Toast.makeText(getApplicationContext(), "wifi is disabled..making it enabled", Toast.LENGTH_LONG).show(); 
      wifi.setWifiEnabled(true); 
     } 
     wifi.startScan(); //js dopisal 
     // this.adapter = new SimpleAdapter(WiFiDemo.this, arraylist, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.list_value }); 
     lv.setAdapter(this.adapter); 

       registerReceiver(new BroadcastReceiver() 
     { 
      @Override 
      public void onReceive(Context c, Intent intent) 
      { 
       results = wifi.getScanResults(); 
       size = results.size(); 
      } 
     }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));      
    } 

    public void onClick(View view) 
    { 
     arraylist.clear();   
     wifi.startScan(); 

       Toast.makeText(this, "Scanning...." + size, Toast.LENGTH_SHORT).show(); 
     try 
     { 
      size = size - 1; 
      while (size >= 0) 
      { 
       HashMap<String, String> item = new HashMap<String, String>();      
       item.put(ITEM_KEY, results.get(size).SSID + " " + results.get(size).capabilities); 

       arraylist.add(item);  
       size--; 
       adapter.notifyDataSetChanged();     
      } 
     } 
     catch (Exception e) 
     { }   
    }  
} 

我activity_wifi_scan.xml文件:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/TableLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context=".WifiScan" > 

    <Button  
     android:id="@+id/scan" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="scan" 
     android:text="SCAN" /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 

</TableLayout> 

而且我AndroidManifest文件:

<?xml version="1.0" encoding="utf-8"?> 
     <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.wifiscan" 
    android:versionCode="1" 
      android:versionName="1.0" > 

     <uses-premission android:name="android.permission.ACCESS_WIFI_STATE"/> 
     <uses-permission android:name="android.permission.WAKE_LOCK"/> 
     <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-permission> 
    <uses-permission android:name="android.permission.INTERNET"> </uses-permission> 

    <uses-sdk 
      android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

    <activity android:name=".activity_wifi_scan"> 
     <intent-filter> 
       <action android:name="android.intent.action.MAIN"></action> 
       <category android:name="android.intent.category.LAUNCHER"></category> 
       <data /> 
     </intent-filter> 
    </activity> 

    <receiver android:name=".activity_wifi_scan"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER"/> 
      <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/> 
     </intent-filter> 
    </receiver>   
    </application> 
</manifest> 
+0

請張貼您的代碼以獲取更多詳細信息 –

+0

確保您的Activity在Manifest.xml文件中定義。如果已定義,請發佈您的代碼。 –

+0

我已解決此問題。請參閱此問題的更多細節http://stackoverflow.com/a/16607165/1118886 –

回答

2

您的活動名稱是WifiScan,但你已經宣佈它作爲.activity_wifi_scan改變它,然後再試一次。

更改<activity>元素:

<activity android:name=".WifiScan"> 
     <intent-filter> 
       <action android:name="android.intent.action.MAIN"></action> 
       <category android:name="android.intent.category.LAUNCHER"></category> 
       <data /> 
     </intent-filter> 
    </activity> 
+1

我的班級名稱是WifiScan,是的,我不明白爲什麼在xml中有.activity_wifi_scan,畢竟你是通過R.layout.activity_wifi_scan獲得sdetContentView。那麼? – wanttobeprofessional

+0

* vinoth *提供瞭解決方案,在AndroidManifest中,您必須將Activity類名稱(相對於聲明的「package」,或者是規範類名稱) – gunar

0

試圖將活動com.example.wifiscan.activity_wifi_scan添加到您的AndroidManifest.xml

+0

,並且確保有在宣佈活動沒有錯字的錯誤 – vinoth

+0

@It似乎他的類名是錯誤的...跟蹤沒有按」牛逼抱怨清單 – Pragnani

+0

如果我添加com.example.wifiscan.activity_wifi_scan insted的的.activity_wifi_scan對bouth安卓:名稱標籤,它顯示錯誤控制檯: – wanttobeprofessional

0

你沒有初始化清單檔案中的

0

解決方案1的活動:嘗試清潔您的項目,重新啓動蝕。 解決方案2:檢查清單文件。 解決方案3:檢查清單文件中的標籤和標籤是否與活動的正確位置匹配。

這將有助於您發佈代碼。

0

我是有這個錯誤和搜索小時後我已經出來了,這是我的錯誤(哦,但這是不可能的LOL!)。

這個問題對我來說是我已經添加了android:theme="@style/Theme.appcompat.Light"佈局個XML,而不是應用程序清單。

一旦我已經移除佈局的atributes,取而代之的清單一切一個工作就像預期。

相關問題