I am writing an android app and am trying to start an activity from a button
The button calls the function startDb(), which is supposed to start the DB_manager activity.
The code and LogCat are shown below:
public class MainActivity extends Activity {
public void Main(){
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void startDb() {
Intent activity1 = new Intent(getApplicationContext(), DB_manager.class);
startActivity(activity1);
//finish();
}
}
It gives the following error:
07-03 13:11:26.525: E/AndroidRuntime(19273): FATAL EXCEPTION: main
07-03 13:11:26.525: E/AndroidRuntime(19273): java.lang.IllegalStateException: Could not
find a method startDb()(View) in the activity class com.example.quiz.MainActivity for
onClick handler on view class android.widget.Button with id 'edit_db'
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.view.View$1.onClick(View.java:3647)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.view.View.performClick(View.java:4162)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.view.View$PerformClick.run(View.java:17082)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.os.Handler.handleCallback(Handler.java:615)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.os.Looper.loop(Looper.java:137)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.app.ActivityThread.main(ActivityThread.java:4856)
07-03 13:11:26.525: E/AndroidRuntime(19273): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 13:11:26.525: E/AndroidRuntime(19273): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 13:11:26.525: E/AndroidRuntime(19273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
07-03 13:11:26.525: E/AndroidRuntime(19273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
07-03 13:11:26.525: E/AndroidRuntime(19273): at dalvik.system.NativeStart.main(Native Method)
07-03 13:11:26.525: E/AndroidRuntime(19273): Caused by: java.lang.NoSuchMethodException: startDb() [class android.view.View]
07-03 13:11:26.525: E/AndroidRuntime(19273): at java.lang.Class.getConstructorOrMethod(Class.java:460)
07-03 13:11:26.525: E/AndroidRuntime(19273): at java.lang.Class.getMethod(Class.java:915)
07-03 13:11:26.525: E/AndroidRuntime(19273): at android.view.View$1.onClick(View.java:3640)
07-03 13:11:26.525: E/AndroidRuntime(19273): ... 11 more