Android Navigation

I am very new to Android development and I am working on an application in which I have 4 actions. Each action should be able to go to any of the other 3. Therefore, I created 4 buttons at the top of each action that allow this. The XML code is as follows:

<Button ... android:onClick="loadProfileLayout"/> <Button ... android:onClick="loadRulesLayout"/> <Button ... android:onClick="loadSettingsLayout"/> <Button ... android:onClick="loadHelpLayout"/> 

the manifest has an activity tag for each:

  <activity android:name=".Profiler" 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="Rules"></activity> <activity android:name="Settings"></activity> <activity android:name="Help"></activity> 

And the called functions:

 public void loadProfileLayout() { startActivity(new Intent(this, Profiler.class)); } public void loadRulesLayout(View v) { startActivity(new Intent(this, Rules.class)); } public void loadSettingsLayout(View v) { startActivity(new Intent(this, Settings.class)); } public void loadHelpLayout(View v) { startActivity(new Intent(this, Help.class)); } 

So, this initially works. From the main activity "Profile" I can go to any of the others. And from the other 3 I can move anywhere, but back to the main one. When I click the main activity button, the application crashes. I am trying to debug, but not even performing loadProfileLayout (). Eclipse opens the file "View.class" with the contents basically "Source not found." If I press F8 to continue debugging, it will load "ZygoteInit $ MethodAndArgsCaller.run ()" ... again, "Source not found." Pressing F8 will load the error message again into the emulator "Sorry! The application has stopped unexpectedly. Please try again."

Again, I'm new to Android, and all I know about activity is what I read on the dev website. Am I making a fundamental mistake here that I don't know about?

Thanks,
Nat

+4
source share
1 answer

I'm not sure if this was a typo in your question, but loadProfileLayout() should also use View as the only parameter:

 public void loadProfileLayout(View v) 

Change The View parameter is the view that onClick event (in your case, the Button instance). I did not look at the code, but I assume that View uses reflection to find a method to call (in particular, one that takes the form as an argument), and since it does not find a suitable method, it decides to throw an exception.

+4
source

All Articles