snowpigppp 2017-04-04 04:17 采纳率: 50%
浏览 1539
已结题

从Github上下载的android蓝牙代码,显示外部无法调用非公共

https://github.com/pkarira/Androble
这个是代码链接
我用的是他提供的参考MainActivity
具体代码是

package com.example.snowpig.myble;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import com.mdg.androble.BluetoothActivity;
import com.mdg.androble.BluetoothManager;
import com.mdg.androble.DeviceList;
import java.util.Observable;
import java.util.Observer;

public class MainActivity extends BluetoothActivity {


    BluetoothManager bluetoothManager;
    receiveMassage rm;
    DeviceList dl;
    String type="";
    ListView listview;
    int c=0;
    EditText et1;
    EditText et2;
    private ArrayAdapter adapter;


    @Override
    protected void onCreate(Bundle saveInstanceState){
        super.onCreate(saveInstanceState);
        setContentView(R.layout.activity_main);
        bluetoothManager=BluetoothManager.getInstance();
        rm=new receiveMassage();
        dl=new DeviceList();
        listview=(ListView)findViewById(R.id.select_dialog_listview);
        et1=(EditText)findViewById(R.id.text);
        et2=(EditText)findViewById(R.id.text2);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
                    public void onItemClick(AdapterView<?>parent, View view,int position,long id){
                String itemValue=(String) listview.getItemAtPosition(position);
                bluetoothManager.connectTo(itemValue);
            }
        });
        adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1);
        listview.setAdapter(adapter);
    }


    public void client(View v) {
    type = "CLIENT";
    bluetoothManager.Type(type);
    }

    public void server(View v){
        type="SERVER";
        bluetoothManager.Type(type);
    }

    public void start(View v){
        bluetoothManager.setMessageObject(rm);
        bluetoothManager.setListObject(dl);
        if (type.equals("CLIENT")){
            enableBluetooth();
        }
        if (type.equals("SERVER")){
            enableBluetooth();
        }
    }

    public void clienttoclient(View v){
        bluetoothManager.clientToClient(et1.getText().toString(),Integer.parseInt(et2.getText().toString()));
    }

    public void devicelist(View v){
        if(type.equals("SERVER"))
            Toast.makeText(getApplicationContext(), bluetoothManager.getAllConnectedDevices(), Toast.LENGTH_LONG).show();
        else
            bluetoothManager.getAllConnectedDevices();
    }

    public void send(View v){
        if(type.equals("CLIENT")){
            bluetoothManager.sendText(et1.getText().toString());
        }
        if (type.equals("SERVER")){
            bluetoothManager.sendText(et1.getText().toString(),Integer.parseInt(et2.getText().toString()));
        }
    }

    public void disconnect(View v){
        Toast.makeText(getApplicationContext(),bluetoothManager.disconnect(),Toast.LENGTH_LONG).show();
    }

    class receiveMassage implements Observer{

        @Override
         public void update(Observable observable,Object data){
            final String msg=((receivemsg)observable).getMessage();
             runOnUiThread(new Runnable(){
                 public void run(){
                    Toast.makeText(MainActivity.this,msg,Toast.LENGTH_LONG).show();
                 }
             });
        }
    }

    class DeviceList implements Observer{
    @Override
        public void update(Observable observable,Object data){
            if(((com.mdg.androble.DeviceList)observable).getContent().equals("bluetooth enabled")){
                bluetoothManager.scanClients();
            }
            else
                adapter.add(((com.mdg.androble.DeviceList)observable).getContent());
        }

    }
}


报错的内容是
1、类MainActivity
没有变量bm
——改为bluetoothManager出现新错误:unhandled exception:java.io.IOException

2、类MainActivity.receiveMassage
没有类receivemsg

3&5、getContent()在DeviceList中不是公共的

4、scanClients()在BluetoothManager中不是公共的

  • 写回答

1条回答 默认 最新

  • bambi2017 2017-04-04 05:53
    关注

    你下载其他源码试试。

    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多