Android Studio的“ TextView”类问题

时间:2019-02-01 21:59:16

标签: java android android-studio

我正在运行一个应用程序来获取手机的Mac地址,我执行了代码,并且在编译时没有错误,但是如果我单击main_activity,则预览下会出现错误:找不到以下类:

  

-Textview(更改为TextView,修复构建路径,编辑XML)。

实际上我没有输出。

这是MainActivity:

'use strict';

var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');

gulp.task('compile', function () {
    return gulp.src('assets/scss/main.scss')
        .pipe(sass())
        .pipe(concat('main.min.css'))
        .pipe(cleanCSS())
        .pipe(gulp.dest('public/css'));
});

gulp.task('watch', function () {
    gulp.watch('assets/scss/**/*.scss', gulp.series('compile'));
});

这是activity_main.xml:

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());
}
}

这是清单:

<?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">

<Textview
    android:id="@+id/tv_uids"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Mac Address" />

</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>

对不起,但我是应用程序的新手。我该怎么解决?

谢谢!

1 个答案:

答案 0 :(得分:2)

  

找不到以下类:-Textview(更改为   TextView,修复构建路径,编辑XML)

这意味着您的xml中有不正确的标记或无法识别的标记。您在activity_main.xml中有以下xml是不正确的:

<Textview
    android:id="@+id/tv_uids"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Mac Address" />

应该是:

<TextView
    android:id="@+id/tv_uids"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Mac Address" />

正确的标签是TextView而不是Textview