I'm trying to create a simple flashlight app in order to learn android development. I'm trying to get it so that when when you click on the light ImageView object it changes the image. However right now it crashes when the debugger gets to light.setImageResource().
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
public class flash extends ActionBarActivity {
public Boolean on = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flash);
ImageView light = (ImageView) findViewById(R.id.light);
light.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
ImageView light = (ImageView) findViewById(R.id.light);
if(on){
light.setImageResource(R.drawable.flash_off);
on = false;
}else{
light.setImageResource(R.drawable.flash_on);
on = true;
}
}
});
}
@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_flash, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The error it's throwing is
--------- beginning of crash
01-18 14:05:27.675 1953-1953/com.peterchappy.openflash E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.peterchappy.openflash, PID: 1953
java.lang.OutOfMemoryError: Failed to allocate a 51840012 byte allocation with 4194304 free bytes and 13MB until OOM