gpt4 book ai didi

android-activity - 在图像上创建按钮以打开新的 Activity onclick会崩溃

转载 作者:行者123 更新时间:2023-12-03 16:26:41 25 4
gpt4 key购买 nike

我试图这样做:
当我单击imagebutton时,它打开了新的 Activity (名为:TakingPick.class)。
它崩溃了,我听不懂logcat。
我需要怎么做才能使其正常工作?

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.main, menu);
return true;
}

public void sendMessage(View view) {
Intent intent = new Intent(this, TakingPick.class);
startActivity(intent);

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
return false;

}

}

xml:activity_main
    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"


android:background="@drawable/bridgebg"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/bridgenew" />

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="sendMessage"
android:layout_marginBottom="61dp"
android:src="@drawable/loginfacebook" />

LOGCAT:
    06-14 19:36:56.111: E/dalvikvm-heap(14770): Out of memory on a 354168112-byte allocation.
06-14 19:36:56.211: E/AndroidRuntime(14770): FATAL EXCEPTION: main
06-14 19:36:56.211: E/AndroidRuntime(14770): Process: idan.nir.debridge, PID: 14770
06-14 19:36:56.211: E/AndroidRuntime(14770): java.lang.OutOfMemoryError
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.content.res.Resources.loadDrawable(Resources.java:3056)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.content.res.Resources.getDrawable(Resources.java:1613)
06-14 19:36:56.211: E/AndroidRuntime(14770): at com.android.internal.widget.ActionBarView.setIcon(ActionBarView.java:1016)
06-14 19:36:56.211: E/AndroidRuntime(14770): at com.android.internal.policy.impl.PhoneWindow.setDefaultIcon(PhoneWindow.java:1543)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.Activity.initActionBar(Activity.java:2001)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.Activity.setContentView(Activity.java:2016)
06-14 19:36:56.211: E/AndroidRuntime(14770): at idan.nir.debridge.TakingPick.onCreate(TakingPick.java:14)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.Activity.performCreate(Activity.java:5431)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.ActivityThread.access$900(ActivityThread.java:161)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.os.Handler.dispatchMessage(Handler.java:102)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.os.Looper.loop(Looper.java:157)
06-14 19:36:56.211: E/AndroidRuntime(14770): at android.app.ActivityThread.main(ActivityThread.java:5356)
06-14 19:36:56.211: E/AndroidRuntime(14770): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 19:36:56.211: E/AndroidRuntime(14770): at java.lang.reflect.Method.invoke(Method.java:515)
06-14 19:36:56.211: E/AndroidRuntime(14770): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
06-14 19:36:56.211: E/AndroidRuntime(14770): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
06-14 19:36:56.211: E/AndroidRuntime(14770): at dalvik.system.NativeStart.main(Native Method)

捡取
public class TakingPick extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO Auto-generated method stub
setContentView(R.layout.takingpick);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
return false;

}
}

xml:takingPick
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/bridgebg"
android:layout_height="match_parent" >


</RelativeLayout>

最佳答案

您遇到了内存不足的异常。您尝试加载的位图之一太大,导致内存泄漏。
如果您使用的是可绘制资源,请确保该资源位于正确的可绘制目录中。同时尝试减小图像尺寸和分辨率

关于android-activity - 在图像上创建按钮以打开新的 Activity onclick会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30831926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com