0

我想从登录活动切换......我有所有的表格,但是当我点击按钮时......它会强制关闭。

这是我的代码。

头等舱

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);

}

}

原木猫:

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)
4

2 回答 2

1
if("12345".contentEquals(pass.getText().toString()))

AND

final Intent myIntent = new Intent(MainActivity.this, Menu.class);

Try this?

于 2012-12-21T22:56:38.173 回答
1

From your LogCat:

Unable to find explicit activity class {com.example.pizzasjaps/android.view.Menu}

This line is trying to load the class android.view.Menu instead of your Menu Activity:

final Intent myIntent = new Intent(getApplicationContext(), Menu.class);

Scope Menu to the appropriate class (and consider using this instead of getApplicationContext()):

final Intent myIntent = new Intent(this, com.example.pizzasjaps.Menu.class);
于 2012-12-21T22:57:33.780 回答