-1

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

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)

这是主要活动的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>
4

2 回答 2

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

试试这个重置按钮。它有效吗?

于 2013-09-10T16:17:11.000 回答
0

您需要发布更多信息以获得更好的答案。但是查看代码,您正在正确地创建一个 Intent 并正确调用 startActivity(intent)。我的猜测是你忘了在你的 AndroidManifest 中声明活动。

<activity
    android:name="com.example.package.Rts" />

如果您发现 Logcat,它可能会告诉您需要声明您的活动。如果这不是您的答案,您将不得不发布堆栈跟踪

于 2013-09-10T16:22:10.547 回答