我尝试为按钮调用onClickListener,但它无效。每当我试图点击"创建帐户"按钮,它不指示我注册页面,而是强行退出。我查了很多帖子,但我还是没有得到解决方案。任何人都可以帮助我,请...
这是register.java
package ezms.ezms;
import android.app.AlertDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class register extends AppCompatActivity implements View.OnClickListener {
Button btn_SignIn, btn_Reg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("EzMS - Online Store");
setContentView(R.layout.activity_register);
btn_SignIn = (Button) findViewById(R.id.btn_SignIn);
btn_SignIn.setOnClickListener(this);
btn_Reg = (Button) findViewById(R.id.btn_Reg);
btn_Reg.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_SignIn:
startActivity(new Intent(this, register_acc.class));
break;
case R.id.btn_Reg:
startActivity(new Intent(this, register_acc.class));
break;
}
}
}
这是activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/banner"
tools:context="ezms.ezms.register">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign In"
android:id="@+id/btn_SignIn"
android:clickable="true"
android:layout_marginBottom="95dp"
android:background="#27468D"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Account"
android:id="@+id/btn_Reg"
android:layout_alignTop="@+id/btn_SignIn"
android:clickable="true"
android:layout_marginTop="72dp"
android:layout_alignEnd="@+id/btn_SignIn"
android:background="#FFFFFF"
android:textColor="#27468D"
android:layout_alignParentStart="true"/>
</RelativeLayout>
以下是错误......
05-05 00:16:18.862 16596-16596/ezms.ezms E/AndroidRuntime: FATAL EXCEPTION: main
Process: ezms.ezms, PID: 16596
java.lang.OutOfMemoryError: Failed to allocate a 95976012 byte allocation with 16777120 free bytes and 38MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:655)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:488)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:978)
at android.content.res.Resources.createFromResourceStream(Resources.java:3016)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2711)
at android.content.res.Resources.loadDrawable(Resources.java:2597)
at android.content.res.MiuiResources.loadDrawable(MiuiResources.java:348)
at android.content.res.TypedArray.getDrawable(TypedArray.java:751)
at android.widget.ImageView.<init>(ImageView.java:146)
at android.widget.ImageView.<init>(ImageView.java:135)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1030)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:729)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:508) at android.view.LayoutInflater.inflate(LayoutInflater.java:418) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at ezms.ezms.register_acc.onCreate(register_acc.java:18)
at android.app.Activity.performCreate(Activity.java:5977)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2415)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524) at android.app.ActivityThread.access$800(ActivityThread.java:167)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1419) at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)