简体   繁体   English

清单中的类集成:应用程序已停止

[英]Class integration in Manifest: application stopped

My manifest.xml raises error for ".RoleActivity". 我的manifest.xml引发“ .RoleActivity”错误。 But If I replace my ".roleActivity" with others for checking, they all are okay. 但是,如果我用其他人替换我的“ .roleActivity”进行检查,它们都可以。 Here is my manifest.xml 这是我的manifest.xml

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.zobaed.androidlogin" >
 <uses-permission android:name="android.permission.INTERNET" />
 <application
    android:allowBackup="true"
  android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity android:name=".RoleActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

         <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".DoctorLoginActivity">
        </activity>
    <activity android:name=".PatientLoginActivity">
        </activity>

   </application>
  </manifest>

Here is my RoleActivity. 这是我的RoleActivity。 Tried to write switch case here. 试图在这里写开关盒。

public class RoleActivity extends AppCompatActivity {

    private Button btnPatient;
    private Button btnDoctor;
    private Button btnGuest;
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.log_in_role);


    btnPatient = (Button) findViewById(R.id.btpatient);
    btnDoctor = (Button) findViewById(R.id.btdoctor);
    btnGuest = (Button) findViewById(R.id.btguest);

    btnPatient.setOnClickListener((View.OnClickListener) this);
    btnDoctor.setOnClickListener((View.OnClickListener) this);
    btnGuest.setOnClickListener((View.OnClickListener) this);
    }

    public void onClick(View v) {
    switch (v.getId()) {
        case  R.id.btdoctor: {

            Intent i = new Intent(getApplicationContext(), DoctorLoginActivity.class);
            startActivity(i);
            break;
        }

        case R.id.btpatient: {

            Intent i = new Intent(getApplicationContext(), PatientLoginActivity.class);
            startActivity(i);
            break;
        }

    }
}

}

Your activity is not implementing View.OnClickListener . 您的活动未实现View.OnClickListener Unless you implement View.OnClickListener on your activity you cannot cast the activity as an OnClickListener. 除非您在活动上实现View.OnClickListener ,否则无法将活动转换为OnClickListener。 That is why you are getting error, probably a ClassCastException 这就是为什么会出现错误的原因,可能是ClassCastException

 btnPatient.setOnClickListener((View.OnClickListener) this);
    btnDoctor.setOnClickListener((View.OnClickListener) this);
    btnGuest.setOnClickListener((View.OnClickListener) this);

implement View.OnClickListener on your activity. 在您的活动上实现View.OnClickListener Change 更改

public class RoleActivity extends AppCompatActivity

to

public class RoleActivity extends AppCompatActivity implements View.OnClickListener 

and then you can remove that casting 然后您可以删除该演员表

btnPatient.setOnClickListener(this);
btnDoctor.setOnClickListener(this);
btnGuest.setOnClickListener(this);

if you are not implemeting View.OnClickListener on your activity you can add the click listener as an anonymous inner class to handle clicks on views 如果您未在活动中实现View.OnClickListener ,则可以将Click侦听器添加为匿名内部类,以处理对View的单击

implement onClickListner in RoleActivity class and change code to 在RoleActivity类中实现onClickListner并将代码更改为

btnPatient.setOnClickListener( this);
btnDoctor.setOnClickListener(this);
btnGuest.setOnClickListener(this);

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

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