Xin mọi người giúp em giải quyết lỗi này với ạ.
Đây kà lỗi ạ
12-27 13:57:20.060 14291-14291/hn.bk.nguyenbaongoc.trangngoc E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: hn.bk.nguyenbaongoc.trangngoc, PID: 14291
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2192)
at android.content.res.Resources.loadDrawable(Resources.java:2075)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:129)
at android.widget.ImageButton.<init>(ImageButton.java:87)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:59)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:55)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:107)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at hn.bk.nguyenbaongoc.trangngoc.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Đây là layout của em ạ:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/hienThi"
android:layout_width="280dp"
android:layout_height="100dp"
android:padding="8dp"
android:text=""
android:textSize="60sp" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="80dp"
android:layout_height="100dp"
android:onClick="xoa"
android:scaleType="centerCrop"
android:src="@drawable/xoa1" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button1"
android:scaleType="centerCrop"
android:src="@drawable/so1" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button2"
android:scaleType="centerCrop"
android:src="@drawable/so2" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button3"
android:scaleType="centerCrop"
android:src="@drawable/so3" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="cong"
android:scaleType="centerCrop"
android:src="@drawable/cong" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button4"
android:scaleType="centerCrop"
android:src="@drawable/so4" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button5"
android:scaleType="centerCrop"
android:src="@drawable/so5" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button6"
android:scaleType="centerCrop"
android:src="@drawable/so6" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="tru"
android:scaleType="centerCrop"
android:src="@drawable/tru" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button7"
android:scaleType="centerCrop"
android:src="@drawable/so7" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button8"
android:scaleType="centerCrop"
android:src="@drawable/so8" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button9"
android:scaleType="centerCrop"
android:src="@drawable/so9" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="nhan"
android:scaleType="centerCrop"
android:src="@drawable/nhan" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button7"
android:scaleType="centerCrop"
android:src="@drawable/so7" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button8"
android:scaleType="centerCrop"
android:src="@drawable/so8" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="button9"
android:scaleType="centerCrop"
android:src="@drawable/bang" />
<ImageButton
android:layout_width="90dp"
android:layout_height="100dp"
android:onClick="chia"
android:scaleType="centerCrop"
android:src="@drawable/chia" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:onClick="buttonReset"
android:text="Khởi động lại" />
</LinearLayout>
</LinearLayout>
code đây ạ:
package hn.bk.nguyenbaongoc.trangngoc;
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.TextView;
public class MainActivity extends ActionBarActivity {
@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) {
// 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);
}
int a, b, x = 1;
String so1 = "";
String so2 = "";
public void button1(View view) {
if (x == 1) {
so1 = so1 + "1";
hienThi();
} else {
so2 = so2 + "1";
hienThi();
}
}
public void button2(View view) {
if (x == 1) {
so1 = so1 + "2";
hienThi();
} else {
so2 = so2 + "2";
hienThi();
}
}
public void button3(View view) {
if (x == 1) {
so1 = so1 + "3";
hienThi();
} else {
so2 = so2 + "3";
hienThi();
}
}
public void button4(View view) {
if (x == 1) {
so1 = so1 + "4";
hienThi();
} else {
so2 = so2 + "4";
hienThi();
}
}
public void button5(View view) {
if (x == 1) {
so1 = so1 + "5";
hienThi();
} else {
so2 = so2 + "5";
hienThi();
}
}
public void button6(View view) {
if (x == 1) {
so1 = so1 + "6";
hienThi();
} else {
so2 = so2 + "6";
hienThi();
}
}
public void button7(View view) {
if (x == 1) {
so1 = so1 + "7";
hienThi();
} else {
so2 = so2 + "7";
hienThi();
}
}
public void button8(View view) {
if (x == 1) {
so1 = so1 + "8";
hienThi();
} else {
so2 = so2 + "8";
hienThi();
}
}
public void button9(View view) {
if (x == 1) {
so1 = so1 + "9";
hienThi();
} else {
so2 = so2 + "9";
hienThi();
}
}
public void button0(View view) {
if (x == 1) {
so1 = so1 + "0";
hienThi();
} else {
so2 = so2 + "0";
hienThi();
}
}
public void buttonReset(View view) {
so1 = "";
so2 = "";
x = 1;
hienThi();
}
public void cong(View view) {
a = Integer.parseInt(so1);
x = 2;
}
public void tru(View view) {
a = Integer.parseInt(so1);
x = 3;
}
public void nhan(View view) {
a = Integer.parseInt(so1);
x = 4;
}
public void chia(View view) {
a = Integer.parseInt(so1);
x = 5;
}
public void bang(View view) {
b = Integer.parseInt(so2);
switch (x) {
case 2:
TextView hienThi1 = (TextView) findViewById(R.id.hienThi);
int c = a + b;
hienThi1.setText(String.valueOf(c));
break;
case 3:
TextView hienThi2 = (TextView) findViewById(R.id.hienThi);
c = a - b;
hienThi2.setText(String.valueOf(c));
break;
case 4:
TextView hienThi3 = (TextView) findViewById(R.id.hienThi);
c = a * b;
hienThi3.setText(String.valueOf(c));
break;
case 5:
TextView hienThi4 = (TextView) findViewById(R.id.hienThi);
c = a / b;
hienThi4.setText(String.valueOf(c));
break;
}
}
public void xoa(View view) {
if (x == 1) {
so1 = so1.substring(0, so1.length() - 1);
hienThi();
} else {
so2 = so2.substring(0, so2.length() - 1);
hienThi();
}
}
public void hienThi() {
TextView hienThi1 = (TextView) findViewById(R.id.hienThi);
if (x == 1) {
hienThi1.setText(so1);
} else {
hienThi1.setText(so2);
}
}
}