1 Replies - 491 Views - Last Post: 15 June 2017 - 06:28 AM

#1 manideep123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-June 17

Getting an error as unfortunately your app stoped

Posted 15 June 2017 - 01:09 AM

I am learning the android, i got an error in android emulator that app is unfortunately closed.
I was helpless will you please help to solve the problem.

// HERE IS MY JAVA CODE
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Display;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

    @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.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        RelativeLayout main_view = (RelativeLayout) findViewById(R.id.main_view);

        switch (item.getItemId())
        {
            case R.id.menu_red:
                       if(item.isChecked())
                           item.setChecked(false);

                       else
                           item.setChecked(true);
                main_view.setBackgroundColor(Color.RED);
                return true;

            case R.id.menu_blue:
                  if(item.isChecked())
                    item.setChecked(false);


                else
                    item.setChecked(true);
                main_view.setBackgroundColor(Color.BLUE);
                return true;

            case R.id.menu_green:
                if(item.isChecked())
                    item.setChecked(false);

                else
                    item.setChecked(true);
                main_view.setBackgroundColor(Color.GREEN);
                return true;

            default:return super.onOptionsItemSelected(item);
        }
    }
}
:code:

This post has been edited by modi123_1: 15 June 2017 - 06:27 AM
Reason for edit:: In the future, please use the [code] tag button in the editor..


Is This A Good Question/Topic? 0
  • +

Replies To: Getting an error as unfortunately your app stoped

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13482
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: Getting an error as unfortunately your app stoped

Posted 15 June 2017 - 06:28 AM

Please copy/paste your errors here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1