It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
This is the coding for my application, and I am using Eclipse.
DisplayMessageActivity.java
package com.example.myfirstapp;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
#SuppressLint("NewApi") public class DisplayMessageActivity extends Activity
{
#SuppressLint("NewApi") #Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
//Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
//Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
//Set the text view
setContentView(textView);
}
// OKAY TO REMOVE
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_display_message, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
MyFirstAppManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" android:debuggable="true">
<activity
android:name="com.example.myfirstapp.MainActivity"
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="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
MainActivity.java
package com.example.myfirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity
{
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#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.activity_main, menu);
return true;
}
/** Called when the user clicks the Send button */
public void sendMessage (View view)
{
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
If you need more information or debug results, please let me know. I am following the Android Developer Tutorial located here.
Without the LogCat, I can address one problem with your code. #SuppressLint("NewApi"). Lint makes a good point - your target API is 8. Froyo and Gingerbread don't have an Action Bar.
Now, in DisplayMessageActivity make a method like this:
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
Now take this line out of your code in DisplayMessageActivity
getActionBar().setDisplayHomeAsUpEnabled(true);
and replace it with
setupActionBar();
That way Android checks the API version and if it is below HoneyComb's does not call the getActionBar() method which does not exist on Gingerbread.
Related
I am new to the Android development app. I was following the tutorials given in the official site. So far everything was good but when I started to create and modify the action bar, this error started to arise:
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Main AndroidManifest.xml at AndroidManifest.xml manifest:package attribute is not declared
My manifest file is this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="14"/>
package="com.mycompany.myfirstapp" >
<application>
<!-- The/main activity (it has no parent activity) -->
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<activity
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="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.hpcore.myfirstapp.MyActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.hpcore.myfirstapp.MyActivity" />
</activity>
</application>
</manifest>
And my main activity Java code is this:
package com.example.hpcore.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import com.mycompany.myfirstapp.DisplayMessageActivity;
public class MyActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE= "com.hp core.myfirstapp.MESSAGE";
public void sendMessage(View view)
{
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE,message);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_displaymessage);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_Activity_actions,menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId())
{
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
I guess the problem in one of these files.
You package attribute should be part of Manifest Tag-
Change your manifest Tag like below-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myfirstapp" >
<uses-sdk android:minSdkVersion="14"/>
I'm writing simple tutorial app and for some reason my App icon is not showing up (I want to use it as navigate up button instead of the arrow).
As stated in the topic, I want to do it on Api level 11, however all the sollutions I've found rely on setIcon method.
getActionBar().setIcon(R.drawable.ic_launcher); //only on API >= 14
The fragment preview in Android studio 1.0.2 does show the icon, however the emulator does not, so I'd expect the resource is ok. Also, the search and delete icons are working like a charm. I've tried setting this both as Icon and a logo to no avail.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yamba"
android:versionCode="1"
android:versionName="1.0"
>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:logo="#drawable/ic_launcher"
>
<activity
android:parentActivityName=".MainActivity"
android:name=".StatusActivity"
android:label="#string/app_name" >
</activity>
<!--- The labe is what's displayed at the taskbar!-->
<activity
android:parentActivityName=".MainActivity"
android:name=".SettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_settings.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.yamba.SettingsActivity">
<TextView android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
menu_settings.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.yamba.SettingsActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
SettingsActivity.java
package com.example.yamba;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SettingsActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null){
SettingsFragment fragment = new SettingsFragment();
getFragmentManager().beginTransaction().add(android.R.id.content, fragment, fragment.getClass().getSimpleName()).commit();
setContentView(R.layout.activity_settings);
// getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
// only for API>=14
// getActionBar().setDisplayShowHomeEnabled(true);
// getActionBar().setIcon(R.drawable.ic_launcher);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.menu_settings, menu);
// return true;
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch(id){
case R.id.action_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
case R.id.action_tweet:
startActivity(new Intent(this, com.example.yamba.StatusActivity.class));
return true;
default:
return false;
}
}
}
SettingsFragment.java
package com.example.yamba;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
/**
* Created by me on 19-01-2015.
*/
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences prefs;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
public void onStart(){
super.onStart();
prefs= PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(this);
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
}
}
I've stumbled upon suggestion that I may be able to define custom style based on one of the existing styles, but can't quite figure out how to approach it.
If you need any other file, let me know and thanks for your time.
since it's API 11..
did you try using the support libraries?
try switching
getActionBar().setIcon(R.drawable.ic_launcher);
with :
getSupportActionBar().setIcon(R.drawable.ic_launcher);
tell me if it works and we'll continue from there :)
The scenario I have consists of 3 activities:
1- Homepage
2-Login
3-Register
The thing is now Home page has 2 buttons one login and one for homepage , and the login activity should be called from either this button or from inside register after I am done registering ,also both login and register activities inflate 2 different fragments.
The problem : Login activity doesnt start , instead it sometimes just blinks with the layout it should inflate for a split second and then backs to the previous activity whichever one it is , also when I replaced the login activity with another activity it started normally with no problems
Any idea what that might be.
NOTE: I'm not getting any errors or so
Signin Activity code:
package engezni.Activties;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;
import Fragments.SigninFragment;
import engezni.Activties.R;
public class SignInScreen extends Activity {
FrameLayout frameLayout;
SigninFragment signinFragment;
TextView signinScreen;
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in_screen);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getActionBar().setCustomView(R.layout.custom_action_bar);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
/*Setting text to the textview in the xml actionbar layout */
signinScreen = (TextView) findViewById(R.id.actionbarTitleOrderScreen);
signinScreen.setText("Sign In");
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
getActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.backlogo));
frameLayout=(FrameLayout)findViewById(R.id.signin_framelayout);
signinFragment=new SigninFragment();
if (findViewById(R.id.signin_framelayout) != null) {
if (savedInstanceState != null) {
return;
}
signinFragment.setArguments(getIntent().getExtras());
getFragmentManager().beginTransaction().add(R.id.signin_framelayout, signinFragment).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sign_in_screen, menu);
onBackPressed();
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And then here is the manifest
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen" >
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeScreen"
android:label="#string/title_activity_home_screen"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".SignInScreen"
android:label="#string/title_activity_sign_in_screen"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".RegisterScreen"
android:label="#string/title_activity_register_screen"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".MyActivity"
android:label="#string/title_activity_my" >
</activity>
</application>
Problem:
getMenuInflater().inflate(R.menu.sign_in_screen, menu);
onBackPressed();
When the onCreateOptionsMenu is called that is where you go back to the last activity because you called onBackPressed which will destroy your current activity.
solution:
remove the onBackPressed
For my project I have to have two .java classes and two .xml files. The first one that I have created is SplashActivity.java. After I have created that class, put some code in there, and worked with my activity_splash.xml. I needed to create the MainActivity.java class. I went into the
AndroidManifest.xml -> Application -> Add -> Actiivity. Name ->
.MainActivity
In my MainActivity.java class I write an onCreate() method to create the activity_main.xml. However, my eclipse emulator underlines the activity_main with a red underline. When I move my mouse to it, it gives me several options "Create filed "activity_main" in type layout", "Create constant "activity_main" in type layout". I am not sure which ones of those are correct way to fix the issue that's why I decided not to mess with R.java. But I am confused why I have that error because as far as I am concerned my code is correct.
The following are the codes:
SplashActivity.java
package com.example.easternmusic;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class SplashActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
TimerTask task = new TimerTask() {
#Override
public void run() {
// TODO Auto-generated method stub
finish();
startActivity(new
Intent(SplashActivity.this,MainActivity.class));
}
};
Timer opening = new Timer ();
opening.schedule(task, 5000);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.splash, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_splash,
container, false);
return rootView;
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.easternmusic"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.easternmusic.SplashActivity"
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=".MainActivity"></activity>
</application>
</manifest>
MainActivity.java
package com.example.easternmusic;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Each activity consist of a layout(xml file) and a java class. Here you create the class MainActivity but you forget to add layout of the activity i.e xml file.when you write this setContentView(R.layout.activity_main);. its mean you are setting layout here.Activity_main is the name of the layout file.which you dont add in your layout folder. So the answer to this question is go to your layout folder and add xml file with name activity_main. Your problem will be solved.
I have looked through these forums to find a solution to this problem, and even though there appear to be solutions, none of them seem to be working for me. So here goes.
I am a newbie to Android development. I have an app with an options menu. When I click on one to the options, I want it to launch a new activity - but I keep getting the error
Intent cannot be resolved to a type
in home.java on the line:
Intent intent = new Intent(this, about.class);
Below is all of my code that I believe is relevant. Please let me know if you need to see anything else. As I said, I have tried to follow other questions, but none of them seem to work for me (as-in the below code seems to work for everyone else). Any help would be awesome.
I have my menu defined in res/menu/main_menu.xml by:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/home"
android:icon="#drawable/ic_menu_home"
android:title="#string/home" />
<item android:id="#+id/about"
android:icon="#drawable/ic_menu_about"
android:title="#string/about" />
</menu>
I have two activities - home.java and about.java. Home.java is the activity that is launched when the app is launched and is shown below.
package ca.example.home;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class home extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.home:
return true;
case R.id.about:
Intent intent = new Intent(this, about.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
About.java is the new activity to be launched and is shown below:
package ca.brianmccain.nbla;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
public class about extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
}
I have changed the manifest to:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.example.home"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".home"
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=".about">
</activity>
</application>
</manifest>
You have to import the intent class.
import android.content.Intent;
If you ever get a similar error, and if you are using eclipse,
press Ctrl-Shift-O ("Organize imports") - this searches for all required imports and adds them to the file.
I just solved my menu problem. The menu page would open but when I clicked on an individual menu option it would not proceed to the next page / activity.
It was all due to a simple addition of a "space" right at the end of the statement after the "." just before the +cheese I deleted the space and it worked.
BEFORE
Class ourClass = Class.forName("com.example.androidtutorial2. " +cheese);
AFTER
Class ourClass = Class.forName("com.example.androidtutorial2." +cheese);