i am working as a beginner on new android application, i have done everything according to the tutorials, but im still getting this error. here is the code for MyAcitivty.java:
this is MYActivity.java
package com.example.ambuj.myfirstapp;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MyActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.example.ambuj.myfirstapp";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
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 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);
}
}
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);
}
public void openSearch(){
Toast.makeText(this, "Search Button Pressed", Toast.LENGTH_LONG).show();
}
public void openSettings(){
Toast.makeText(this, "Settings Button Pressed",Toast.LENGTH_LONG).show();
}
}
this is my logcat:
01-18 14:22:33.180 26194-26194/com.example.ambuj.myfirstapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.ambuj.myfirstapp, PID: 26194
java.lang.StackOverflowError
at android.util.SparseArray.get(SparseArray.java:111)
at android.util.SparseArray.get(SparseArray.java:102)
at android.content.res.StringBlock.get(StringBlock.java:70)
at android.content.res.AssetManager.getPooledString(AssetManager.java:275)
at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:730)
at android.content.res.TypedArray.getText(TypedArray.java:97)
at android.support.v7.internal.view.SupportMenuInflater$MenuState.readItem(SupportMenuInflater.java:374)
at android.support.v7.internal.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:168)
at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)
at com.example.ambuj.myfirstapp.MyActivity.onCreateOptionsMenu(MyActivity.java:32)
at com.example.ambuj.myfirstapp.MyActivity.onCreateOptionsMenu(MyActivity.java:33)
Yout problem is here:
@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 onCreateOptionsMenu(menu); //<--- conflicting line
}
Change
return onCreateOptionsMenu(menu);
to
return true;
Hope it helps