Welcome to the Android Central Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 1 of 1
  1. Thread Author  Thread Author    #1  

    Default ANDROID Studio crashes

    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!

Similar Threads

  1. How can I post reviews in Android apps?
    By accactg in forum Android Central Apps
    Replies: 2
    Last Post: 03-13-2014, 08:54 AM
  2. Galaxy S4: Android Battery Built-In Monitoring Tool Question
    By stormage in forum Samsung Galaxy S4
    Replies: 1
    Last Post: 03-07-2014, 01:59 PM
  3. Changing Android version to another!
    By TariqOthman in forum General Help and How To
    Replies: 0
    Last Post: 03-07-2014, 11:52 AM
  4. Android encryption question(s)
    By Why Why See in forum General Help and How To
    Replies: 0
    Last Post: 03-07-2014, 11:38 AM
  5. Android Battery Built-In Monitoring Tool Question
    By stormage in forum General Help and How To
    Replies: 2
    Last Post: 03-07-2014, 11:01 AM

Posting Permissions