綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 我不知道哪裡出錯了

[複製連結] 查看: 1183|回覆: 3|好評: 0
跳轉到指定樓層
樓主
st904100 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2016-5-8 17:11

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
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);
    }



這是我的程式碼但是我依照除錯視窗去檢查感覺不出來哪裡錯可以請各位幫我看一下嗎?

「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
 樓主| st904100 | 收聽TA | 只看該作者
發表於 2016-5-8 17:13
補上圖

圖上面有蚯蚓的地方就是程式說錯誤的地方
但是每個)、}都有對應到...
所以不懂錯在哪
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
ploglin | 收聽TA | 只看該作者
發表於 2016-5-8 21:19
看你的錯誤有語法錯誤,也有結構錯誤,你有寫過 JAVA 嗎?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
 樓主| st904100 | 收聽TA | 只看該作者
發表於 2016-5-9 15:05
沒有  我是新手
但是這是照課本寫的QQ

不過誤打誤撞問題解決了XD
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則