2016-06-28 41 views
0

この質問に重複して記載する前に、thisthisを試したことをご理解ください。Androidのエラーが「シンボルRを解決できません」

私は私のメッセージで、次のエラーを取得しています:これは私の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); 
     } 
    }; 
} 

ある

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 

そして、これは私の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> 

私はプロジェクトを掃除しようとしましたが、それを再構築して、&をgradleと同期させました。そのうちのどれもうまくいかなかった...

助けてください。あなたの時間をありがとう!

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

新しいビューを定義している、それはのIDは次のようになります。あなたはこれにあなたのImageViewのコードを変更して "+"、試すには@ + ID/screenimageView

+1

アンドロイド使用してみてください:IDを=」 @ + id/screenimageView " –

+1

あなたのエラーは次のとおりです:エラー:(15、21)指定された名前(値 '@ id/screenimageView'の 'id')に一致するリソースは見つかりませんでした。これは、IDが何であるかを知らないことを意味します。これは、@ id /がプリコンパイルされたIDに使用され、@ + idがコンパイル時に生成される新しいIDであるためです。もし私が正確に覚えていれば。 – JoxTraex

+0

最初にエラーメッセージをお読みください。 –

答えて

3

android:id="@+id/screenimageView" 

をしていないこの::次のように定義された

android:id="[email protected]/screenimageView" 

またはこの:あなたはあなたのImageViewのウィジェットへの参照を作成している意味+記号を、指定していない

android:id="@id/screenimageView" 
0

を見逃している

+0

答えを確認するには、android:id = "@ + id/screenmageView "notroid:id =" + @ id/screenimageView " – mdDroid

+0

@mdDroidを指摘してくれてありがとう、それはタイプミスでした! –

0
<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" /> 

関連する問題