Android 台灣中文網
標題:
我不知道哪裡出錯了
[打印本頁]
作者:
st904100
時間:
2016-5-8 17:11
標題:
我不知道哪裡出錯了
package
com.example.easyledout
;
import
java.io.BufferedOutputStream
;
import
java.io.IOException
;
import
java.math.BigInteger
;
import
java.util.UUID
;
import
android.bluetooth.BluetoothAdapter
;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothSocket
;
import
android.content.Intent
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.Toast
;
public class
EasyLedOut
extends
AppCompatActivity {
private
BluetoothSocket
socket8051
;
private
BufferedOutputStream
out8051
;
private int
outNum
;
private
Button
end
,
Sendout
;
private
EditText
editOutNum
;
byte
[]
array_51
;
private final
UUID
UID8051
=UUID.
fromString
(
"00001101-0000-1000-8000-00805F9B34FB"
)
;
private static final int
REQUEST_ENABLE_BLUETOOTH
=
2
;
private
BluetoothAdapter
bluetoothApapter
;
@Override
protected void
onCreate
(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState)
;
setContentView(R.layout.
easy_led_out
)
;
findId()
;
bluetoothApapter
=BluetoothAdapter.
getDefaultAdapter
()
;
if
(
bluetoothApapter
==
null
){
Toast.
makeText
(EasyLedOut.
this,
"不支援Bluetooth"
,
Toast.
LENGTH_LONG
).show()
;
finish()
;
}
else if
(!
bluetoothApapter
.isEnabled()){
Intent it=
new
Intent(BluetoothAdapter.
ACTION_REQUEST_ENABLE
)
;
startActivityForResult(it
,
REQUEST_ENABLE_BLUETOOTH
)
;
}
BluetoothDevice device=
bluetoothApapter
.getRemoteDevice(
"00:11:12:06:00:26"
)
;
try
{
socket8051
=device.createRfcommSocketToServiceRecord(
UID8051
)
;
socket8051
.connect()
;
out8051
=
new
BufferedOutputStream(
socket8051
.getOutputStream())
;
array_51
= BigInteger.
valueOf
(
512
+
127
).toByteArray()
;
out8051
.write(
array_51
)
;
out8051
.flush()
;
}
catch
(IOException e){
}
Sendout
.setOnClickListener(
new
View.OnClickListener() {
@Override
public void
onClick
(View v) {
outNum
=Integer.
parseInt
(
editOutNum
.getText().toString())
;
array_51
= BigInteger.
valueOf
(
512
+
outNum
).toByteArray()
;
try
{
out8051
.write(
array_51
)
;
out8051
.flush()
;
}
catch
(IOException e){
e.printStackTrace()
;
}
}
})
;
end
.setOnClickListener(
new
View.OnClickListener() {
@Override
public void
onClick
(View v) {
if
(
socket8051
!=
null
)
{
try
{
out8051
.close()
;
socket8051
.close()
;
android.os.Process.
killProcess
(android.os.Process.
myPid
())
;
}
catch
(IOException e){
e.printStackTrace()
;
android.os.Process.
killProcess
(android.os.Process.
myPid
())
;
}
}
else
{Toast.
makeText
(EasyLedOut.
this,
"還沒有連接成功"
,
Toast.
LENGTH_SHORT
).show()
;
android.os.Process.
killProcess
(android.os.Process.
myPid
())
;
}
})
;
}
}
private void
findId
() {
Sendout
=(Button)findViewById(R.id.
sendout
)
;
end
=(Button)findViewById(R.id.
end
)
;
editOutNum
=(EditText)findViewById(R.id.
editoutnum
)
;
}
這是我的程式碼但是我依照除錯視窗去檢查感覺不出來哪裡錯可以請各位幫我看一下嗎?
作者:
st904100
時間:
2016-5-8 17:13
補上圖
圖上面有蚯蚓的地方就是程式說錯誤的地方
但是每個)、}都有對應到...
所以不懂錯在哪
登錄/註冊後可看大圖
作者:
ploglin
時間:
2016-5-8 21:19
看你的錯誤有語法錯誤,也有結構錯誤,你有寫過 JAVA 嗎?
作者:
st904100
時間:
2016-5-9 15:05
沒有 我是新手
但是這是照課本寫的QQ
不過誤打誤撞問題解決了XD
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1