gpt4 book ai didi

android - 应用程序在简单的 Activity 开关上崩溃…按下按钮时

转载 作者:行者123 更新时间:2023-12-03 17:47:23 24 4
gpt4 key购买 nike

好的,所以我有一个简单的Java Activity 文件,当按下按钮时,该文件只会切换 Activity 。现在我的动画效果良好...第一个 Activity 也可以正常打开... Rts按钮也可以正常工作....但是单击重置按钮时,而不是按要求更改 Activity 时,它使应用程序崩溃了...我不能了解问题...没有错误或问题正在显示....只有日志猫在我测试时发疯了..请帮助...

public class Title extends Activity {

Button reset, rts;
ImageView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_title);
Animation a = AnimationUtils.loadAnimation(this, R.animator.animation);
ImageView rImage = (ImageView) findViewById(R.id.title);
rImage.startAnimation(a);
func();

reset = (Button) findViewById(R.id.reset);
reset.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
Intent reset=new Intent(Title.this,MainActivity.class);
startActivity(reset);
}
});



rts = (Button) findViewById(R.id.rts);
rts.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent rts=new Intent(Title.this,Rts.class);
startActivity(rts);

}
});


}

protected void func() {
// TODO Auto-generated method stub

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.title, menu);
return true;
}



}

这是原木猫
09-10 17:30:22.110: E/dalvikvm-heap(581): Out of memory on a 15681616-byte allocation.
09-10 17:30:22.340: E/AndroidRuntime(581): FATAL EXCEPTION: main
09-10 17:30:22.340: E/AndroidRuntime(581): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.whattodo2/com.example.whattodo2.Question36}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.TextView
09-10 17:30:22.340: E/AndroidRuntime(581): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.os.Looper.loop(Looper.java:137)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-10 17:30:22.340: E/AndroidRuntime(581): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 17:30:22.340: E/AndroidRuntime(581): at java.lang.reflect.Method.invoke(Method.java:511)
09-10 17:30:22.340: E/AndroidRuntime(581): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-10 17:30:22.340: E/AndroidRuntime(581): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-10 17:30:22.340: E/AndroidRuntime(581): at dalvik.system.NativeStart.main(Native Method)
09-10 17:30:22.340: E/AndroidRuntime(581): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.TextView
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
09-10 17:30:22.340: E/AndroidRuntime(581): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-10 17:30:22.340: E/AndroidRuntime(581): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)

这是主要 Activity 的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
>

<TextView
android:id="@+id/q4y"
android:layout_width="match_parent"
android:layout_height="300dip"

android:layout_margin="15dip"
android:background="@drawable/paper"
android:gravity="center"
android:padding="25dip"
android:text="@string/bored"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="35sp" />

<Button
android:id="@+id/bNo"
android:layout_width="80dip"
android:layout_height="80dip"
android:layout_alignBaseline="@+id/bYes"
android:layout_alignBottom="@+id/bYes"
android:layout_alignLeft="@+id/q4y"
android:layout_marginLeft="40dip"
android:layout_marginRight="15dip"
android:background="@drawable/no" />

<Button
android:id="@+id/bYes"
android:layout_width="80dip"
android:layout_height="80dip"
android:layout_alignRight="@+id/q4y"
android:layout_below="@+id/q4y"
android:layout_marginTop="80dip"
android:layout_toLeftOf="@+id/bNo"
android:layout_marginRight="40dip"
android:background="@drawable/yes"
/>



</RelativeLayout>

最佳答案

       @Override
public void onClick(View arg0) {
Intent resetIntent=new Intent(Title.this,MainActivity.class);
startActivity(resetIntent);
}
});

尝试使用此按钮进行重置。能行吗

关于android - 应用程序在简单的 Activity 开关上崩溃…按下按钮时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18723646/

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