简体   繁体   English

不幸的是,该应用已停止在Android中运行

[英]Unfortunately the app has stopped working error in Android

I am new to making Android Applications. 我是制作Android应用程序的新手。 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(ie jumping from one activity to the next), the app stops and it displays this message instead of showing the next screen. 我正在使用蓝牙API的Android应用程序(在Eclipse中)工作,当我从已配对设备的列表中选择特定的设备名称时(即从一个活动跳转到下一个活动),该应用程序停止并显示此问题消息,而不是显示下一个屏幕。 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) 这是第二个活动Controls.java的代码(截至目前仅包含按钮)

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>

I assume you are getting NullPointerException because you have commented following line. 我假设您收到NullPointerException原因是您已注释了以下行。

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

remove the comment from this line. 从此行中删除评论。 That file holds your view components. 该文件包含您的视图组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM