我正在运行一个应用程序来获取手机的 Mac 地址,我编写了代码并且我在编译时没有错误,但是如果我点击 main_activity,预览下会出现错误:找不到以下类:
- Textview(更改为 TextView、修复构建路径、编辑 XML)。
事实上我没有输出。
那是 MainActivity:
package com.example.app1;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tvUIDS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvUIDS = (TextView) findViewById(R.id.tv_uids);
StringBuilder sb = new StringBuilder();
TelephonyManager telMan = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
sb.append("IMEI: " + telMan.getDeviceId() + "\n");
sb.append("Android ID: " + Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID) + "\n");
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String mac_adr = wm.getConnectionInfo().getMacAddress();
if (mac_adr != null) {
sb.append("WLAN MAC Address: " + mac_adr + "\n");
} else {
sb.append("WLAN MAC Address: not supported on this device\n");
}
BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
if (ba != null) {
sb.append("Bluetooth Address: " + ba.getAddress() + "\n");
} else {
sb.append("Bluetooth Address: not supported on this device\n");
}
tvUIDS.setText(sb.toString());
}
}
这就是activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
抱歉,我是做应用程序的新手。我该如何解决?
慕仙森
相关分类