I created an app for Transfer of file from bluetooth in android but unfortunately my app crashes
Following is my main source code and log of error.I have a file named "hi.txt" in my sdcard.
Kindly guide where i a going wrong.
public class MainActivity extends AppCompatActivity
{
ListView listViewPaired;
ListView listViewDetected;
ArrayList<String> arrayListpaired;
Button buttonSearch, buttonOn, buttonDesc, buttonOff;
ArrayAdapter<String> adapter, detectedAdapter, mNewDevicesArrayAdapter;
static HandleSeacrh handleSeacrh;
BluetoothDevice bdDevice;
BluetoothClass bdClass;
ArrayList<BluetoothDevice> arrayListPairedBluetoothDevices;
private ButtonClicked clicked;
ListItemClickedonPaired listItemClickedonPaired;
BluetoothAdapter bluetoothAdapter = null;
ArrayList<BluetoothDevice> arrayListBluetoothDevices = null;
ListItemClicked listItemClicked;
UUID applicationUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listViewDetected = (ListView) findViewById(R.id.listViewDetected);
listViewPaired = (ListView) findViewById(R.id.listViewPaired);
buttonSearch = (Button) findViewById(R.id.buttonSearch);
buttonOn = (Button) findViewById(R.id.buttonOn);
buttonDesc = (Button) findViewById(R.id.buttonDesc);
buttonOff = (Button) findViewById(R.id.buttonOff);
arrayListpaired = new ArrayList<String>();
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
clicked = new ButtonClicked();
handleSeacrh = new HandleSeacrh();
arrayListPairedBluetoothDevices = new ArrayList<BluetoothDevice>();
/*
* the above declaration is just for getting the paired bluetooth devices;
* this helps in the removing the bond between paired devices.
*/
listItemClickedonPaired = new ListItemClickedonPaired();
arrayListBluetoothDevices = new ArrayList<BluetoothDevice>();
adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, arrayListpaired);
detectedAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_single_choice);
mNewDevicesArrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_single_choice);
listViewDetected.setAdapter(detectedAdapter);
listItemClicked = new ListItemClicked();
detectedAdapter.notifyDataSetChanged();
listViewPaired.setAdapter(adapter);
}
#Override
protected void onStart()
{
// TODO Auto-generated method stub
super.onStart();
getPairedDevices();
buttonOn.setOnClickListener(clicked);
buttonSearch.setOnClickListener(clicked);
buttonDesc.setOnClickListener(clicked);
buttonOff.setOnClickListener(clicked);
listViewDetected.setOnItemClickListener(listItemClicked);
listViewPaired.setOnItemClickListener(listItemClickedonPaired);
}
private void getPairedDevices()
{
Set<BluetoothDevice> pairedDevice = bluetoothAdapter.getBondedDevices();
if (pairedDevice.size() > 0)
{
for (BluetoothDevice device : pairedDevice)
{
arrayListpaired.add(device.getName() + "\n" + device.getAddress());
arrayListPairedBluetoothDevices.add(device);
}
}
adapter.notifyDataSetChanged();
}
class ListItemClicked implements AdapterView.OnItemClickListener
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
bdDevice = arrayListBluetoothDevices.get(position);
Log.i("Log", "The dvice : " + bdDevice.toString());
Boolean isBonded = false;
try {
isBonded = createBond(bdDevice);
if (isBonded) {
Log.i("Log", "Paired");
}
} catch (Exception e)
{
e.printStackTrace();
}
Log.i("Log", "The bond is created: " + isBonded);
}
}
public void btSend()
{
String path = Environment.getExternalStorageDirectory()+"/hi.txt";
File file = new File(path);
BluetoothSocket socket= null;
try
{
socket = bdDevice.createRfcommSocketToServiceRecord(applicationUUID);
socket.connect();
}
catch (IOException e)
{
e.printStackTrace();
}
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, path);
values.put(BluetoothShare.DESTINATION,bdDevice.getAddress());
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
getContentResolver().insert(BluetoothShare.CONTENT_URI,values);
}
class ListItemClickedonPaired implements AdapterView.OnItemClickListener
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
bdDevice = arrayListPairedBluetoothDevices.get(position);
try {
Boolean removeBond = removeBond(bdDevice);
if (removeBond) {
arrayListpaired.remove(position);
adapter.notifyDataSetChanged();
}
Log.i("Log", "Removed" + removeBond);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private Boolean connect(BluetoothDevice bdDevice)
{
Boolean bool = false;
try {
Log.i("Log", "service method is called ");
Class cl = Class.forName("android.bluetooth.BluetoothDevice");
Class[] par = {};
Method method = cl.getMethod("createBond", par);
Object[] args = {};
bool = (Boolean) method.invoke(bdDevice);//, args);
} catch (Exception e)
{
Log.i("Log", "Inside catch of serviceFromDevice Method");
e.printStackTrace();
}
return bool.booleanValue();
};
public boolean removeBond(BluetoothDevice btDevice) throws Exception
{
Class btClass = Class.forName("android.bluetooth.BluetoothDevice");
Method removeBond = btClass.getMethod("removeBond");
Boolean returnValue = (Boolean)removeBond.invoke(btDevice);
return returnValue.booleanValue();
}
public boolean createBond(BluetoothDevice btDevice)
throws Exception
{
Class class1 = Class.forName("android.bluetooth.BluetoothDevice");
Method createBondMethod = class1.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);
return returnValue.booleanValue();
}
class ButtonClicked implements View.OnClickListener
{
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.buttonOn:
onBluetooth();
break;
case R.id.buttonSearch:
arrayListBluetoothDevices.clear();
startSearching();
break;
case R.id.buttonDesc:
makeDiscoverable();
break;
case R.id.buttonOff:
offBluetooth();
break;
default:
break;
}
}
}
private BroadcastReceiver myReceiver = new BroadcastReceiver()
{
#Override
public void onReceive(Context context, Intent intent) {
Message msg = Message.obtain();
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
Toast.makeText(context, "ACTION_FOUND", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Searching for devices", Toast.LENGTH_LONG).show();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
try {
//device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true);
//device.getClass().getMethod("cancelPairingUserInput", boolean.class).invoke(device);
} catch (Exception e) {
Log.i("Log", "Inside the exception: ");
e.printStackTrace();
}
if (arrayListBluetoothDevices.size() < 1) // this checks if the size of bluetooth device is 0,then add the
{ // device to the arraylist.
detectedAdapter.add(device.getName() + "\n" + device.getAddress());
arrayListBluetoothDevices.add(device);
detectedAdapter.notifyDataSetChanged();
} else {
boolean flag = true; // flag to indicate that particular device is already in the arlist or not
for (int i = 0; i < arrayListBluetoothDevices.size(); i++) {
if (device.getAddress().equals(arrayListBluetoothDevices.get(i).getAddress())) {
flag = false;
}
}
if (flag == true) {
detectedAdapter.add(device.getName() + "\n" + device.getAddress());
arrayListBluetoothDevices.add(device);
detectedAdapter.notifyDataSetChanged();
}
}
if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
arrayListBluetoothDevices.add(device);
}
}
}
};
private void startSearching()
{
Log.i("Log", "in the start searching method");
IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
MainActivity.this.registerReceiver(myReceiver, intentFilter);
bluetoothAdapter.startDiscovery();
}
private void onBluetooth()
{
if (!bluetoothAdapter.isEnabled()) {
bluetoothAdapter.enable();
Log.i("Log", "Bluetooth is Enabled");
Toast.makeText(getApplicationContext(), "Turned on", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Already on", Toast.LENGTH_LONG).show();
}
}
private void offBluetooth()
{
if (bluetoothAdapter.isEnabled())
{
bluetoothAdapter.disable();
Toast.makeText(getApplicationContext(), "Turned off", Toast.LENGTH_LONG).show();
}
}
private void makeDiscoverable()
{
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
Log.i("Log", "Discoverable ");
}
class HandleSeacrh extends Handler
{
#Override
public void handleMessage(Message msg) {
switch (msg.what)
{
case 111:
break;
default:
break;
}
}
}
}
Log file:
13170-13170/com.example.toshiba.bluetoothdemo D/ActivityThread: handleBindApplication:com.example.toshiba.bluetoothdemo
11-16 18:01:45.587 13170-13170/com.example.toshiba.bluetoothdemo D/ActivityThread: setTargetHeapUtilization:0.75
11-16 18:01:45.587 13170-13170/com.example.toshiba.bluetoothdemo D/ActivityThread: setTargetHeapMinFree:2097152
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve interface method 17915: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve interface method 17919: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
11-16 18:01:45.637 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getTotalMemory ()J
11-16 18:01:45.647 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getFreeMemory ()J
11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve virtual method 439: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: VFY: unable to resolve virtual method 461: Landroid/content/res/TypedArray;.getType (I)I
11-16 18:01:45.687 13170-13170/com.example.toshiba.bluetoothdemo D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
11-16 18:01:45.787 13170-13170/com.example.toshiba.bluetoothdemo D/BluetoothAdapter: 1112941536: getState() : mService = null. Returning STATE_OFF
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.24.02.07
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Build Date: 03/30/15 Mon
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Local Branch:
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Remote Branch:
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Local Patches:
11-16 18:01:45.837 13170-13170/com.example.toshiba.bluetoothdemo I/Adreno-EGL: Reconstruct Branch:
11-16 18:01:45.897 13170-13170/com.example.toshiba.bluetoothdemo D/OpenGLRenderer: Enabling debug mode 0
11-16 18:01:46.037 13170-13170/com.example.toshiba.bluetoothdemo I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#424fa760 time:8721552
11-16 18:01:48.687 13170-13170/com.example.toshiba.bluetoothdemo I/Log: Bluetooth is Enabled
11-16 18:01:48.717 13170-13170/com.example.toshiba.bluetoothdemo W/Toast: From com.example.toshiba.bluetoothdemo, go ahead.
11-16 18:01:50.267 13170-13170/com.example.toshiba.bluetoothdemo I/Timeline: Timeline: Activity_launch_request time:8725789
11-16 18:01:50.297 13170-13170/com.example.toshiba.bluetoothdemo I/Log: Discoverable
11-16 18:01:52.337 13170-13170/com.example.toshiba.bluetoothdemo I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#424fa760 time:8727857
11-16 18:01:53.227 13170-13170/com.example.toshiba.bluetoothdemo I/Log: in the start searching method
11-16 18:01:54.717 13170-13170/com.example.toshiba.bluetoothdemo W/Toast: From com.example.toshiba.bluetoothdemo, go ahead.
11-16 18:01:54.727 13170-13170/com.example.toshiba.bluetoothdemo W/Toast: From com.example.toshiba.bluetoothdemo, go ahead.
11-16 18:01:57.917 13170-13170/com.example.toshiba.bluetoothdemo I/Log: The dvice : 24:EC:99:5C:FA:8C
11-16 18:01:57.947 13170-13170/com.example.toshiba.bluetoothdemo I/Log: The bond is created: false
11-16 18:01:57.957 13170-13170/com.example.toshiba.bluetoothdemo W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
11-16 18:01:57.967 13170-13170/com.example.toshiba.bluetoothdemo D/BluetoothSocket: connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[67]}
11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] gammamode=2, cemode=10
11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] temp_gammavalue=2, temp_cevalue=10
11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] Don't setGamma!
11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] Don't setCe!
11-16 18:01:58.567 13567-13567/? W/: [ColorAdjust] Set temp_prefer temp_ce!
11-16 18:02:02.277 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:574)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:585)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:326)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at com.example.toshiba.bluetoothdemo.MainActivity.btSend(MainActivity.java:163)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at com.example.toshiba.bluetoothdemo.MainActivity$ListItemClicked.onItemClick(MainActivity.java:146)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.widget.AdapterView.performItemClick(AdapterView.java:299)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.widget.AbsListView.performItemClick(AbsListView.java:1115)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.widget.AbsListView$PerformClick.run(AbsListView.java:2928)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.widget.AbsListView$3.run(AbsListView.java:3691)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.os.Looper.loop(Looper.java:136)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5113)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
11-16 18:02:02.287 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
11-16 18:02:02.297 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-16 18:02:02.297 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
11-16 18:02:02.297 13170-13170/com.example.toshiba.bluetoothdemo W/System.err: at dalvik.system.NativeStart.main(Native Method)
11-16 18:02:02.307 13170-13170/com.example.toshiba.bluetoothdemo D/AndroidRuntime: Shutting down VM
11-16 18:02:02.307 13170-13170/com.example.toshiba.bluetoothdemo W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x416d9d58)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: FATAL EXCEPTION: main
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: Process: com.example.toshiba.bluetoothdemo, PID: 13170
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: java.lang.SecurityException: Permission Denial: writing com.android.bluetooth.opp.BluetoothOppProvider uri content://com.android.bluetooth.opp/btopp from pid=13170, uid=10137 requires android.permission.ACCESS_BLUETOOTH_SHARE, or grantUriPermission()
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1472)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.content.ContentProviderProxy.insert(ContentProviderNative.java:468)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.content.ContentResolver.insert(ContentResolver.java:1190)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at com.example.toshiba.bluetoothdemo.MainActivity.btSend(MainActivity.java:178)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at com.example.toshiba.bluetoothdemo.MainActivity$ListItemClicked.onItemClick(MainActivity.java:146)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.widget.AdapterView.performItemClick(AdapterView.java:299)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.widget.AbsListView.performItemClick(AbsListView.java:1115)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.widget.AbsListView$PerformClick.run(AbsListView.java:2928)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.widget.AbsListView$3.run(AbsListView.java:3691)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5113)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
11-16 18:02:02.317 13170-13170/com.example.toshiba.bluetoothdemo E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
'
Read this line in logcat
java.lang.SecurityException: Permission Denial: writing com.android.bluetooth.opp.BluetoothOppProvider uri content://com.android.bluetooth.opp/btopp from pid=13170, uid=10137 requires android.permission.ACCESS_BLUETOOTH_SHARE, or grantUriPermission()
This is your issue, add the android.permission.ACCESS_BLUETOOTH_SHARE permission to your manifest
I should add that this might not be your only error but it is the one causing this specific crash
Related
I cant figure out where I went wrong with my code. Every time I press a button my apps shuts down unless I add a try and catch. As soon as I enter the two numbers and add the sign, the results should print out, but instead the app is just shutting down. Here is my LogCat and code. BTW I'm new to java & android studio, so excuse my mistakes.
public class MainActivity extends AppCompatActivity {
Button btnAdd, btnSubtract,btnMultiply, btnDivide;
TextView textResults, textSigns;
EditText firstnumber, secondnumber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstnumber = (EditText) findViewById(R.id.firstnumber);
secondnumber =(EditText) findViewById(R.id.secondnumber);
textResults = (TextView) findViewById(R.id.results);
textSigns = (TextView) findViewById(R.id.invisible_signs);
btnAdd = (Button) findViewById(R.id.Add);
btnDivide = (Button) findViewById(R.id.divide);
btnMultiply =(Button) findViewById(R.id.Multiply);
btnSubtract =(Button) findViewById(R.id.Subtract);
final String number1 = firstnumber.getText().toString();
final String number2 = secondnumber.getText().toString();
btnDivide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {int divide = Integer.parseInt(number1) / Integer.parseInt(number2);
textResults.setText(number1 + " / " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + divide);}
catch(Exception e){
Toast.makeText(getApplicationContext(), "Cannot Divide These Numbers", Toast.LENGTH_SHORT).show();
}
}
});
btnMultiply.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int multiply = Integer.parseInt(number1) * Integer.parseInt(number2);
textResults.setText(number1 + " * " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + multiply);
}
});
btnAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int addition = Integer.parseInt(number1) + Integer.parseInt(number2);
textResults.setText(number1 + " + " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + addition);
}
});
btnSubtract.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int subtract = Integer.parseInt(number1) - Integer.parseInt(number2);
textResults.setText(number1 + " - " + number2 );
textResults.setVisibility(View.VISIBLE);
textResults.append("\n" + subtract);
}
});
}
}
.
Logcat:
0-25 16:12:28.330 1860-1860/com.squarespace.atpublishing.calculatorapp I/art: Not late-enabling -Xcheck:jni (already on)
10-25 16:12:28.640 1860-1867/com.squarespace.atpublishing.calculatorapp E/art: Failed writing handshake bytes (-1 of 14): Broken pipe
10-25 16:12:28.640 1860-1867/com.squarespace.atpublishing.calculatorapp I/art: Debugger is no longer active
10-25 16:12:29.680 1860-1872/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 20ms
10-25 16:12:29.680 1860-1872/com.squarespace.atpublishing.calculatorapp I/art: Background partial concurrent mark sweep GC freed 371(64KB) AllocSpace objects, 0(0B) LOS objects, 47% free, 556KB/1068KB, paused 20ms total 280ms
10-25 16:12:30.370 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 40ms
10-25 16:12:30.620 1860-1900/com.squarespace.atpublishing.calculatorapp D/OpenGLRenderer: Render dirty regions requested: true
10-25 16:12:30.690 1860-1860/com.squarespace.atpublishing.calculatorapp D/: HostConnection::get() New Host Connection established 0x7fc39eccf580, tid 1860
10-25 16:12:30.690 1860-1860/com.squarespace.atpublishing.calculatorapp D/Atlas: Validating map...
10-25 16:12:30.870 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 100ms
10-25 16:12:30.890 1860-1872/com.squarespace.atpublishing.calculatorapp I/art: Background sticky concurrent mark sweep GC freed 824(47KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 919KB/1068KB, paused 0 total 160ms
10-25 16:12:30.940 1860-1872/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 50ms
10-25 16:12:31.300 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 10ms
10-25 16:12:31.540 1860-1872/com.squarespace.atpublishing.calculatorapp I/art: Background sticky concurrent mark sweep GC freed 437(19KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 942KB/1068KB, paused 0 total 240ms
10-25 16:12:31.680 1860-1900/com.squarespace.atpublishing.calculatorapp I/OpenGLRenderer: Initialized EGL, version 1.4
10-25 16:12:31.720 1860-1900/com.squarespace.atpublishing.calculatorapp D/OpenGLRenderer: Enabling debug mode 0
10-25 16:12:31.760 1860-1900/com.squarespace.atpublishing.calculatorapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-25 16:12:31.760 1860-1900/com.squarespace.atpublishing.calculatorapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fc39ece3040, error=EGL_SUCCESS
10-25 20:12:38.850 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 220ms
10-25 20:12:39.010 1860-1860/com.squarespace.atpublishing.calculatorapp I/Choreographer: Skipped 72 frames! The application may be doing too much work on its main thread.
10-25 20:12:39.790 1860-1860/com.squarespace.atpublishing.calculatorapp I/Choreographer: Skipped 46 frames! The application may be doing too much work on its main thread.
10-25 16:12:42.610 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 30ms
10-25 16:12:42.940 1860-1860/com.squarespace.atpublishing.calculatorapp I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
10-25 16:12:43.120 1860-1900/com.squarespace.atpublishing.calculatorapp W/EGL_emulation: eglSurfaceAttrib not implemented
10-25 16:12:43.120 1860-1900/com.squarespace.atpublishing.calculatorapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fc3a5ff6fc0, error=EGL_SUCCESS
10-25 16:12:49.020 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 150ms
10-25 16:12:49.380 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 80ms
10-25 16:12:58.690 1860-1860/com.squarespace.atpublishing.calculatorapp D/AndroidRuntime: Shutting down VM
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: FATAL EXCEPTION: main
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: Process: com.squarespace.atpublishing.calculatorapp, PID: 1860
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: java.lang.NumberFormatException: Invalid int: ""
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.Integer.invalidInt(Integer.java:138)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:358)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:334)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at com.squarespace.atpublishing.calculatorapp.MainActivity$2.onClick(MainActivity.java:56)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.view.View.performClick(View.java:4756)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19749)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5221)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
10-25 16:12:58.770 1860-1860/com.squarespace.atpublishing.calculatorapp E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
10-25 16:13:05.160 1860-1867/com.squarespace.atpublishing.calculatorapp W/art: Suspending all threads took: 250ms
Remove these lines
final String number1 = firstnumber.getText().toString();
final String number2 = secondnumber.getText().toString();
And adjust this one
int divide = Integer.parseInt(firstnumber.getText()) / Integer.parseInt(secondnumber.getText());
You don't read the values of the inputs when doing calculations, so the strings will be always empty.
Variables get their values when assigned, the assignment doesn't mean they're bound to the inputs and change their values when the inputs change.
My app consists of level, each level has 10 question. This is my first level and first question class..
public class level1 extends ActionBarActivity {
private EditText mans1;
private TextView mcount;
int sum;
public void Onclick(View v) {
mans1 = (EditText) findViewById(R.id.ans1);
mcount = (TextView) findViewById(R.id.count);
double answer = Double.parseDouble(mans1.getText().toString());
if (answer == (8 + 7))
{
Toast.makeText(level1.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
mcount.setText(sum++);
}
else
{
Toast.makeText(level1.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
mcount.setText(sum);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1);
final TextView texview = (TextView)findViewById(R.id.count);
Button sendButton = (Button)findViewById(R.id.tm);
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int count = Integer.parseInt(texview.getText().toString());
Intent intent = new Intent(getApplicationContext(), level1.class);
intent.putExtra("mycount", sum);
startActivity(intent);
}
});
}
public void buttonOnClickgo(View v) {
Button next = (Button) v;
startActivity(new Intent(getApplicationContext(), level1q2.class));
}
public void buttonOnClickBack(View v) {
Button back = (Button) v;
startActivity(new Intent(getApplicationContext(), Activity2.class));
}
}
and this is the first level second question class.
public class level1q2 extends ActionBarActivity {
private EditText mans1;
private TextView mcount;
int sum;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level1q2);
TextView textView = (TextView)findViewById(R.id.count);
Intent intent = getIntent();
int count = intent.getIntExtra("mycount", 0);
textView.setText(count);}
public void Onclick(View view)
{
mans1 = (EditText) findViewById(R.id.ans1);
mcount = (TextView) findViewById(R.id.count);
double answer = Double.parseDouble(mans1.getText().toString());
if (answer == (15-3)) {
Toast.makeText(level1q2.this, "الإجابة صحيحة", Toast.LENGTH_LONG).show();
int count = getIntent().getIntExtra("mycount", 0);
mcount.setText(count++);
} else {
Toast.makeText(level1q2.this, "الإجابة خاطئة", Toast.LENGTH_LONG).show();
int count = getIntent().getIntExtra("mycount", 0);
mcount.setText(count);
}
}
public void buttonOnClickgo(View v) {
Button next = (Button) v;
startActivity(new Intent(getApplicationContext(), level1q3.class));
}
public void buttonOnClickBack(View v) {
Button back = (Button) v;
startActivity(new Intent(getApplicationContext(), Activity2.class));
}
}
I did some changes in these classes because I want to pass the count variable from first question to the second question activity.
It is was working before I edited them but now it shows "unfortunately stopped" message ..
please review the codes
After debugging ..
04:30:29.101 1075-1075/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3b03ba8)
08-23 04:30:29.121 1075-1075/com.mainuser.math.passgrade4.passgrade4 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mainuser.math.passgrade4.passgrade4, PID: 1075
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
08-23 04:30:37.051 1075-1075/com.mainuser.math.passgrade4.passgrade4 I/Process﹕ Sending signal. PID: 1075 SIG: 9
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.061 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
08-23 04:30:38.071 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 366: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
08-23 04:30:38.101 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 W/dalvikvm﹕ VFY: unable to resolve virtual method 388: Landroid/content/res/TypedArray;.getType (I)I
08-23 04:30:38.111 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
08-23 04:30:38.591 1118-1118/com.mainuser.math.passgrade4.passgrade4 D/dalvikvm﹕ GC_FOR_ALLOC freed 125K, 7% free 2894K/3100K, paused 35ms, total 35ms
The problem is exactly what your exception says:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mainuser.math.passgrade4.passgrade4/com.mainuser.math.passgrade4.passgrade4.level1}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
...
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
at com.mainuser.math.passgrade4.passgrade4.level1.onCreate(level1.java:34)
...
Your button is an ImageButton, but you tried to cast it to Button (which is not a superclass of ImageButton).
I am creating a quiz app for androids. I have 3 fragments and 3 checkboxes on first two of them. On the last fragment there is a button which when pressed opens an activity called "End". I need that on the "End" activity a result would appear of how many correct answers one have chosen.
Firstly, I've tried to check if it's working with only the first fragment, but I got stuck. The app closes when I press the button.
End.java:
package bandymas.viewpagerexample;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class End extends ActionBarActivity {
private CheckBox checkBox1, checkBox2, checkBox3;
private Button button;
TextView newresult = (TextView)findViewById(R.id.textView1);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
getSupportActionBar().hide();
addListenerOnButton();
}
private void addListenerOnButton() {
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
//Run when button is clicked
#Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("CheckBox1 : ").append(checkBox1.isChecked());
result.append("\nCheckbox2 : ").append(checkBox2.isChecked());
result.append("\nCheckBox3 :").append(checkBox3.isChecked());
newresult.setText("My Awesome Text");
}
});
}
#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_naujas_baigimas, 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.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's my logcat:
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:04:37.684 6020-6020/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:04:37.734 6020-6020/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_GT-I9505_4.4.2_0033
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> Normal User
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> bandymas.viewpagerexample [ userId:0 | appId:10229 ]
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ Late-enabling CheckJNI
04-01 20:07:31.584 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:31.594 7094-7094/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:07:31.794 7094-7094/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:07:31.844 7094-7094/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:42.454 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 365: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getType (I)I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample D/AndroidRuntime﹕ Shutting down VM
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4187fda0)
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bandymas.viewpagerexample, PID: 7094
java.lang.RuntimeException: Unable to start activity ComponentInfo{bandymas.viewpagerexample/bandymas.viewpagerexample.End}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at bandymas.viewpagerexample.End.addListenerOnButton(End.java:33)
at bandymas.viewpagerexample.End.onCreate(End.java:23)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
activity_end.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="bandymas.viewpagerexample.End">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Result"
android:id="#+id/textView1"
android:layout_marginTop="100dp"
android:textSize="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Please Check that there is the button(R.id.button) in activity_end.xml.
I guess that the button's id doesn't exist in activity_end.xml.
im making a simple calories calculator and it gives me that error, i already reviewed the code and searched here for the solution but im not able to see why is not running.
I thought it was because i had not initialized the variable, so i did it and still got the same error, maybe is something with the spinners, im new on using spinners
here is the code:
public class CaloriesCalculator extends ActionBarActivity {
EditText etAge, etWeight, etHeight;
Button btnCalculate;
TextView tvResult;
Spinner spinnerGender, spinnerActivity;
String itemGender, itemActivity;
int Height=0;
int Weight=0;
int Age=0;;
double bmr=0.0;
double tdee=0.0;
String result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.caloriescalculator);
spinnerGender=(Spinner)findViewById(R.id.spinnerGender);
spinnerActivity=(Spinner)findViewById(R.id.spinnerActivity);
etAge=(EditText)findViewById(R.id.etAge);
etWeight=(EditText)findViewById(R.id.etWeight);
etHeight=(EditText)findViewById(R.id.etHeight);
tvResult=(TextView)findViewById(R.id.tvResult);
List<String> list = new ArrayList<String>();
list.add("Male");
list.add("Female");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, list );
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerGender.setAdapter(dataAdapter);
List<String> list2 = new ArrayList<String>();
list.add("Sedentary");
list.add("Lightly Active");
list.add("Moderalety Active");
list.add("Very Active");
list.add("Extremely Active");
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, list2 );
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerActivity.setAdapter(dataAdapter2);
btnCalculate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
spinnerGender.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
spinnerActivity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
itemGender=String.valueOf(spinnerGender.getSelectedItem());
itemActivity=String.valueOf(spinnerActivity.getSelectedItem());
if(itemGender=="Male"){
Weight=Integer.parseInt(etWeight.getText().toString());
Height=Integer.parseInt(etHeight.getText().toString());
Age=Integer.parseInt(etAge.getText().toString());
if(itemActivity=="Sedentary"){
bmr=66+((13.7 * Weight)+(5*Height))-(6.8*Age);
tdee=bmr*1.2;
}
else if(itemActivity=="Lightly Active"){
bmr=66+((13.7 * Weight)+(5*Height))-(6.8*Age);
tdee=bmr*1.375;
}
else if(itemActivity=="Moderalety Active"){
bmr=66+((13.7 * Weight)+(5*Height))-(6.8*Age);
tdee=bmr*1.55;
}
else if(itemActivity=="Very Active"){
bmr=66+((13.7 * Weight)+(5*Height))-(6.8*Age);
tdee=bmr*1.725;
}
else if(itemActivity=="Extremely Active"){
bmr=66+((13.7 * Weight)+(5*Height))-(6.8*Age);
tdee=bmr*1.9;
}
}
else if(itemGender=="Female") {
Weight=Integer.parseInt(etWeight.getText().toString());
Height=Integer.parseInt(etHeight.getText().toString());
Age=Integer.parseInt(etAge.getText().toString());
if(itemActivity=="Sedentary"){
bmr=655+((9.6*Weight)+(1.8*Height))-(4.7*Age);
tdee=bmr*1.2;
}
else if(itemActivity=="Lightly Active"){
bmr=655+((9.6*Weight)+(1.8*Height))-(4.7*Age);
tdee=bmr*1.375;
}
else if(itemActivity=="Moderalety Active"){
bmr=655+((9.6*Weight)+(1.8*Height))-(4.7*Age);
tdee=bmr*1.55;
}
else if(itemActivity=="Very Active"){
bmr=655+((9.6*Weight)+(1.8*Height))-(4.7*Age);
tdee=bmr*1.725;
}
else if(itemActivity=="Extremely Active"){
bmr=655+((9.6*Weight)+(1.8*Height))-(4.7*Age);
tdee=bmr*1.9;
}
}
result=Double.toString(tdee);
tvResult.setText(result);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
logcat:
11-28 17:20:05.501: E/AndroidRuntime(1455): FATAL EXCEPTION: main
11-28 17:20:05.501: E/AndroidRuntime(1455): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.calculadoracalorias/com.app.calculadoracalorias.CaloriesCalculator}: java.lang.NullPointerException
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.os.Looper.loop(Looper.java:137)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-28 17:20:05.501: E/AndroidRuntime(1455): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 17:20:05.501: E/AndroidRuntime(1455): at java.lang.reflect.Method.invoke(Method.java:525)
11-28 17:20:05.501: E/AndroidRuntime(1455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-28 17:20:05.501: E/AndroidRuntime(1455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-28 17:20:05.501: E/AndroidRuntime(1455): at dalvik.system.NativeStart.main(Native Method)
11-28 17:20:05.501: E/AndroidRuntime(1455): Caused by: java.lang.NullPointerException
11-28 17:20:05.501: E/AndroidRuntime(1455): at com.app.calculadoracalorias.CaloriesCalculator.onCreate(CaloriesCalculator.java:67)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.Activity.performCreate(Activity.java:5133)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-28 17:20:05.501: E/AndroidRuntime(1455): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-28 17:20:05.501: E/AndroidRuntime(1455): ... 11 more
11-28 17:24:42.341: D/AndroidRuntime(1507): Shutting down VM
11-28 17:24:42.341: W/dalvikvm(1507): threadid=1: thread exiting with uncaught exception (group=0x41465700)
11-28 17:24:42.371: E/AndroidRuntime(1507): FATAL EXCEPTION: main
11-28 17:24:42.371: E/AndroidRuntime(1507): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.calculadoracalorias/com.app.calculadoracalorias.CaloriesCalculator}: java.lang.NullPointerException
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.os.Looper.loop(Looper.java:137)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-28 17:24:42.371: E/AndroidRuntime(1507): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 17:24:42.371: E/AndroidRuntime(1507): at java.lang.reflect.Method.invoke(Method.java:525)
11-28 17:24:42.371: E/AndroidRuntime(1507): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-28 17:24:42.371: E/AndroidRuntime(1507): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-28 17:24:42.371: E/AndroidRuntime(1507): at dalvik.system.NativeStart.main(Native Method)
11-28 17:24:42.371: E/AndroidRuntime(1507): Caused by: java.lang.NullPointerException
11-28 17:24:42.371: E/AndroidRuntime(1507): at com.app.calculadoracalorias.CaloriesCalculator.onCreate(CaloriesCalculator.java:70)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.Activity.performCreate(Activity.java:5133)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-28 17:24:42.371: E/AndroidRuntime(1507): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-28 17:24:42.371: E/AndroidRuntime(1507): ... 11 more
Yout btnCalculate is null, you should initialize before doing the onclickListener:
btnCalculate = (Button)findViewById(R.id.btnCalculate); //your id
Also note that you are initializing the dataAdapter2 but actually you are using dataAdapert, and list2 dont have any elements, because you declare it but u are filling always list1
I would like to create applications forming charts based on data from parse.com. I have read some examples and tutorials but still have problem with displaying charts. Below is my code:
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import java.util.ArrayList;
public class LineGraph {
public ArrayList<Integer> dataArray;
XYMultipleSeriesDataset dataset;
XYMultipleSeriesRenderer renderer;
public static boolean ClickEnabled = true;
public Intent getIntent(Context context) {
ArrayList<Integer> y = this.dataArray;
XYSeries seriesY = new XYSeries("Y");
for (int i = 0; i < y.size(); i++) {
seriesY.add(i, y.get(i));
}
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesY);
renderer.setPanEnabled(true, false);
renderer.setClickEnabled(ClickEnabled);
renderer.setBackgroundColor(Color.WHITE);
renderer.setApplyBackgroundColor(true);
renderer.setChartTitle("Simple data");
renderer.setAxesColor(Color.BLACK);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setColor(Color.RED);
renderer.setPointStyle(PointStyle.DIAMOND);
mRenderer.addSeriesRenderer(renderer);
Intent intent = ChartFactory.getLineChartIntent(context, dataset, mRenderer, "Line Graph Title");
return intent;
}
public void getData() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Counters_data");
query.getInBackground("lxFzCTeOcl", new GetCallback<ParseObject>() {
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
String object = parseObject.getString("value");
Integer objectValue = Integer.parseInt(object);
if (dataArray == null) {
dataArray = new ArrayList<Integer>();
dataArray.add(objectValue);
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
}
}
And there is how I invoke charts:
public void lineGraphHandler(View view) {
LineGraph line = new LineGraph();
line.getData();
Intent lineIntent = line.getIntent(this);
startActivity(lineIntent);
}
And XML part:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/counters"
android:onClick="lineGraphHandler"
android:text="Charts"
android:id="#+id/charts"/>
There is my logcat:
03-26 08:42:13.096 1229-1229/com.example.tst D/dalvikvm﹕ Late-enabling
CheckJNI 03-26 08:42:13.487 1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libEGL_genymotion.so 03-26 08:42:13.491
1229-1229/com.example.tst D/﹕ HostConnection::get() New Host
Connection established 0xb94f4270, tid 1229 03-26 08:42:13.551
1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libGLESv1_CM_genymotion.so 03-26 08:42:13.551
1229-1229/com.example.tst D/libEGL﹕ loaded
/system/lib/egl/libGLESv2_genymotion.so 03-26 08:42:14.035
1229-1229/com.example.tst W/EGL_genymotion﹕ eglSurfaceAttrib not
implemented 03-26 08:42:14.039 1229-1229/com.example.tst
E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache 03-26
08:42:14.043 1229-1229/com.example.tst E/OpenGLRenderer﹕
MAX_TEXTURE_SIZE: 4096 03-26 08:42:14.055 1229-1229/com.example.tst
E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from
Caches::initConstraints() 03-26 08:42:14.063 1229-1229/com.example.tst
E/OpenGLRenderer﹕ MAX_TEXTURE_SIZE: 4096 03-26 08:42:14.063
1229-1229/com.example.tst D/OpenGLRenderer﹕ Enabling debug mode 0
03-26 08:42:50.327 1229-1229/com.example.tst D/dalvikvm﹕ GC_FOR_ALLOC
freed 200K, 8% free 2975K/3228K, paused 10ms, total 13ms 03-26
08:42:51.675 1229-1229/com.example.tst D/dalvikvm﹕ GC_FOR_ALLOC freed
431K, 14% free 3056K/3540K, paused 22ms, total 28ms 03-26 08:42:52.043
1229-1229/com.example.tst W/EGL_genymotion﹕ eglSurfaceAttrib not
implemented 03-26 08:42:53.543 1229-1229/com.example.tst
I/Choreographer﹕ Skipped 89 frames! The application may be doing too
much work on its main thread. 03-26 08:43:01.747
1229-1229/com.example.tst D/AndroidRuntime﹕ Shutting down VM 03-26
08:43:01.747 1229-1229/com.example.tst W/dalvikvm﹕ threadid=1: thread
exiting with uncaught exception (group=0xa4d8fb20) 03-26 08:43:01.767
1229-1229/com.example.tst E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.tst, PID: 1229 java.lang.IllegalStateException:
Could not execute method of the activity at
android.view.View$1.onClick(View.java:3823) at
android.view.View.performClick(View.java:4438) at
android.view.View$PerformClick.run(View.java:18422) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5017) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.reflect.InvocationTargetException at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
android.view.View$1.onClick(View.java:3818) at
android.view.View.performClick(View.java:4438) at
android.view.View$PerformClick.run(View.java:18422) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.NullPointerException at
com.example.tst.LineGraph.getIntent(LineGraph.java:36) at
com.example.tst.MainActivity.lineGraphHandler(MainActivity.java:44)
at java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
android.view.View$1.onClick(View.java:3818) at
android.view.View.performClick(View.java:4438) at
android.view.View$PerformClick.run(View.java:18422) at
android.os.Handler.handleCallback(Handler.java:733) at
android.os.Handler.dispatchMessage(Handler.java:95) at
android.os.Looper.loop(Looper.java:136) at
android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:515) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method) 03-26 08:43:04.507
1229-1229/com.example.tst I/Process﹕ Sending signal. PID: 1229 SIG: 9
I don't understand where the problem is. My app starts but crashes immediately when I push "chart" button. Is it data type of problem or because I misunderstand something?
Thank you in advance.
I tried like this but still got crash:
public void done(ParseObject parseObject, ParseException e) {
if (e == null) {
String object = parseObject.getString("value");
Integer objectValue = Integer.parseInt(object);
if (dataArray == null) {
dataArray = new ArrayList<Integer>();
dataArray.add(objectValue);
ArrayList<Integer> y = dataArray;
XYSeries seriesY = new XYSeries("Y");
for (int i = 0; i < y.size(); i++) {
seriesY.add(i, y.get(i));
dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesY);
}
}
Your getData() retrieves the data asynchronously. dataArray won't be initialized immediately when you call getIntent().
Wait for the async operation to complete before using the data there. For example, call the code requiring that data from the done() callback.