Android shows error "Cannot resolve symbol R" -
before mark question duplicate, please know have tried this , this.
i getting following error in messages:
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 matches given name (at 'id' value '@id/screenimageview'). error:execution failed 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 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
this 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 default bluetooth adapter on android device public bluetoothadapter ba = bluetoothadapter.getdefaultadapter(); //a request code identify activity executed private int req_code = 1; private boolean on = false; //the search button on main screen private button searchbutton; //the view lists nearby bluetooth devices found private listview listbtdevices; //display welcome text private textview btdesc; //store found bluetooth devices & pass them on listview private arrayadapter btarrayadapter; //a variable points actual bluetooth on device private bluetoothdevice btd; //uuid specify services can provide //intent filter detect 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 rotation of screen setrequestedorientation(activityinfo.screen_orientation_locked); searchbutton = (button) findviewbyid(r.id.searchbutton); listbtdevices = (listview) findviewbyid(r.id.listbtdevices); //initially listview hidden, after search button has been pressed, // listview 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 menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify 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 checks if targeted device supports bluetoth or not //in case does, execute searchbtdevices method search public void connect() { //registering intentfilter this.registerreceiver(receiver, filter); //if device doesn't have bluetooth, bluetooth adapter ba returns null if (ba == null) toast.maketext(mainactivity.this, "system doesn't support bluetooth", toast.length_short).show(); //in case device has bluetooth, bluetooth isn't enabled //enables bluetooth on device //startactivityforresult() takes in intent & request code identify intent else if (!ba.isenabled()) { intent enablebt = new intent(bluetoothadapter.action_request_enable); startactivityforresult(enablebt, req_code); } //in case bluetooth enabled on device, start 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 enable bluetooth", toast.length_long).show(); } public void searchbtdevices() { //as search starts, 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 discovery fails begin if (!ba.startdiscovery()) toast.maketext(mainactivity.this, "failed 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 onitemclick selecting bluetooth device connect 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 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); } }; }
and content_connected.xml
<?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>
i tried cleaning project, rebuilding & syncing gradle. none of worked...
please help. thank time!!
you've missed "+", try @+id/screenimageview
Comments
Post a Comment