unfortunately my app has stopped (my first app in android)

user3348242

this is my first .... i try to search the problem in this website but i did not fix it

this is my code in main activity

package com.example.joker;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.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.widget.Button;
import android.widget.ImageButton;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
Button b=(Button)findViewById(R.id.button1);
b.setText("why so serious ?");

        if (savedInstanceState == null) {
            getSupportFragmentManager().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.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();
        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_main, container, false);
            return rootView;
        }
    }

}

and this fregment

<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:gravity="top"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.joker.MainActivity$PlaceholderFragment" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="102dp"
        android:layout_marginLeft="58dp"
        android:text="@string/b" />

</RelativeLayout>

....... i confide in your to help to fix the problem by the way >>>what is difference between fregment.xml and activity.xml ?

Raghunandan

The button belongs to the fragment layout

So remove the initialization of button in Activity and move it to fragment onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        Button b=(Button)rootView.findViewById(R.id.button1);
        b.setText("why so serious ?");
        return rootView;
 }

what is difference between fregment.xml and activity.xml ?

Both are xml layouts. One is set to the activity setContentView(R.layout.activity_main); and the other you inflate in fragment View rootView = inflater.inflate(R.layout.fragment_main, container, false);. There is no difference.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unfortunately my app has stopped in Android Emulator

From Dev

“Unfortunately My Android App has stopped”

From Dev

Android Studio: Unfortunately "my App" has stopped

From Dev

Unfortunately my app has stopped in Android Emulator

From Dev

My app has unfortunately stopped

From Dev

Android Studio error: Unfortunately My Own App has stopped

From Dev

Unfortunately my app has stopped working

From Dev

My android login app unfortunately stopped

From Dev

Android : Unfortunately, app has stopped

From Dev

android app unfortunately has stopped

From Dev

Android Studio : When ever i run my app, it says Unfortunately app has stopped

From Dev

Starting my very first app in the emulator results in "unfortunately, AppName has stopped"

From Dev

Android App Unfortunately App has stopped

From Dev

Android SQL app unfortunately app has stopped

From Dev

Unfortunately App Has Stopped

From Dev

my first app has stopped working error

From Dev

my application keeps receiving "Unfortunately "My App" has stopped" after Running the app

From Dev

Android Emulator: Unfortunately App has stopped

From Dev

Unfortunately app has stopped working android emulator

From Dev

Unfortunately, APP has stopped - Android Twitter Client

From Dev

Unfortunately "App" has Stopped Android Studio

From Dev

Unfortunately the app has stopped working error in Android

From Dev

Unfortunately (app) has stopped android developer error

From Dev

Android Emulator: Unfortunately App has stopped

From Dev

Android unfortunately app has stopped admob

From Dev

how solve "unfortunately android app has stopped"

From Dev

Unfortunately App has stopped (Android Studio)

From Dev

Android studio error: Unfortunately “App” has Stopped

From Dev

Android Studio: Unfortunately, app has stopped

Related Related

  1. 1

    Unfortunately my app has stopped in Android Emulator

  2. 2

    “Unfortunately My Android App has stopped”

  3. 3

    Android Studio: Unfortunately "my App" has stopped

  4. 4

    Unfortunately my app has stopped in Android Emulator

  5. 5

    My app has unfortunately stopped

  6. 6

    Android Studio error: Unfortunately My Own App has stopped

  7. 7

    Unfortunately my app has stopped working

  8. 8

    My android login app unfortunately stopped

  9. 9

    Android : Unfortunately, app has stopped

  10. 10

    android app unfortunately has stopped

  11. 11

    Android Studio : When ever i run my app, it says Unfortunately app has stopped

  12. 12

    Starting my very first app in the emulator results in "unfortunately, AppName has stopped"

  13. 13

    Android App Unfortunately App has stopped

  14. 14

    Android SQL app unfortunately app has stopped

  15. 15

    Unfortunately App Has Stopped

  16. 16

    my first app has stopped working error

  17. 17

    my application keeps receiving "Unfortunately "My App" has stopped" after Running the app

  18. 18

    Android Emulator: Unfortunately App has stopped

  19. 19

    Unfortunately app has stopped working android emulator

  20. 20

    Unfortunately, APP has stopped - Android Twitter Client

  21. 21

    Unfortunately "App" has Stopped Android Studio

  22. 22

    Unfortunately the app has stopped working error in Android

  23. 23

    Unfortunately (app) has stopped android developer error

  24. 24

    Android Emulator: Unfortunately App has stopped

  25. 25

    Android unfortunately app has stopped admob

  26. 26

    how solve "unfortunately android app has stopped"

  27. 27

    Unfortunately App has stopped (Android Studio)

  28. 28

    Android studio error: Unfortunately “App” has Stopped

  29. 29

    Android Studio: Unfortunately, app has stopped

HotTag

Archive