开发者

force down error in app

I have a problem on running my app but i cant find out where is the problem! I have created a first screen that has two buttons. This "home" screen is chordsApp.java. I want to go to the track1.java if I press the first button and to track2.java if I press the second! The program runs but when I'm trying to press the first or the second button it pops up an error and tells me to force down!! Here is the code:

ChordApp.java

package com.example.ChordsApp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ChordsApp extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button next = (Button) findViewById(R.id.button);
        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), track1.class);
                startActivityForResult(myIntent,0);
            }

        });
        Button next1 = (Button) findViewById(R.id.button1);
        next1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), track2.class);
                startActivityForResult(myIntent, 0);
            }

        });

    }

}

track1.java

package com.example.ChordsApp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class track1 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        Button next = (Button) findViewById(R.id.button3);
        next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
           }

       });

    }
}

track2.java

package com.example.ChordsApp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;开发者_StackOverflow
import android.widget.Button;

public class track2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main3);

        Button next1 = (Button) findViewById(R.id.button4);
        next1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
           }

       });

    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <ImageView 
            android:id="@+id/pic"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/guitar"
            android:layout_gravity="center"
       />
        <TextView  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:text="@string/hello"
            />  
    <LinearLayout
       android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" >
            <Button
                android:text="track1"
                android:id="@+id/button"
                android:layout_width="250px"
                android:textSize="18px"
                android:layout_height="55px" />    
       <Button 
                android:text="track2"
                android:id="@+id/button1"
                android:layout_width="250px"
                android:textSize="18px"
                android:layout_height="55px" /> 
    </LinearLayout>
</LinearLayout>

main2.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="hi"/>

<Button android:text="Home"
    android:id="@+id/button3"
    android:layout_width="250px"
        android:textSize="18px"
    android:layout_height="55px"
    android:layout_gravity="center_horizontal"
    > 

   </Button>  
</LinearLayout>

main3.xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="hi"/>

<Button android:text="Home"
    android:id="@+id/button4"
    android:layout_width="250px"
        android:textSize="18px"
    android:layout_height="55px"
    android:layout_gravity="center_horizontal"
    > 

</Button>  
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜