Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android显示错误“;无法解析符号R";_Android - Fatal编程技术网

Android显示错误“;无法解析符号R";

Android显示错误“;无法解析符号R";,android,Android,在你把这个问题标记为重复问题之前,请知道我已经试过了 我的邮件中出现以下错误: Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources] :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:pre

在你把这个问题标记为重复问题之前,请知道我已经试过了

我的邮件中出现以下错误:

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources
D:\AndroidStudioProject\BlueAlert\app\src\main\res\layout\content_connected.xml
Error:(15, 21) No resource found that matches the given name (at 'id' with value '@id/screenimageView').
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\ANDROID\AndroidSDK\build-tools\23.0.2\aapt.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 5.214 secs
Information:2 errors
Information:0 warnings
Information:See complete output in console
这是我的MainActivity.java

package vertex2016.mvjce.edu.bluealert;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.*;

import java.util.UUID;

import static java.lang.Thread.sleep;

public class MainActivity extends AppCompatActivity {

    //To get the default Bluetooth adapter on the Android device
    public BluetoothAdapter BA = BluetoothAdapter.getDefaultAdapter();

    //A request code to identify which activity was executed
    private int REQ_CODE = 1;

    private boolean on = false;

    //The Search button on the main screen
    private Button searchButton;

    //The View that lists all the nearby Bluetooth devices found
    private ListView listBTDevices;

    //Display the welcome text
    private TextView BTDesc;

    //Store the recently found Bluetooth devices & pass them on to the ListView
    private ArrayAdapter BTArrayAdapter;

    //A variable that points to the actual Bluetooth on the device
    private BluetoothDevice btd;

    //UUID to specify the services it can provide


    //Intent Filter to detect the discovery of nearby Bluetooth devices
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //Lock the rotation of the screen
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

        searchButton = (Button) findViewById(R.id.searchButton);
        listBTDevices = (ListView) findViewById(R.id.listBTDevices);

        //Initially the ListView will be hidden, only after the Search button has been pressed,
        // the ListView will be visible
        listBTDevices.setVisibility(View.GONE);
        BTDesc = (TextView) findViewById(R.id.BTDesc);


        searchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!on) {
                    connect();

                } else if (on) {
                    stopDiscovery();
                    on = false;
                    searchButton.setText("Search");
                }

            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    //A method that checks if targeted device supports Bluetoth or not
    //In case it does, execute the SearchBTDevices method to search
    public void connect() {
        //Registering the IntentFilter
        this.registerReceiver(receiver, filter);

        //If the device doesn't have Bluetooth, the Bluetooth Adapter BA returns NULL
        if (BA == null)
            Toast.makeText(MainActivity.this, "System Doesn't Support Bluetooth", Toast.LENGTH_SHORT).show();

            //In case the device has Bluetooth, but Bluetooth isn't enabled
            //Enables the Bluetooth on the device
            //startActivityForResult() takes in the Intent & a REQUEST CODE to specifically identify that intent
        else if (!BA.isEnabled()) {
            Intent enableBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBT, REQ_CODE);
        }
        //In case Bluetooth is enabled on the device, start the discovery
        else {
            searchBTDevices();
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_CANCELED) {
            Toast.makeText(MainActivity.this, "TURNED ON!", Toast.LENGTH_SHORT).show();
            searchBTDevices();
        } else
            Toast.makeText(MainActivity.this, "FAILED TO ENABLE BLUETOOTH", Toast.LENGTH_LONG).show();
    }


    public void searchBTDevices() {
        //As soon as the search starts, the Welcome screen TextView disappears & ListView appears
        BTDesc.setVisibility(View.GONE);
        listBTDevices.setVisibility(View.VISIBLE);


        BTArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);


        //In case the discovery fails to begin
        if (!BA.startDiscovery())
            Toast.makeText(MainActivity.this, "Failed to start discovery", Toast.LENGTH_SHORT).show();

        else {
            Toast.makeText(MainActivity.this, "Discovery Started", Toast.LENGTH_SHORT).show();
            on = true;
            searchButton.setText("Stop Discovery");

        }

        listBTDevices.setAdapter(BTArrayAdapter);


        //Setting the onItemClick for selecting a Bluetooth device to connect to
        listBTDevices.setOnItemClickListener(clickListener);

    }


    private final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                btd = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); //Get the device details

                BTArrayAdapter.add(btd.getName() + "\t\t" + btd.getAddress());
            }

        }
    };

    private void stopDiscovery() {
        BA.cancelDiscovery();
        Toast.makeText(MainActivity.this, "Discovery Stopped", Toast.LENGTH_SHORT).show();
        this.unregisterReceiver(receiver);
    }

    @Override
    protected void onResume() {
        super.onResume();
        BA.cancelDiscovery();
        BA.startDiscovery();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        BTArrayAdapter.clear();
        Toast.makeText(MainActivity.this, "Discovery Resumed", Toast.LENGTH_SHORT).show();
    }

    public final AdapterView.OnItemClickListener clickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
            Intent connectedBT = new Intent(MainActivity.this, Connected.class);
            connectedBT.putExtra("Bluetooth Device", btd);
            startActivity(connectedBT);
        }
    };
}
包vertex2016.mvjce.edu.bluealert;
导入android.bluetooth.BluetoothAdapter;
导入android.bluetooth.bluetooth设备;
导入android.content.BroadcastReceiver;
导入android.content.Context;
导入android.content.Intent;
导入android.content.IntentFilter;
导入android.content.pm.ActivityInfo;
导入android.os.Bundle;
导入android.os.Handler;
导入android.support.design.widget.FloatingActionButton;
导入android.support.design.widget.Snackbar;
导入android.support.v7.app.AppActivity;
导入android.support.v7.widget.Toolbar;
导入android.view.Gravity;
导入android.view.view;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.widget.Button;
导入android.widget.ListView;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.*;
导入java.util.UUID;
导入静态java.lang.Thread.sleep;
公共类MainActivity扩展了AppCompatActivity{
//获取Android设备上的默认蓝牙适配器
公共BluetoothAdapter BA=BluetoothAdapter.getDefaultAdapter();
//用于标识已执行的活动的请求代码
专用int REQ_代码=1;
私有布尔on=false;
//主屏幕上的搜索按钮
私人按钮搜索按钮;
//列出附近找到的所有蓝牙设备的视图
私有ListView ListBT设备;
//显示欢迎文本
私有文本视图BTDesc;
//存储最近找到的蓝牙设备并将其传递到ListView
专用阵列适配器BTArrayAdapter;
//指向设备上实际蓝牙的变量
私人蓝牙设备;
//UUID指定它可以提供的服务
//意图过滤器,用于检测附近蓝牙设备的发现
IntentFilter筛选器=新的IntentFilter(BluetoothDevice.ACTION\u已找到);
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
设置支持操作栏(工具栏);
//锁定屏幕的旋转
设置请求方向(ActivityInfo.屏幕方向锁定);
searchButton=(按钮)findViewById(R.id.searchButton);
listBTDevices=(ListView)findViewById(R.id.listBTDevices);
//最初,只有在按下搜索按钮后,ListView才会隐藏,
//ListView将可见
listBTDevices.setVisibility(View.GONE);
BTDesc=(TextView)findViewById(R.id.BTDesc);
searchButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(!on){
connect();
}否则,如果(打开){
停止发现();
开=假;
searchButton.setText(“搜索”);
}
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单菜单菜单主菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
//一种检查目标设备是否支持Bluetoth的方法
//如果有,请执行SearchBTDevices方法进行搜索
公共void connect(){
//注册IntentFilter
此注册表接收程序(接收器、过滤器);
//如果设备没有蓝牙,蓝牙适配器BA将返回NULL
if(BA==null)
Toast.makeText(MainActivity.this,“系统不支持蓝牙”,Toast.LENGTH_SHORT.show();
//如果设备具有蓝牙功能,但未启用蓝牙功能
//在设备上启用蓝牙
//startActivityForResult()接受Intent&一个请求代码来专门标识该意图
如果(!BA.isEnabled()){
Intent enableBT=新意图(BluetoothAdapter.ACTION\u REQUEST\u ENABLE);
startActivityForResult(启用BT,请求代码);
}
//如果设备上已启用蓝牙,请启动查找
否则{
searchBTDevices();
}
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
if(resultCode!=结果\u已取消){
Toast.makeText(MainActivity.this,“打开!”,Toast.LENGTH_SHORT.show();
searchBTDevices();
}否则
Toast.makeText(MainActivity.this,“未能启用蓝牙”,Toast.LENGTH_LONG.show();
}
公共无效搜索设备(){
//搜索一开始,欢迎屏幕TextView就会消失,并显示ListView
BTDesc.setVisibility(View.GONE);
listBTDevices.setVisibility(View.VISIBLE);
BTArrayAdapter=newarrayadapter(这是android.R.layout.simple\u list\u item\u 1);
//以防发现失败
如果(!BA.startDiscovery())
Toast.makeText(MainActivity.this,“启动发现失败”,Toast.LENGTH_SHORT.show();
否则{
Toast.makeText(MainActivity.this,“发现已开始”,Toast.LENGTH\u SHORT.show())
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="vertex2016.mvjce.edu.bluealert.Connected"
    tools:showIn="@layout/activity_connected">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@id/screenimageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/screenimageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
android:id="@+id/screenimageView"
android:id="+@id/screenimageView"
android:id="@id/screenimageView"
<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"   
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />