Java 错误:(53,43)错误:找不到符号变量列
我是android studio的新手,正在学习开发android应用程序, 我有一个如上所述的错误,无法解决它。 任何形式的帮助都将不胜感激。 谢谢 我的ledControl.java代码如下Java 错误:(53,43)错误:找不到符号变量列,java,android,Java,Android,我是android studio的新手,正在学习开发android应用程序, 我有一个如上所述的错误,无法解决它。 任何形式的帮助都将不胜感激。 谢谢 我的ledControl.java代码如下 package com.led.led; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;
package com.led.led;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.AsyncTask;
import java.io.IOException;
import java.util.UUID;
public class ledControl extends ActionBarActivity {
Button btnOn, btnOff, btnDis;
SeekBar brightness;
TextView lumn;
String address = null;
private ProgressDialog progress;
BluetoothAdapter myBluetooth = null;
BluetoothSocket btSocket = null;
private boolean isBtConnected = false;
//SPP UUID. Look for it
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent newint = getIntent();
address = newint.getStringExtra(DeviceList.EXTRA_ADDRESS); //receive the address of the bluetooth device
//view of the ledControl
setContentView(R.layout.activity_led_control);
//call the widgtes
btnOn = (Button)findViewById(R.id.button2);
btnOff = (Button)findViewById(R.id.button3);
btnDis = (Button)findViewById(R.id.button4);
brightness = (SeekBar)findViewById(R.id.seekBar);
lumn = (TextView)findViewById(R.id.lumn);
new ConnectBT().execute(); //Call the class to connect
//commands to be sent to bluetooth
btnOn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
turnOnLed(); //method to turn on
}
});
btnOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
turnOffLed(); //method to turn off
}
});
btnDis.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Disconnect(); //close connection
}
});
brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser==true)
{
lumn.setText(String.valueOf(progress));
try
{
btSocket.getOutputStream().write(String.valueOf(progress).getBytes());
}
catch (IOException e)
{
}
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
private void Disconnect()
{
if (btSocket!=null) //If the btSocket is busy
{
try
{
btSocket.close(); //close connection
}
catch (IOException e)
{ msg("Error");}
}
finish(); //return to the first layout
}
private void turnOffLed()
{
if (btSocket!=null)
{
try
{
btSocket.getOutputStream().write("TF".toString().getBytes());
}
catch (IOException e)
{
msg("Error");
}
}
}
private void turnOnLed()
{
if (btSocket!=null)
{
try
{
btSocket.getOutputStream().write("TO".toString().getBytes());
}
catch (IOException e)
{
msg("Error");
}
}
}
// fast way to call Toast
private void msg(String s)
{
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}
@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_led_control, 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);
}
private class ConnectBT extends AsyncTask<Void, Void, Void> // UI thread
{
private boolean ConnectSuccess = true; //if it's here, it's almost connected
@Override
protected void onPreExecute()
{
progress = ProgressDialog.show(ledControl.this, "Connecting...", "Please wait!!!"); //show a progress dialog
}
@Override
protected Void doInBackground(Void... devices) //while the progress dialog is shown, the connection is done in background
{
try
{
if (btSocket == null || !isBtConnected)
{
myBluetooth = BluetoothAdapter.getDefaultAdapter();//get the mobile bluetooth device
BluetoothDevice dispositivo = myBluetooth.getRemoteDevice(address);//connects to the device's address and checks if it's available
btSocket = dispositivo.createInsecureRfcommSocketToServiceRecord(myUUID);//create a RFCOMM (SPP) connection
BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
btSocket.connect();//start connection
}
}
catch (IOException e)
{
ConnectSuccess = false;//if the try failed, you can check the exception here
}
return null;
}
@Override
protected void onPostExecute(Void result) //after the doInBackground, it checks if everything went fine
{
super.onPostExecute(result);
if (!ConnectSuccess)
{
msg("Connection Failed. Is it a SPP Bluetooth? Try again.");
finish();
}
else
{
msg("Connected.");
isBtConnected = true;
}
progress.dismiss();
}
}
}
package com.led.led;
导入android.support.v7.app.ActionBarActivity;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.bluetooth.BluetoothSocket;
导入android.content.Intent;
导入android.view.view;
导入android.widget.Button;
导入android.widget.SeekBar;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.app.ProgressDialog;
导入android.bluetooth.BluetoothAdapter;
导入android.bluetooth.bluetooth设备;
导入android.os.AsyncTask;
导入java.io.IOException;
导入java.util.UUID;
公共类ledControl扩展了ActionBarActivity{
按钮btnOn、btnOff、btnDis;
SeekBar亮度;
文本视图列;
字符串地址=空;
私人进展对话进展;
蓝牙适配器myBluetooth=null;
BluetoothSocket btSocket=null;
私有布尔值isBtConnected=false;
//SPP UUID,找它
静态最终UUID myUUID=UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”);
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent newint=getIntent();
address=newint.getStringExtra(DeviceList.EXTRA_address);//接收蓝牙设备的地址
//LED控制的视图
setContentView(R.layout.activity\u led\u控件);
//打电话给寡妇
btnOn=(按钮)findviewbyd(R.id.button2);
btnOff=(按钮)findViewById(R.id.button3);
btnDis=(按钮)findViewById(R.id.button4);
亮度=(SeekBar)findViewById(R.id.SeekBar);
lumn=(TextView)findViewById(R.id.lumn);
new ConnectBT().execute();//调用类进行连接
//要发送到蓝牙的命令
btnOn.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
turnOnLed();//要启用的方法
}
});
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v)
{
turnOffLed();//要关闭的方法
}
});
btnDis.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
Disconnect();//关闭连接
}
});
亮度.setOnSeekbarchaneListener(新的SeekBar.onSeekbarchaneListener(){
@凌驾
public void onProgressChanged(SeekBar-SeekBar、int-progress、boolean-fromUser){
if(fromUser==true)
{
column.setText(String.valueOf(progress));
尝试
{
btSocket.getOutputStream().write(String.valueOf(progress.getBytes());
}
捕获(IOE异常)
{
}
}
}
@凌驾
开始跟踪触摸时的公共无效(SeekBar SeekBar){
}
@凌驾
TopTrackingTouch(SeekBar SeekBar)上的公共无效{
}
});
}
私有无效断开连接()
{
if(btSocket!=null)//如果btSocket正忙
{
尝试
{
btSocket.close();//关闭连接
}
捕获(IOE异常)
{msg(“错误”);}
}
finish();//返回到第一个布局
}
私家车空置道岔()
{
if(btSocket!=null)
{
尝试
{
btSocket.getOutputStream().write(“TF.toString().getBytes());
}
捕获(IOE异常)
{
msg(“错误”);
}
}
}
私人空房
{
if(btSocket!=null)
{
尝试
{
btSocket.getOutputStream().write(“TO”.toString().getBytes());
}
捕获(IOE异常)
{
msg(“错误”);
}
}
}
//叫吐司的快速方法
私有void消息(字符串s)
{
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG.show();
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.menu\u led\u控件,菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
私有类ConnectBT扩展异步任务//UI线程
{
private boolean ConnectSuccess=true;//如果它在这里,它几乎是连接的
@凌驾
受保护的void onPreExecute()
{
progress=ProgressDialog.show(ledControl.this,“正在连接…”,“请稍候!!!”;//显示进度对话框
}
@凌驾
受保护的Void doInBackground(Void…devices)//显示进度对话框时,连接在后台完成
{
尝试
{
if(btSocket==null | |!isBtConnected)
{
myBluetooth=蓝牙
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.led.led.ledControl">
<TextView android:text="LED Control" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview2" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brightness"
android:id="@+id/textView3"
android:layout_above="@+id/seekBar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ON"
android:id="@+id/button2"
android:layout_above="@+id/button3"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OFF"
android:id="@+id/button3"
android:layout_above="@+id/button4"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Disconnect"
android:id="@+id/button4"
android:layout_above="@+id/textView3"
android:layout_alignLeft="@+id/button3"
android:layout_alignStart="@+id/button3" />
</RelativeLayout>
lumn = (TextView)findViewById(R.id.lumn);