[英]Login successful but unable to open the next activity
我無意中成功登錄。 但是,當我添加客戶活動意圖時,它在嘗試登錄時給了我一個強制關閉錯誤。 我有一個5差異的列表視圖。 customer.java內的所有活動都可以正常打開。 我想知道為什么登錄出現錯誤
Login.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends Activity {
private EditText etUsername;
private Button btnLogin;
private Button btnCancel;
private TextView lblResult;
/** Called when the activity is first created. */
//@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
etUsername = (EditText)findViewById(R.id.username);
btnLogin = (Button)findViewById(R.id.login_button);
btnCancel = (Button)findViewById(R.id.cancel_button);
lblResult = (TextView)findViewById(R.id.result);
btnLogin.setOnClickListener(new OnClickListener() {
//@Override
public void onClick(View v) {
// Check Login
String username = etUsername.getText().toString();
if(username.equals("guest")){
lblResult.setText("Login successful.");
Intent i = new Intent("com.merrill.Customer");
startActivity(i);
} else {
lblResult.setText("Login failed. Username doesn't match.");
}
}
});
btnCancel.setOnClickListener(new OnClickListener() {
//@Override
public void onClick(View v) {
// Close the application
finish();
}
});
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.royalcabinets.merrill"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Login"
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="com.merrill.Customer"
android:label="Customer Service Group">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
請參閱Ronnie的回復或
Intent i= new Intent(Login.this, Customer.class);
要么
Intent i= new Intent(this, Customer.class);
要么
Intent i = new Intent(getApplicationContext(), Customer.class);
和
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.royalcabinets.merrill"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Login"
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="Customer"
android:label="Customer Service Group">
</activity>
</application>
</manifest>
您的問題在於您的應用有兩個入口點。 Manifest
應該只標有android.intent.action.MAIN
的intent-filter
動作的Activity
。
除此之外,我仍然覺得您的代碼中可能還有其他問題的根源。 我建議您啟動ddms
工具。 [轉到終端/命令提示符並執行android-sdk\\tools
文件夾中的ddms.bat
文件]。 設置一個過濾器以打印Errors
,您會發現一些有意義的消息。
發布該帖子,我們可以繼續進行-也就是說,如果刪除多余的MAIN
Activity
不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.