|
Mostrar Temas
|
Páginas: 1 [2] 3 4
|
12
|
Programación / Java / [Android] Conexión BD externa. [Solucionado]
|
en: 14 Septiembre 2015, 08:26 am
|
Hola, Estoy intentando que se conecte el Android directamente a la BD Mysql de mi ordenador y cuando llega a la línea Class.forName("com.mysql.jdbc.Driver").newInstance();
me salta la excepción ClassNotFoundException a que se debe??? import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * Created by alarcon on 27/7/15. */ public class BBDDMySQL { boolean debug = true; public BBDDMySQL() { super(); } { if (mConnection == null) { if (catalog != "") { urlMySQL = "jdbc:mysql://" + ip + ":" + port + "/" + catalog; }else { urlMySQL = "jdbc:mysql://" + ip + ":" + port; } if (!user.isEmpty() && !ip.isEmpty() && !port.isEmpty()) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } { if(debug) System. out. println("Connect2BDMySQL --" + " Connect2BDMySQL -> Error: " + e.getMessage()); return false; } { if(debug) System. out. println("Connect2BDMySQL --" + " Connect2BDMySQL -> Error: " + e.getMessage()); return false; e.printStackTrace(); e.printStackTrace(); } } } return true; } }
Solución: vaya fallo no me había cogido la librería de sql, no estaba linkada. -------------------------------------- Pero sigo sin poder conectarme a la BD ahora el problema es que no me puedo conectar. Connect2BDMySQL -- Connect2BDMySQL -> Error: Could not create connection to database server. SQLState: 08001 VendorError: 0 Parece que es un problema de red, pero tengo ambos dispositivos conectados en la misma red. Solución. El problema no era del código si no de la configuración del MySQL para solucionarlo había que proporcionale permisos al usuario y habilitar en mysql las conexiones externeas. Ojito si teneis ferial activo. aquí un enlace con los pasos a seguir. http://www.trey.es/blog/base-de-datos/mysql/permitir-conexiones-externas-mysql/
|
|
|
13
|
Programación / Programación C/C++ / Conversión tipos float a U_int8
|
en: 23 Agosto 2015, 22:57 pm
|
Hola gente,
Estoy aquí porque ando un poco perdido con los tipos y los diferentes lenguajes, les comento.
tengo un numero en float(32 bits) y necesito pasarlo a u_int8. Mi idea, y creo que no voy a perder representación es el numero tipo float multiplicarlo por 1000, es decir, 25.890 float seria 25890.0 hacerle un cast a entero.
y luego esto dividirlo en en 4 bytes que se enviaría y en java recoger los 4byte y montar el número entero.
Mi pregunta es ¿Perderé representación al multiplicar x1000?
¿Hay alguna otra manera? He visto que con memcpy pero después de probarlo no lo he conseguido.
|
|
|
14
|
Programación / Java / conversion de tipos.
|
en: 5 Agosto 2015, 21:12 pm
|
Hola tengo una dudilla a ver si me pueden echar una mano. tengo un array de bytes que me llega de un dispositivo Bluetooth byte[] scandRecord ={9,9,65,114,113,117,101,116,97,0,3,3,-1,-1,5,-1,15,60,112 ,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0};
yo se que la información que me tiene que llegar va a ser unsigned y de 8 bites por eso no entiendo porque aparece el -1, debería aparecer f = 255 2^7-1 que es lo que ha sido enviado en el dispositivo. Como podría yo comparar estos valores si estoy haciendo una comparación en hex. es decir 0xf con -1. hasta ahora comparaba cogiendo el tipo? switch(byte) case 0xff: pero no me funciona? PD: creo que son las horas delante de la pantalla las que demuestran mi idiotez.
|
|
|
15
|
Programación / Java / [Android] Por qué funciona y salta excepcion del error.
|
en: 27 Julio 2015, 11:58 am
|
Hola, les comento gente estoy haciendo un controlador BLE (Bluetooth low energy). Estoy montando una arquitectura separando el controlador BLE de la GUI y demás pero tengo un error que aunque el programa funciona me gustaría corregirlo. Os explico: Tengo una clase para manejar los dispositivos BLE: package pfc.teleco.upct.es.iot_ble.BLE; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter.LeScanCallback; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCallback; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.Intent; import android.util.Log; import java.util.ArrayList; import java.util.List; import java.util.UUID; import pfc.teleco.upct.es.iot_ble.BEAN.BeanBluetoothDevice; import pfc.teleco.upct.es.iot_ble.Constant; import pfc.teleco.upct.es.iot_ble.DEVICES.Device; public class HandlerBLE implements LeScanCallback { public static final String ACTION_DEVICE_CONNECTED = "pfc.teleco.upct.es.iot_ble.DEVICE_FOUND"; private static HandlerBLE mHandlerBLE; private static BluetoothDevice mDevice; private static String mDeviceAddress ; private static BluetoothGatt mGatt; private static BluetoothAdapter mBlueAdapter = null; public static boolean isScanning = false; //################################################################### /****************** Constructor **********************/ //################################################################### { mContext = context; mDeviceAddress= null; } //################################################################### /********************* statics methods **************************/ //################################################################### public static HandlerBLE getInstance (Context context ) { if(mHandlerBLE==null){ mHandlerBLE = new HandlerBLE(context); setup(); } return mHandlerBLE; } public static void resetHandlerBLE() { mDeviceAddress=null; disconnect(); mGatt=null; } public static void setup() { BluetoothManager manager = (BluetoothManager ) mContext. getSystemService(Context. BLUETOOTH_SERVICE); mBlueAdapter = manager.getAdapter(); } //################################################################### /********************* methods bluetooth *************/ //################################################################### public void setDeviceAddress (String address ) { mDeviceAddress=address; } public String getDeviceAddress () { return mDeviceAddress; } public void startLeScan() { try { mBlueAdapter.startLeScan(this);//deprecated isScanning = true; //mBlueAdapter.startDiscovery(); } { Log.i(Constant.TAG,"(HandlerBLE)[Error]:"+e.getStackTrace()+" "+e.getCause()+" "+e.getMessage()+ " "+e.getLocalizedMessage()); } } public void stopLeScan() { try { mBlueAdapter.stopLeScan(this); //deprecated //mBlueAdapter.startDiscovery(); isScanning = false; } { Log.i(Constant.TAG,"(HandlerBLE)[Error]:"+e.getStackTrace()+" "+e.getCause()+" "+e.getMessage()+ " "+e.getLocalizedMessage()); } } /* public void connect() { mDevice = mBlueAdapter.getRemoteDevice(mDeviceAddress); mServices.clear(); if(mGatt!=null){ mGatt.connect(); }else{ mDevice.connectGatt(mContext, false, mCallBack); } } */ public void discoverServices() { if (Constant.DEBUG) Log.i(Constant.TAG, "(HandlerBLE)Scanning services and caracteristics"); mGatt.discoverServices(); } public static void disconnect(){ if (mGatt!=null) { try{ mGatt.disconnect(); mGatt.close(); if (Constant.DEBUG) Log.i(Constant.TAG, "(HandlerBLE)Disconnecting GATT"); } mGatt = null; } public boolean isConnected(){ return (mGatt!=null); } //################################################################### /********************* methods Scan bluetooth *************/ //################################################################### /* * this method is used to receive devices which were found durind a scan*/ @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { if(Constant.DEBUG) Log.i(Constant.TAG,"(HandlerBLE) -- onLeScan -> throwing information to the listener."); //create the packet wich will be sent to listener. Intent intent = new Intent(); intent.setAction(HandlerBLE.ACTION_DEVICE_CONNECTED); BeanBluetoothDevice beanBlue = new BeanBluetoothDevice(); beanBlue.setBluetoothDevice(device); beanBlue.setmRssi(rssi); beanBlue.setmScanRecord(scanRecord); intent.putExtra(Constant.EXTRA_BEAN_BLUETOOTHDEVICE,beanBlue); mContext.sendBroadcast(intent); } }
Esta clase se encargará de controlar el BLE sanea, conexión y comunicación con otros dispositivos. Y a su vez se comunicará con el resto de la aplicación con Broadcastreceiver , es decir en el método implementado en la interfaz onLeScan, me avisa cuando se ha encontrado un dispositivo y envia la señal broadcast. Como se puede ver tengo un objeto llamado BeanBluetoothDevice este simplemente es una encapsulación de la información que necesito y serializado. public class BeanBluetoothDevice implements Parcelable { private BluetoothDevice mdevice; private int mRssi; private byte[] mScanRecord; public BeanBluetoothDevice() { super(); } //################################################################### protected BeanBluetoothDevice(Parcel in) { mdevice = in.readParcelable(BluetoothDevice.class.getClassLoader()); mRssi = in.readInt(); mScanRecord = in.createByteArray(); } public static final Creator<BeanBluetoothDevice> CREATOR = new Creator<BeanBluetoothDevice>() { @Override public BeanBluetoothDevice createFromParcel(Parcel in) { return new BeanBluetoothDevice(in); } @Override public BeanBluetoothDevice[] newArray(int size) { return new BeanBluetoothDevice[size]; } }; //################################################################### /****************** gets and sets methods **********************/ //################################################################### public void setBluetoothDevice(BluetoothDevice device) {mdevice = device;} public BluetoothDevice getBluetoothDevice() {return mdevice;} public int getmRssi() { return mRssi; } public void setmRssi(int mRssi) { this.mRssi = mRssi; } public byte[] getmScanRecord() { return mScanRecord; } public void setmScanRecord(byte[] mScanRecord) { this.mScanRecord = mScanRecord; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(mdevice, flags); dest.writeInt(mRssi); dest.writeByteArray(mScanRecord); } }
una vez e envia la señal yo la recojo en la activity que me interesa, en mi casa es la principal para mostrar los dispositivos. public class ScanActivity extends ListActivity implements OnItemClickListener{ //}, LeScanCallback { private static final int SCAN_ITEM = 1; private static HandlerBLE mHandlerBLE; private Handler mHandler; private static MySimpleArrayAdapter mAdapter; private static List<BluetoothDevice> mDeviceList; private Activity mActivity; private BLEBroadcastReceiver mScanBroadcastReceiver; //################################################################### /****************** metodos del flujo Android. **********************/ //################################################################### @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scan); mActivity = this; mContext = this; mHandler = new Handler() ; mDeviceList = new ArrayList<BluetoothDevice>(); mAdapter = new MySimpleArrayAdapter(mContext, mDeviceList); mScanBroadcastReceiver = new BLEBroadcastReceiver(this,mAdapter); IntentFilter i = new IntentFilter(HandlerBLE.ACTION_DEVICE_CONNECTED); registerReceiver(mScanBroadcastReceiver,i); if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "BLE TECHNOLOGY NOT SUPPORTED ON THIS DEVICE", Toast.LENGTH_SHORT).show(); finish(); } //run service Intent service = new Intent(this, ServiceDetectionTag.class); startService(service); //manejador BLE mHandlerBLE = ((BLE_Application) getApplication()).getmHandlerBLEInstance(this); ((BLE_Application) getApplication()).resetHandlerBLE(); mListView = getListView(); mListView. setVisibility(View. VISIBLE); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(this); } @Override public boolean onCreateOptionsMenu (Menu menu ) { super.onCreateOptionsMenu(menu); mMenu = menu; String menuTitle = getResources (). getString(R. string. scan); menu.add(0,SCAN_ITEM,0,menuTitle); /* // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_scan, menu);*/ return true; } @Override public boolean onOptionsItemSelected (MenuItem item ) { switch (item.getItemId()){ case SCAN_ITEM: scan(); break; } return true; /* // 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. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item);*/ } @Override protected void onResume() { super.onResume(); //mAdapter.clear(); HandlerBLE.setup(); } @Override protected void onPause() { super.onStop(); //Make sure that there is no pending Callback mHandler.removeCallbacks(mStopRunnable); //stop service Intent service = new Intent(this, ServiceDetectionTag.class); stopService(service); //mAdapter.clear(); if (mHandlerBLE.isScanning) { mHandlerBLE.stopLeScan(); unregisterReceiver(mScanBroadcastReceiver); } } @Override protected void onStop() { super.onStop(); } //################################################################### /****************** metodos manejo Tag **********************/ //################################################################### @Override //recogemos los metodos del tag seleccionado y recogemos los datos. public void onItemClick (AdapterView <?> parent, View view, int position, long id ) { if (Constant.DEBUG) Log.i(Constant.TAG, "Selected device " + mDeviceList.get(position).getAddress()); if (mHandlerBLE.isScanning) { //stop scanning configureScan(false); mHandlerBLE.stopLeScan(); if (Constant.DEBUG) Log.i(Constant.TAG, "Stop scanning"); } String address = mDeviceList. get(position ). getAddress(); String name = mDeviceList. get(position ). getName(); if (name==null) name="unknown"; Intent intentActivity= new Intent(this, DeviceActivity.class); intentActivity.putExtra(Constant.EXTRA_ADDRESS, address); intentActivity.putExtra(Constant.EXTRA_NAME, name); this.startActivity(intentActivity); if (Constant.DEBUG) Log.i(Constant.TAG, "Trying to connect"); //mConnectionManager.connect(address,true); Toast.makeText(this, "Wait for connection to selected device", Toast.LENGTH_LONG).show(); } //Handle automatic stop of LEScan @Override public void run() { mHandlerBLE.stopLeScan(); configureScan(false); if (Constant.DEBUG) Log.i(Constant.TAG, "Stop scanning"); } }; public void configureScan(boolean flag) { //isScanning = flag; if (mHandlerBLE.isScanning) { itemText = getResources().getString(R.string.stopScan); mHandlerBLE.stopLeScan(); if (Constant.DEBUG) Log.i(Constant.TAG, "ScanActivity -- StopScan"); } else { itemText= getResources().getString(R.string.scan); mHandlerBLE.startLeScan(); if (Constant.DEBUG) Log.i(Constant.TAG, "ScanActivity -- StartScan"); } mMenu.findItem(SCAN_ITEM).setTitle(itemText); if (Constant.DEBUG) Log.i(Constant.TAG, "Updated Menu Item. New value: " + itemText); } // Metodo para iniciar el scaneo cuando te llaman manualmente. private void scan() { if (mHandlerBLE.isScanning) { //stop scanning configureScan(false); mHandlerBLE.stopLeScan(); if (Constant.DEBUG) Log.i(Constant.TAG, "Stop scanning"); return; } else { mAdapter.clear(); mAdapter.notifyDataSetChanged(); configureScan(true); if (Constant.DEBUG) Log.i(Constant.TAG, "Start scanning for BLE devices..."); mHandlerBLE.startLeScan(); //automatically stop LE scan after 5 seconds mHandler.postDelayed(mStopRunnable, 30000); } } /* Clase para crear el adaptador de dispositos Bluetooh */ public class MySimpleArrayAdapter extends ArrayAdapter<BluetoothDevice> { public MySimpleArrayAdapter (Context context, List <BluetoothDevice > deviceList ) { super(context, R.layout.activity_scan_item,R.id.deviceName, deviceList); this.context = context; } } /* @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { String name="unknown"; if (device.getName()!=null) name=device.getName(); final String finalName = name; final String finalAddress = device.getAddress(); if (Constant.DEBUG) Log.i(Constant.TAG, "Found new device "+ finalAddress + " --- Name: " + finalName); final BluetoothDevice finalDevice= device; // This callback from Bluetooth LEScan can arrive at any moment not necessarily on UI thread. // Use this mechanism to update list View mActivity.runOnUiThread(new Runnable() { @Override public void run() { mAdapter.add(finalDevice); mAdapter.notifyDataSetChanged(); if (Constant.DEBUG) Log.i(Constant.TAG, "Added new device "+ finalAddress + " --- Name: " + finalName); } } ); }*/ }
Como se puede ver en el método onCreate doy de alta la señal que espero recibir. mScanBroadcastReceiver = new BLEBroadcastReceiver(this,mAdapter); IntentFilter i = new IntentFilter(HandlerBLE.ACTION_DEVICE_CONNECTED); registerReceiver(mScanBroadcastReceiver,i);
Ahora nos dirigimos en la clase donde creo que está el problema, es la clase donde se recibe la señal Broadcast y se procesa. public class BLEBroadcastReceiver extends BroadcastReceiver { private Activity mActivity; private ScanActivity.MySimpleArrayAdapter mAdapter; public BLEBroadcastReceiver(Activity activity, ScanActivity.MySimpleArrayAdapter adapter) { super(); mAdapter = adapter; mActivity = activity; } public BLEBroadcastReceiver() { super(); } @Override public void onReceive (Context context, Intent intent ) { if(Constant.DEBUG) Log.i(Constant.TAG, "ScanActivity -- OnReceive() -> BroadcastReceiver new device found."); //get signal and add new device into MyarrayAdapter if(intent.getAction().equals(HandlerBLE.ACTION_DEVICE_CONNECTED)) { try { BeanBluetoothDevice beanDeviceFound = intent.getExtras().getParcelable(Constant.EXTRA_BEAN_BLUETOOTHDEVICE); final BluetoothDevice deviceFound = beanDeviceFound.getBluetoothDevice(); mActivity. runOnUiThread(new Runnable() { @Override public void run() { mAdapter.add(deviceFound); mAdapter.notifyDataSetChanged(); if (Constant.DEBUG) Log.i(Constant.TAG, "Added new device " + deviceFound.getAddress() + " --- Name: " + deviceFound.getName()); } }); { Log.i(Constant.TAG,"[Error(BLEBroadcastReceiver)]: "+e.getCause()+"\n"+e.getStackTrace()+"\n"+e.getLocalizedMessage()); } } } }
aquí el problema me aparice cuando quito el constructor vacío, es decir, al que no se le pasan parámetros. Si lo eliminamos en tiempo de ejecución el programa peta y cuando se lo pongo todo corre normalmente, es decir, si me introduce el dispositivo en el arrayList pero a su vez me da una excepción de los objetos mAdapter y mActivity. ¿A qué puede deberse esto? Si al final lo introduce correctamente. PD: soy un patata programando, no ser muy duros conmigo.
|
|
|
17
|
Programación / .NET (C#, VB.NET, ASP) / [C#] DataGridView congelación de app
|
en: 10 Junio 2015, 10:15 am
|
Hola,
El problema es el siguiente: inserto filas en un datagridview y cuando llega a un determinado número de filas se queda la app congelada y el scroll vertical no aparece si no que hace algo raro. Además tengo la propiedad ScrollBar en Vertical.
Personalmente no sé que puede estar pasando quizas un problema de la interfaz .... ni idea. He estado buscando por internet y a la gente este componente no suele darle muchos problemas.
¿Se os ocurre que puede estar pasando?
######################### Ya aparece el scroll era simplemente que tenia la propiedad AutoSize = true; y claro había que ponerla a false. Pero el problema sigue existiendo cuando aparece el scroollBar la app se queda congelada.
|
|
|
20
|
Programación / Programación General / [Estimación]Controlar tiempo de desarrollo.
|
en: 29 Abril 2015, 16:45 pm
|
Hola,
Me gustaría que me comentaseis como hacéis para calcular los tiempos de desarrollo dado que actualmente estoy de freelance y me como algunos marrones porque no estimo convenientemente.
¿Qué metodología utilizais?¿Los que desarrollas solos os marcáis plazos?
PD: en mi caso son proyectos semi profesionales (java, android, .Net y C).
|
|
|
|
|
|
|