我是Android开发尝试启动新活动的新手。当按钮onclick在注册按钮上点击时,新活动启动,我能够完成我需要的所有内容。但是,当我尝试启动菜单活动时,应用程序崩溃了。我看了,活动是在android清单文件中。
非常感谢任何帮助。
android清单文件
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Register"
android:label="@string/title_activity_register"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Menu"
android:label="@string/title_activity_menu"
android:theme="@style/AppTheme.NoActionBar"/>
</application>
MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText usernameEt, passwordEt;
//String JSON_STRING;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
usernameEt = (EditText)findViewById(R.id.etUserName);
passwordEt = (EditText)findViewById(R.id.etPassword);
}
public void OnLogin(View view) {
String username = usernameEt.getText().toString();
String password = passwordEt.getText().toString();
String type = "login";
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
backgroundWorker.execute(type, username, password);
}
public void OpenReg(View view){
startActivity(new Intent(this, Register.class));
}
public void mainMenu(View view){
startActivity(new Intent(this, Menu.class));
}
以下是两个按钮的代码
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:id="@+id/btn_reg"
android:onClick="OpenReg"
android:layout_below="@+id/btnLogin"
android:layout_alignLeft="@+id/btnLogin"
android:layout_alignStart="@+id/btnLogin"
android:layout_marginTop="103dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="main menu"
android:id="@+id/btn_menu"
android:onClick="mainMenu"
android:layout_alignTop="@+id/btn_reg"
android:layout_toRightOf="@+id/etPassword"
android:layout_toEndOf="@+id/etPassword" />
这是堆栈轨道
03-28 12:25:19.533: D/TaskPersister(1232): removeObsoleteFile: deleting file=167_task_thumbnail.png
03-28 12:25:34.101: I/ActivityManager(1232): START u0 {cmp=com.example.dancastillo.mysqldemo/android.view.Menu} from uid 10059 on display 0
03-28 12:25:34.102: D/AndroidRuntime(11715): Shutting down VM
03-28 12:25:34.102: E/AndroidRuntime(11715): FATAL EXCEPTION: main
03-28 12:25:34.102: E/AndroidRuntime(11715): Process: com.example.dancastillo.mysqldemo, PID: 11715
03-28 12:25:34.102: E/AndroidRuntime(11715): java.lang.IllegalStateException: Could not execute method for android:onClick
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.view.View.performClick(View.java:4780)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.view.View$PerformClick.run(View.java:19866)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.os.Handler.handleCallback(Handler.java:739)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.os.Handler.dispatchMessage(Handler.java:95)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.os.Looper.loop(Looper.java:135)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.ActivityThread.main(ActivityThread.java:5254)
03-28 12:25:34.102: E/AndroidRuntime(11715): at java.lang.reflect.Method.invoke(Native Method)
03-28 12:25:34.102: E/AndroidRuntime(11715): at java.lang.reflect.Method.invoke(Method.java:372)
03-28 12:25:34.102: E/AndroidRuntime(11715): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
03-28 12:25:34.102: E/AndroidRuntime(11715): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
03-28 12:25:34.102: E/AndroidRuntime(11715): Caused by: java.lang.reflect.InvocationTargetException
03-28 12:25:34.102: E/AndroidRuntime(11715): at java.lang.reflect.Method.invoke(Native Method)
03-28 12:25:34.102: E/AndroidRuntime(11715): at java.lang.reflect.Method.invoke(Method.java:372)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
03-28 12:25:34.102: E/AndroidRuntime(11715): ... 10 more
03-28 12:25:34.102: E/AndroidRuntime(11715): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.dancastillo.mysqldemo/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.Activity.startActivityForResult(Activity.java:3745)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.Activity.startActivityForResult(Activity.java:3706)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.Activity.startActivity(Activity.java:4016)
03-28 12:25:34.102: E/AndroidRuntime(11715): at android.app.Activity.startActivity(Activity.java:3984)
03-28 12:25:34.102: E/AndroidRuntime(11715): at com.example.dancastillo.mysqldemo.MainActivity.mainMenu(MainActivity.java:69)
03-28 12:25:34.102: E/AndroidRuntime(11715): ... 13 more
03-28 12:25:34.103: W/ActivityManager(1232): Force finishing activity 1 com.example.dancastillo.mysqldemo/.MainActivity
03-28 12:25:34.107: W/AudioTrack(1232): AUDIO_OUTPUT_FLAG_FAST denied by client
03-28 12:25:34.114: D/(1232): HostConnection::get() New Host Connection established 0xa331c750, tid 1706
03-28 12:25:34.131: E/EGL_emulation(931): tid 931: eglCreateSyncKHR(1288): error 0x3004 (EGL_BAD_ATTRIBUTE)