2017-06-23 5 views
0

を解決できません。今、私はそれで終わりだが、私は次の記号R私は、しばらくの間、このブルートゥースデータ転送プロジェクトに取り組んできました

Error:(41, 35) No resource found that matches the given name (at 'layout_toRightOf' with value '@id/edttxt').

ある別のエラーにこの迷惑なエラーノンストップを取得しておきます

問題はどこですか?

活動の主

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:background="@drawable/mybg" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.cy.el.bluetoothtransfer.MainActivity"> 

<Button 
    android:text="ON/OFF" 
    android:layout_width="100dp" 
    android:layout_height="50dp" 
    android:layout_alignParentTop="true" 
    android:background="@drawable/selector2" 
    android:layout_alignParentRight="true" 
    android:id="@+id/btnONOFF"/> 

<Button 
    android:text="Enable Discoverable" 
    android:layout_width="189dp" 
    android:layout_height="50dp" 
    android:background="@drawable/selector" 
    android:id="@+id/btnDiscoverable_on_off" 
    android:onClick="btnEnableDisable_Discoverable" 
    android:layout_alignParentTop="true" /> 

<Button 
    android:layout_width="95dp" 
    android:layout_height="50dp" 
    android:id="@+id/btnFindUnpairedDevices" 
    android:text="Discover" 
    android:layout_toRightOf="@id/edttxt" 
    android:layout_marginLeft="50dp" 
    android:layout_above="@id/edttxt" 
    android:layout_marginTop="40dp" 
    android:background="@drawable/selector" 
    android:onClick="btnDiscover"/> 

<ListView 
    android:layout_marginTop="120dp" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:id="@+id/lvNewDevices"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/lvNewDevices" 
    android:layout_marginTop="30dp" 
    android:layout_alignParentLeft="true" 
    android:textSize="20dp" 
    android:layout_marginLeft="30dp" 
    android:textColor="#fffffe" 
    android:id="@+id/information" /> 

<EditText 
    android:layout_width="200dp" 
    android:layout_height="100dp" 
    android:layout_below="@id/information" 
    android:hint="   Type here : " 
    android:textColor="#fffffe" 
    android:background="#fafafa" 
    android:layout_marginTop="50dp" 
    android:id="@+id/edttxt"/> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/information" 
    android:layout_toRightOf="@id/edttxt" 
    android:text="Send" 
    android:background="@drawable/selector2" 
    android:layout_marginTop="50dp" 
    android:layout_marginLeft="50dp" 
    android:id="@+id/sendBtn"/> 

<Button 
    android:text="Start Connection" 
    android:id="@+id/btnstartConnection" 
    android:layout_width="189dp" 
    android:layout_height="50dp" 
    android:layout_below="@id/btnDiscoverable_on_off" 
    android:background="@drawable/selector"/> 


</RelativeLayout> 

MainActivity

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{ 

BluetoothConnection myBluetoothConnection ; 
private static final UUID myUUID = UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66"); 
BluetoothDevice myBluetoothDevice ; 

TextView informations ; 
BluetoothAdapter mBluetoothAdapter; 
Button btnEnableDisable_Discoverable; 
EditText edt ; 
Button btnSend ; 
Button btnstartconnection ; 

public ArrayList<BluetoothDevice> mBTDevices = new ArrayList<>(); 

public deviceList mDeviceListAdapter; 

ListView lvNewDevices; 


// Create a BroadcastReceiver for ACTION_FOUND 
private final BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() { 
    public void onReceive(Context context, Intent intent) { 
     String action = intent.getAction(); 
     // When discovery finds a device 
     if (action.equals(mBluetoothAdapter.ACTION_STATE_CHANGED)) { 
      final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, mBluetoothAdapter.ERROR); 

      switch(state){ 
       case BluetoothAdapter.STATE_OFF: 


        break; 
       case BluetoothAdapter.STATE_TURNING_OFF: 
        Toast.makeText(getApplicationContext(), " Turning Off ", Toast.LENGTH_SHORT).show(); 

        break; 
       case BluetoothAdapter.STATE_ON: 


        break; 
       case BluetoothAdapter.STATE_TURNING_ON: 
        Toast.makeText(getApplicationContext(), " Turning On ", Toast.LENGTH_SHORT).show(); 
        break; 
      } 
     } 
    } 
}; 

/** 
* Broadcast Receiver for changes made to bluetooth states such as: 
* 1) Discoverability mode on/off or expire. 
*/ 
private final BroadcastReceiver mBroadcastReceiver2 = new BroadcastReceiver() { 

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

     if (action.equals(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED)) { 

      int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.ERROR); 

      switch (mode) { 
       //Device is in Discoverable Mode 
       case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE: 


        break; 
       //Device not in discoverable mode 
       case BluetoothAdapter.SCAN_MODE_CONNECTABLE: 


        break; 
       case BluetoothAdapter.SCAN_MODE_NONE: 

        break; 
       case BluetoothAdapter.STATE_CONNECTING: 
        Toast.makeText(getApplicationContext(), " Connecting... ", Toast.LENGTH_SHORT).show(); 

        break; 
       case BluetoothAdapter.STATE_CONNECTED: 
        Toast.makeText(getApplicationContext(), " Connected ", Toast.LENGTH_SHORT).show(); 

        break; 
      } 

     } 
    } 
}; 




/** 
* Broadcast Receiver for listing devices that are not yet paired 
* -Executed by btnDiscover() method. 
*/ 
private BroadcastReceiver mBroadcastReceiver3 = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     final String action = intent.getAction(); 

     if (action.equals(BluetoothDevice.ACTION_FOUND)){ 
      BluetoothDevice device = intent.getParcelableExtra (BluetoothDevice.EXTRA_DEVICE); 
      mBTDevices.add(device); 

      informations.setText(device.getName() + " : " + device.getAddress()); 

      mDeviceListAdapter = new deviceList(context, R.layout.devicelistview, mBTDevices); 
      lvNewDevices.setAdapter(mDeviceListAdapter); 
     } 
    } 
}; 

/** 
* Broadcast Receiver that detects bond state changes (Pairing status changes) 
*/ 
private final BroadcastReceiver mBroadcastReceiver4 = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     final String action = intent.getAction(); 

     if(action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)){ 
      BluetoothDevice mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
      //3 cases: 
      //case1: bonded already 
      if (mDevice.getBondState() == BluetoothDevice.BOND_BONDED){ 
       Toast.makeText(getApplicationContext(), " Bonded ", Toast.LENGTH_SHORT).show(); 



       myBluetoothDevice = mDevice ; 





      } 
      //case2: creating a bone 
      if (mDevice.getBondState() == BluetoothDevice.BOND_BONDING) { 
       Toast.makeText(getApplicationContext(), " Bonding ", Toast.LENGTH_SHORT).show(); 
      } 
      //case3: breaking a bond 
      if (mDevice.getBondState() == BluetoothDevice.BOND_NONE) { 
       Toast.makeText(getApplicationContext(), " Not Bonded ", Toast.LENGTH_SHORT).show();    } 
     } 
    } 
}; 



@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    unregisterReceiver(mBroadcastReceiver1); 
    unregisterReceiver(mBroadcastReceiver2); 
    unregisterReceiver(mBroadcastReceiver3); 
    unregisterReceiver(mBroadcastReceiver4); 
    //mBluetoothAdapter.cancelDiscovery(); 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button btnONOFF = (Button) findViewById(R.id.btnONOFF); 
    btnSend = (Button) findViewById(R.id.sendBtn); 
    edt = (EditText) findViewById(R.id.edt); 
    btnstartconnection= (Button) findViewById(R.id.btnstartConnection); 
    informations = (TextView) findViewById(R.id.information); 
    btnEnableDisable_Discoverable = (Button) findViewById(R.id.btnDiscoverable_on_off); 
    lvNewDevices = (ListView) findViewById(R.id.lvNewDevices); 
    mBTDevices = new ArrayList<>(); 


    //Broadcasts when bond state changes (ie:pairing) 
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED); 
    registerReceiver(mBroadcastReceiver4, filter); 

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 

    lvNewDevices.setOnItemClickListener(MainActivity.this); 


    btnONOFF.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      enableDisableBT(); 
     } 
    }); 





    btnstartconnection.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 

      startConnection(); 

     } 
    }); 



    btnSend.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 

      byte [] bytes = edt.getText().toString().getBytes(Charset.defaultCharset()); 
      myBluetoothConnection.write(bytes); 


     } 
    }); 





} 


public void startConnection(){ 

    StartBluetoothConnetion(myBluetoothDevice,myUUID); 

} 















public void StartBluetoothConnetion(BluetoothDevice device , UUID myUUID){ 



    myBluetoothConnection.startClient(device,myUUID); 


} 
















public void enableDisableBT(){ 
    if(mBluetoothAdapter == null){ 

    } 
    if(!mBluetoothAdapter.isEnabled()){ 
     Toast.makeText(getApplicationContext(), " Enabling Bluetooth ", Toast.LENGTH_SHORT).show(); 
     Intent enableBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
     startActivity(enableBTIntent); 


     IntentFilter BTIntent = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); 
     registerReceiver(mBroadcastReceiver1, BTIntent); 
    } 
    if(mBluetoothAdapter.isEnabled()){ 
     Toast.makeText(getApplicationContext(), " Disabling Bluetooth ", Toast.LENGTH_SHORT).show(); 
     mBluetoothAdapter.disable(); 

     IntentFilter BTIntent = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); 
     registerReceiver(mBroadcastReceiver1, BTIntent); 
    } 

} 


public void btnEnableDisable_Discoverable(View view) { 


    Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); 
    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); 
    startActivity(discoverableIntent); 

    IntentFilter intentFilter = new IntentFilter(mBluetoothAdapter.ACTION_SCAN_MODE_CHANGED); 
    registerReceiver(mBroadcastReceiver2,intentFilter); 

} 

public void btnDiscover(View view) { 
    Toast.makeText(getApplicationContext(), " Searching... ", Toast.LENGTH_SHORT).show(); 

    if(mBluetoothAdapter.isDiscovering()){ 
     mBluetoothAdapter.cancelDiscovery(); 


     //check BT permissions in manifest 


     mBluetoothAdapter.startDiscovery(); 
     IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
     registerReceiver(mBroadcastReceiver3, discoverDevicesIntent); 
    } 
    if(!mBluetoothAdapter.isDiscovering()){ 

     //check BT permissions in manifest 


     mBluetoothAdapter.startDiscovery(); 
     IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
     registerReceiver(mBroadcastReceiver3, discoverDevicesIntent); 
    } 
} 

@Override 
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { 
    //first cancel discovery because its very memory intensive. 
    mBluetoothAdapter.cancelDiscovery(); 


    String deviceName = mBTDevices.get(i).getName(); 
    String deviceAddress = mBTDevices.get(i).getAddress(); 

    informations.setText(deviceName); 
    informations.setText(deviceAddress); 

    //create the bond. 
    //NOTE: Requires API 17+? I think this is JellyBean 
    if(Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2){ 
     Toast.makeText(getApplicationContext(), " Paring with " + deviceName, Toast.LENGTH_SHORT).show(); 
     mBTDevices.get(i).createBond(); 

     myBluetoothDevice = mBTDevices.get(i); 
     myBluetoothConnection = new BluetoothConnection(MainActivity.this); 
    } 
}} 

Mainfest

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.cy.el.bluetoothtransfer"> 
<uses-permission android:name="android.permission.BLUETOOTH" /> 
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name="com.cy.el.bluetoothtransfer.MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

+1

これは、RelativeLayoutsの仕組みを研究していないためです。 'edttxt'はまだ定義されていません。レイアウトの後半で定義されています。 EditTextの後にボタンの定義を移動するか、この(恐ろしい)構文を使用します: 'android:layout_above =" @ + id/edttxt "'(** + **記号に注意してください)。しかし、***対応策***です。 –

答えて

0

ないリソースはそれがVALUで( 'layout_toRightOf' で指定された名前と一致しましたe '@ id/edttxt')。 「そう

が問題でからなので、私はあなたのレイアウトに注意約3エラーがあります

0

任意のクエリの場合、私に尋ねるandroid:layout_toRightOf="@+id/edttxt"を使用またはIDた編集テキストとコントロールを定義するが、そのID のない制御をbrecuseありません。レイアウト

最初は、そのボタンのIDを持つボタンで

アンドロイド:ID = "@ + ID/btnFindUnpairedDevices"、

あなたが持っているlayout_toRightOfと同じ値にlayout_aboveセットID @/edttxt

すなわち、第二は、あなただけのIDリレーショナルレイアウトの子または兄弟関係を持っている場合ということです属性は、'+'シンボルを取りますが、あなたのレイアウト

ID = "@ + idを持つのTextView layout_below = "@ + ID/lvNewDevices":/情報は

アンドロイドを持っています。

これらを修正すると問題が解決するはずです。

関連する問題