• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android Studio

Hello, I am new here. I hope someone knows anything on Android Studio and Java. I want to create an application for controlling a LED strip with Arduino. I want to make several buttons. but i cant figure out how to write it! If anyone knows please contact me!
 
Hello, i am new here and also new in android studio. i have some knowledge in java, c++ but it has some time since that. so i am trying to make an application in order to control a led strip via android. i found a project at instructables that it is very close to what i want to make. the problem is that this project is from 2015. i am trying to troubleshoot the code but i am not so good at it. now it shows me an error here:

Code:
error: illegal start of type

    if (myBluetooth == null){

    ^
any thoughts???? Thank you very much!




Code:
package com.example.devicelist;



import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ListView;



import java.io_OutputStream;

import java.util.Set;

import java.util.ArrayList;



import android.widget.Toast;

import android.widget.ArrayAdapter;

import android.widget.AdapterView;

import android.view.View.OnClickListener;

import android.widget.TextView;

import android.content.Intent;

import android.bluetooth.BluetoothAdapter;

import android.bluetooth.BluetoothDevice;







public class DeviceList extends AppCompatActivity implements OnClickListener {

    //widgets

    private Button btnPaired;

    private ListView devicelist;

    //bluetooth

    private BluetoothAdapter myBluetooth = null;

    private Set<BluetoothDevice> pairedDevices;

    private OutputStream outStream = null;

    public static String EXTRA_ADDRESS = "device_address";



    //if the device has bluetooth

    BluetoothAdapter myBluetooth = BluetoothAdapter.getDefaultAdapter();



    if (myBluetooth == null){

        //Show a mensag. that the device has no bluetooth adapter

        Toast.makeText(getApplicationContext(), "Bluetooth Device not Available", Toast.LENGTH_LONG).show();

        //finish apk

        finish();

    }

    else if (!myBluetooth.isEnabled()){

        //Ask the user to turn on the bluetooth

        Intent turnBTon = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

        startActivityForResult(turnBTon, 1);

    }
 
Last edited by a moderator:
I'm afraid I won't be able to help with your coding question but I wanted to let you know that I added some [code]...[/code] tags to your post to make the content a bit easier to parse.
 
Back
Top Bottom