ANDROID Studio crashes

Mar 7, 2014
1
0
0
Visit site
Guys I need help again.. why the hell Android Studio always crashes??? Im trying to change the imageView whenever I click but when I wrote a code it won't go all the way, it just crashes.. HELP!

.java code:
Code:
package com.example.app;

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.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.ImageView;

public class mio extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mio);

        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.mio, 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_mio, container, false);
            return rootView;
        }
    }

    Button button;
    ImageView image;

    public void addButtonListener() {
        image = (ImageView) findViewById(R.id.mio);
        button = (Button) findViewById(R.id.pet);
        button.setOnClickListener(new View.OnClickListener() {
            @Override

            public void onClick(View view) {

                image.setImageResource(R.drawable.mio2);

            }
        });


    }
}

.xml code
Code:
<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.app.mio$PlaceholderFragment">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pet"
        android:id="@+id/pet"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:minHeight="50dp"
        android:minWidth="100dp"
        android:clickable="true"
        android:enabled="true"
        android:onClick="addButtonListener" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sleep"
        android:id="@+id/sleep"
        android:minHeight="50dp"
        android:minWidth="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:clickable="true"
        android:enabled="true" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Talk"
        android:id="@+id/talk"
        android:minHeight="50dp"
        android:minWidth="100dp"
        android:layout_alignTop="@+id/sleep"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:clickable="true"
        android:enabled="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mio"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/mio1"
        android:clickable="true"
        android:focusableInTouchMode="true" />
</RelativeLayout>

thanks in advance! :)
 

Forum statistics

Threads
945,120
Messages
6,924,255
Members
3,159,668
Latest member
smmF14F2