Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java E/MoreInfoHPW_视图组﹕ 父视图不是文本视图_Java_Android_Bluetooth - Fatal编程技术网

Java E/MoreInfoHPW_视图组﹕ 父视图不是文本视图

Java E/MoreInfoHPW_视图组﹕ 父视图不是文本视图,java,android,bluetooth,Java,Android,Bluetooth,我正在android 4.1.1平板电脑上开发一个应用程序,但Galaxy S4和S4mini没有。错误正在吸引我: E/MoreInfoHPW_视图组:父视图不是文本视图 留下代码的方式,看看是否有人可以帮助我,因为我找不到解决办法 主要活动: 设置活动: 感谢您抽出时间根据您的描述,问题似乎在于设置活动扩展了主活动。当MainActivity本身启动时,onCreate方法调用checkBTState,当btAdapter未启用时,它将启动SettingsActivity。当Settings

我正在android 4.1.1平板电脑上开发一个应用程序,但Galaxy S4和S4mini没有。错误正在吸引我:

E/MoreInfoHPW_视图组:父视图不是文本视图

留下代码的方式,看看是否有人可以帮助我,因为我找不到解决办法

主要活动:

设置活动:


感谢您抽出时间

根据您的描述,问题似乎在于设置活动扩展了主活动。当MainActivity本身启动时,onCreate方法调用checkBTState,当btAdapter未启用时,它将启动SettingsActivity。当SettingsActivity启动时,它的onCreate方法调用super.onCreate,这是MainActivity的onCreate,它再次调用checkBTState,它启动SettingsActivity,它调用super.onCreate,它调用checkBTState,等等

SettingsActivity似乎不需要是MainActivity子类,因此解决方案是只更改extends子句:


你能提供一个更全面的stacktrace吗?行号会有帮助。谢谢哪一行给了你这个消息?如果它没有导致崩溃,忽略它。这是Samsungs.01-05 18:13:12.806 3834-3834/com.dydsistemas.demoler.espejorgb D/AbsListView上的常见错误﹕ 获取运动识别管理器01-05 18:13:12.836 3834-3834/com.dydsistemas.demoler.espejorgb E/MoreInfoHPW_视图组﹕ 父视图不是TextView这是一个递归错误,并且不断出现,应用程序从未启动
package com.dydsistemas.demoler.espejorgb;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;

import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.graphics.Color;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;


public class MainActivity extends Activity {

    private ColorPicker colorPicker;
    private Button button;
    private TextView tvRGB;
    protected static final int REQUEST_CODE = 10;
    private String resultMac;

    //SECCION DECLARACIONES BLUETOOTH
    Handler bluetoothIn;

    final int handlerState = 0;                      //used to identify handler message
    private BluetoothAdapter btAdapter = null;
    private BluetoothSocket btSocket = null;
    private StringBuilder recDataString = new StringBuilder();

    private ConnectedThread mConnectedThread;

    // SPP UUID service - this should work for most devices
    private static final UUID BTMODULEUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tvRGB = (TextView) findViewById(R.id.tvRGB);

        colorPicker = (ColorPicker) findViewById(R.id.colorPicker);
        colorPicker.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int color = colorPicker.getColor();
                String rgbString = "R: " + Color.red(color) + " B: " + Color.blue(color) + " G: " + Color.green(color);
                String RGB;
                RGB = Color.red(color) + "," + Color.blue(color) + "," + Color.green(color);
                tvRGB.setText(RGB);
            }
        });

        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                int color = colorPicker.getColor();
                String rgbString = "R: " + Color.red(color) + " B: " + Color.blue(color) + " G: " + Color.green(color);
                String RGB;
                RGB = Color.red(color) + "," + Color.blue(color) + "," + Color.green(color);
                try
                {
                    mConnectedThread.write(RGB);    // Send RGB via Bluetooth
                    tvRGB.setText(RGB);
//                    Toast.makeText(MainActivity.this, rgbString, Toast.LENGTH_SHORT).show();
                }
                catch (Exception e)
                {
///                    Toast.makeText(getBaseContext(), "Error el enviar el comando. No esta conectado el Espejo", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent(MainActivity.this, SettingActivity.class);
                    startActivityForResult(intent, REQUEST_CODE);
                }

            }
        });
        //SECCION BLUETOOTH
        btAdapter = BluetoothAdapter.getDefaultAdapter();       // get Bluetooth adapter
        checkBTState();
    }

/* FUNCIONA
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        colorPicker = (ColorPicker) findViewById(R.id.colorPicker);

        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                int color = colorPicker.getColor();
                String rgbString = "R: " + Color.red(color) + " B: " + Color.blue(color) + " G: " + Color.green(color);
                String RGB;
                RGB = Color.red(color) + "," + Color.blue(color) + "," + Color.green(color);
                mConnectedThread.write(RGB);    // Send RGB via Bluetooth

                Toast.makeText(MainActivity.this, rgbString, Toast.LENGTH_SHORT).show();

            }
        });
        //SECCION BLUETOOTH
        btAdapter = BluetoothAdapter.getDefaultAdapter();       // get Bluetooth adapter
        checkBTState();
    }
*/
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE) {
            // cogemos el valor devuelto por la otra actividad
            if (data.getDataString()!=null) {
                resultMac = data.getDataString();
                // enseñamos al usuario el resultado
//                Toast.makeText(this, "SettingActivity devolvió: " + resultMac, Toast.LENGTH_LONG).show();

                //create device and set the MAC address
                BluetoothDevice device = btAdapter.getRemoteDevice(resultMac);

                try {
                    btSocket = createBluetoothSocket(device);
                } catch (IOException e) {
//                    Toast.makeText(getBaseContext(), "Socket creation failed", Toast.LENGTH_LONG).show();
                }
                // Establish the Bluetooth socket connection.
                try {
                    btSocket.connect();
                    //prueba
                    mConnectedThread = new ConnectedThread(btSocket);
                    mConnectedThread.start();

                    //I send a character when resuming.beginning transmission to check device is connected
                    //If it is not an exception will be thrown in the write method and finish() will be called
                    mConnectedThread.write("128,128,128");
                } catch (IOException e) {
                    try {
                        btSocket.close();
                    } catch (IOException e2) {
                        //insert code to deal with this
//                        Toast.makeText(getBaseContext(), "No se encontró Espejo RGB. ", Toast.LENGTH_LONG).show();
                    }
                }
                /*mConnectedThread = new ConnectedThread(btSocket);
                mConnectedThread.start();

                //I send a character when resuming.beginning transmission to check device is connected
                //If it is not an exception will be thrown in the write method and finish() will be called
                mConnectedThread.write("128,128,128");
                */
            }
        }
    }

    private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {

        return  device.createRfcommSocketToServiceRecord(BTMODULEUUID);
        //creates secure outgoing connecetion with BT device using UUID
    }


/*
    @Override
    public void onPause()
    {
        super.onPause();
        try
        {
            //Don't leave Bluetooth sockets open when leaving activity
            btSocket.close();
        } catch (IOException e2) {
            //insert code to deal with this
        }
    }
*/
    //Checks that the Android device Bluetooth is available and prompts to be turned on if off
    private void checkBTState() {

        if(btAdapter==null) {
//            Toast.makeText(getBaseContext(), "Device does not support bluetooth", Toast.LENGTH_LONG).show();
        } else {
            if (btAdapter.isEnabled()) {
            } else {
                Intent intent = new Intent(MainActivity.this, SettingActivity.class);
                startActivityForResult(intent, REQUEST_CODE);
            }
        }
    }

    //create new class for connect thread
    private class ConnectedThread extends Thread {
        private final InputStream mmInStream;
        private final OutputStream mmOutStream;

        //creation of the connect thread
        public ConnectedThread(BluetoothSocket socket) {
            InputStream tmpIn = null;
            OutputStream tmpOut = null;

            try {
                //Create I/O streams for connection
                tmpIn = socket.getInputStream();
                tmpOut = socket.getOutputStream();
            } catch (IOException e) { }

            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        }


        public void run() {
            byte[] buffer = new byte[256];
            int bytes;

            // Keep looping to listen for received messages
            while (true) {
                try {
                    bytes = mmInStream.read(buffer);            //read bytes from input buffer
                    String readMessage = new String(buffer, 0, bytes);
                    // Send the obtained bytes to the UI Activity via handler
                    bluetoothIn.obtainMessage(handlerState, bytes, -1, readMessage).sendToTarget();
                } catch (IOException e) {
                    break;
                }
            }
        }

        //write method
        public void write(String input) {
            byte[] msgBuffer = input.getBytes();           //converts entered String into bytes
            try {
                mmOutStream.write(msgBuffer);                //write bytes over BT connection via outstream
            } catch (IOException e) {
                //if you cannot write, close the application
//                Toast.makeText(getBaseContext(), "Connection Failure", Toast.LENGTH_LONG).show();
                finish();

            }
        }
    }


    @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_main, 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.
        switch (item.getItemId()) {
            case R.id.action_settings:
                //abro activity Settings
                /*
                Intent intentSettings = new Intent(MainActivity.this, SettingActivity.class);
                startActivity(intentSettings);
                */
                Intent intent = new Intent(MainActivity.this, SettingActivity.class);

                // damos valor al parámetro a pasar
                //intent.putExtra("param1", "valor del parámetro 1 (viene de mainActivity)");
            /*
             * Inicia una actividad que devolverá un resultado cuando
             * haya terminado. Cuando la actividad termina, se llama al método
             * onActivityResult() con el requestCode dado.
             * El uso de un requestCode negativo es lo mismo que llamar a
             * startActivity(intent) (la actividad no se iniciará como una
             * sub-actividad).
             */

                startActivityForResult(intent, REQUEST_CODE);

                return true;
            case R.id.about:
                //abro activity about
                Intent intentAbout = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(intentAbout);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;

public class SettingActivity extends MainActivity {
private static final int OK_RESULT_CODE = 1;
private String address;

private Button On,Off,Visible,list;
private BluetoothAdapter BA;
private Set<BluetoothDevice> pairedDevices;
private ListView lv;

// EXTRA string to send on to mainactivity
public static String EXTRA_DEVICE_ADDRESS = "device_address";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setting);

    On = (Button)findViewById(R.id.button1);
    Off = (Button)findViewById(R.id.button2);
    Visible = (Button)findViewById(R.id.button3);
    list = (Button)findViewById(R.id.button4);

    BA = BluetoothAdapter.getDefaultAdapter();

    lv = (ListView)findViewById(R.id.listView1);
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position,
                                long arg3)
        {

            //String addres = (String)adapter.getItemAtPosition(position);
            String info; //= ((TextView) v).getText().toString();
            info = lv.getItemAtPosition(position).toString();
            address = info.substring(info.length() - 17);
            // assuming string and if you want to get the value on click of list item
            // do what you intend to do on click of listview row
            returnParams();
           /* Intent i = new Intent(SettingActivity.this, MainActivity.class);
            i.putExtra(EXTRA_DEVICE_ADDRESS, address);
            startActivity(i);*/

        }
    });
}

protected void returnParams() {
    Intent intent = new Intent();
    //intent.putExtra(address, "'Valor devuelto por ParametrosActivity'");
    intent.setData(Uri.parse(address));
    setResult(OK_RESULT_CODE, intent);
    finish();
}
@Override
protected void onResume() {
    super.onResume();
}

public void on(View view){
    if (!BA.isEnabled()) {
        Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(turnOn, 0);
//            Toast.makeText(getApplicationContext(), "Turned on"
//

                , Toast.LENGTH_LONG).show();
    }
    else{
//            Toast.makeText(getApplicationContext(),"Already on",
//                Toast.LENGTH_LONG).show();
    }
}

public void list(View view){
    pairedDevices = BA.getBondedDevices();

    ArrayList list = new ArrayList();

    for(BluetoothDevice bt : pairedDevices) {
        list.add(bt.getName() + " - " + bt.getAddress());
    }

//        Toast.makeText(getApplicationContext(),"Showing Paired Devices",
//                Toast.LENGTH_SHORT).show();
    final ArrayAdapter adapter = new ArrayAdapter (this,android.R.layout.simple_list_item_1,      list);
    lv.setAdapter(adapter);

}


public void off(View view){
    BA.disable();
//        Toast.makeText(getApplicationContext(),"Turned off" ,
//                Toast.LENGTH_LONG).show();
}

public void visible(View view){
    Intent getVisible = new Intent(BluetoothAdapter.
            ACTION_REQUEST_DISCOVERABLE);
    startActivityForResult(getVisible, 0);

}

}
public class SettingActivity extends Activity {