2014-02-08 45 views
0

我試圖讓一個應用程序獲取無線網絡附近的規範來將它與另一個應用程序結合起來,但是我在AndroidManifest.xml文件中遇到錯誤我不知道如何解決。該錯誤在下面顯示的android:label =「@ string/title_activity_list_wifi」行中。問候獲取無線網絡附近的數據(代碼中出現錯誤)

// AndroidManifest.xml file. 
    <?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.wifi" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="17" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> 
    <application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
    android:name="com.example.wifi.MainActivity" 
    android:label="@string/app_name" > 
    <intent-filter> 
    <action android:name="android.intent.action.MAIN" /> 
    <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
    </activity> 
    <activity 
    android:name="com.example.wifi.ListWifiActivity" 
    android:label="@string/title_activity_list_wifi"> 
    </activity> 
    </application> 
    </manifest> 
// src/com.example.wifi/MainActivity.java 
package com.example.wifi; 
import java.util.List; 
import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.content.IntentFilter; 
import android.net.wifi.ScanResult; 
import android.net.wifi.WifiManager; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 

public class MainActivity extends Activity { 
WifiManager mainWifiObj; 
WifiScanReceiver wifiReciever; 
ListView list; 
String wifis[]; 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
list = (ListView)findViewById(R.id.listView1); 
mainWifiObj = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
wifiReciever = new WifiScanReceiver(); 
mainWifiObj.startScan(); 
} 
protected void onPause() { 
unregisterReceiver(wifiReciever); 
super.onPause(); 
} 
protected void onResume() { 
registerReceiver(wifiReciever, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); 
super.onResume(); 
} 
class WifiScanReceiver extends BroadcastReceiver { 
@SuppressLint("UseValueOf") 
public void onReceive(Context c, Intent intent) { 
List<ScanResult> wifiScanList = mainWifiObj.getScanResults(); 
wifis = new String[wifiScanList.size()]; 
for(int i = 0; i < wifiScanList.size(); i++){ 
wifis[i] = ((wifiScanList.get(i)).toString()); 
} 
list.setAdapter(new ArrayAdapter<String>(getApplicationContext(), 
android.R.layout.simple_list_item_1,wifis)); 
} 
} 
} 
+1

您認爲告訴我們錯誤是什麼可能有用嗎? – Simon

+0

它說找不到符合給定名稱的行的資源android:label =「@ string/title_activity_list_wifi」 – user3082757

回答

0

android:label="@string/title_activity_list_wifi"是指串title_activity_list_wifi在strings.xml文件(更多關於字符串資源:http://developer.android.com/guide/topics/resources/string-resource.html),這顯然不存在。

有兩件事情可以做,以解決這個問題:
- 使用硬編碼字符串,而不是一個參考:

android:label="This activity has a list of wifi networks" 

- 添加字符串到strings.xml檔案(RES /值):

<string name="title_activity_list_wifi">This activity has a list of wifi networks</string> 
+0

謝謝......問題已解決 – user3082757

+0

歡迎您!請按下向上和向下按鈕下方的綠色標記,謝謝。 – Mdlc

相關問題