我想从登录活动切换...我有所有表格但是当我点击按钮时......它会强行关闭。
这是我的代码。
头等舱
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText pass = (EditText)findViewById(R.id.editText1);
final Intent myIntent = new Intent(getApplicationContext(), Menu.class);
String mydate = java.text.DateFormat.getDateInstance().format(Calendar.getInstance().getTime());
TextView fecha = (TextView)findViewById(R.id.textView2);
fecha.setText(mydate);
Button next = (Button) findViewById(R.id. button1);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if("12345".equals(pass.getText().toString())) {
//Toast.makeText(getApplicationContext(), "Clave Correcta", Toast.LENGTH_SHORT).show();
startActivity(myIntent);
}
else {
Toast.makeText(getApplicationContext(), "Clave Incorrecta", Toast.LENGTH_SHORT).show();
}
}
});
}
二等。
public class Menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
}
}
Log Cat:
12-21 17:04:53.710: E/Trace(2389): error opening trace file: No such file or directory (2)
12-21 17:04:57.680: E/AndroidRuntime(2389): FATAL EXCEPTION: main
12-21 17:04:57.680: E/AndroidRuntime(2389): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.pizzasjaps/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.Activity.startActivityForResult(Activity.java:3351)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.Activity.startActivityForResult(Activity.java:3312)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.Activity.startActivity(Activity.java:3522)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.Activity.startActivity(Activity.java:3490)
12-21 17:04:57.680: E/AndroidRuntime(2389): at com.example.pizzasjaps.MainActivity$1.onClick(MainActivity.java:39)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.view.View.performClick(View.java:4084)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.view.View$PerformClick.run(View.java:16966)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.os.Handler.handleCallback(Handler.java:615)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.os.Looper.loop(Looper.java:137)
12-21 17:04:57.680: E/AndroidRuntime(2389): at android.app.ActivityThread.main(ActivityThread.java:4906)
12-21 17:04:57.680: E/AndroidRuntime(2389): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 17:04:57.680: E/AndroidRuntime(2389): at java.lang.reflect.Method.invoke(Method.java:511)
12-21 17:04:57.680: E/AndroidRuntime(2389): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-21 17:04:57.680: E/AndroidRuntime(2389): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-21 17:04:57.680: E/AndroidRuntime(2389): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
if("12345".contentEquals(pass.getText().toString()))
和
final Intent myIntent = new Intent(MainActivity.this, Menu.class);
试试这个?
答案 1 :(得分:1)
从您的LogCat:
Unable to find explicit activity class {com.example.pizzasjaps/android.view.Menu}
此行正在尝试加载课程android.view.Menu
,而不是您的菜单活动:
final Intent myIntent = new Intent(getApplicationContext(), Menu.class);
范围Menu
到相应的类(并考虑使用this
代替getApplicationContext()
):
final Intent myIntent = new Intent(this, com.example.pizzasjaps.Menu.class);