Question

I am new to making Android Applications. I was working on an Android App(in Eclipse) that uses Bluetooth APIs and the problem occurs when I select a particular device name from the list of paired devices(i.e. jumping from one activity to the next), the app stops and it displays this message instead of showing the next screen. I am not able to understand what the error could be. I am sharing the code snippet from the Main Activity:

// listening to single list item on click
           listOfDevices.setOnItemClickListener(new OnItemClickListener() {
               @Override
               public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

                  // Launching new Activity on selecting single List Item
                 Intent i = new Intent(getApplicationContext(), Controls.class);
                 startActivity(i);

              }
            });

This is the code for the 2nd activity- Controls.java (contains only buttons as of now)

public class Controls extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //this.setContentView(R.layout.controls);

   final Button bt1 = (Button) findViewById(R.id.button1);
    final Button bt2 = (Button) findViewById(R.id.button2);
    final Button bt3 = (Button) findViewById(R.id.button3);
    final Button bt4 = (Button) findViewById(R.id.button4);
bt1.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
bt2.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
bt3.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
bt4.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));
    Intent i = getIntent(); 



    }
}

And this is the Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="team2.cse8.project"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Main"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Controls"
                android:label="@string/app_name">
    </activity>

</application>
</manifest>
Was it helpful?

Solution

I assume you are getting NullPointerException because you have commented following line.

//this.setContentView(R.layout.controls);

remove the comment from this line. That file holds your view components.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top