0

找不到问题。所有按钮都正常工作并从一个活动正确跳转到另一个活动,但“关于”按钮无法正常工作。它必须跳转到“关于活动”......请检查代码是否有问题......“关于按钮”有问题有评论并且在最后......日志,xml也已安装谢谢和问候

有关于按钮的活动

package com.example.routetracker;



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

public class Select_destination extends Activity implements OnClickListener{
Button close,main,about,texila,aslam_market,royal_son,comsat;
MediaPlayer mPlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_destination);

mPlayer=MediaPlayer.create(this, R.raw.selectdestination);


        mPlayer.start();
        texila=(Button)findViewById(R.id.btn_texila);
        texila.setOnClickListener(this);
        aslam_market=(Button)findViewById(R.id.btn_aslam_market);
        aslam_market.setOnClickListener(this);
        royal_son=(Button)findViewById(R.id.btn_royal_son);
        royal_son.setOnClickListener(this);
        comsat=(Button)findViewById(R.id.btn_comsat_wah);
        comsat.setOnClickListener(this);
        main=(Button)findViewById(R.id.btn_main);
        main.setOnClickListener(this);
        about=(Button)findViewById(R.id.btn_about);
        about.setOnClickListener(this);
        close=(Button)findViewById(R.id.btn_close);
        close.setOnClickListener(this);
}


@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_texila:
    mPlayer.stop();

    Intent i=new Intent(Select_destination.this,Start_tracking.class);
    i.putExtra("place", "1");
    startActivity(i);
    break;
case R.id.btn_aslam_market:
    mPlayer.stop();
    Intent j=new Intent(Select_destination.this,Start_tracking.class);
    j.putExtra("place", "2");
    startActivity(j);
    break;
case R.id.btn_royal_son:
    mPlayer.stop();
    Intent k=new Intent(Select_destination.this,Start_tracking.class);
    k.putExtra("place", "3");
    startActivity(k);
    break;
case R.id.btn_comsat_wah:
    mPlayer.stop();
    Intent l=new Intent(Select_destination.this,Start_tracking.class);
    l.putExtra("place", "4");
    startActivity(l);
    break;

case R.id.btn_main:
    mPlayer.stop();
    Intent o=new Intent(Select_destination.this,MainActivity.class);
    startActivity(o);
    break;

case R.id.btn_about:  // for this button i have problem
    mPlayer.stop();
    Intent e=new Intent(Select_destination.this,About.class);
    startActivity(e);
    break;



case R.id.btn_close:
    mPlayer.stop();
    System.exit(1);
}

}


}

关于活动代码

package com.example.routetracker;

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


public class About extends Activity implements OnClickListener{

Button close,main;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);

main=(Button)findViewById(R.id.btn_main);
main.setOnClickListener(this);

close=(Button)findViewById(R.id.btn_close);
close.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn_main:
    Intent o=new Intent(About.this,MainActivity.class);
    startActivity(o);
    break;

case R.id.btn_close:
    System.exit(1);
    break;


}


}

}

关于按钮的 XML 代码

<Button
android:id="@+id/btn_about"
android:layout_width="97dp"
android:layout_height="90dp"
android:layout_alignBaseline="@+id/btn_main"
android:layout_alignBottom="@+id/btn_main"
android:layout_toRightOf="@+id/btn_main"
android:text="About" />

日志文件是

08-27 08:28:16.752: I/Choreographer(1000): Skipped 72 frames!  The application may be doing too much work on its main thread.
08-27 08:28:17.133: I/ActivityManager(293): START u0 {cmp=com.example.routetracker/.About} from pid 1000
08-27 08:28:17.173: W/WindowManager(293): Failure taking screenshot for (123x205) to layer 21020
08-27 08:28:17.443: I/Choreographer(1000): Skipped 178 frames!  The application may be doing too much work on its main thread.
08-27 08:28:19.123: I/Choreographer(293): Skipped 31 frames!  The application may be doing too much work on its main thread.
08-27 08:28:20.563: D/dalvikvm(1000): GC_FOR_ALLOC freed 1320K, 28% free 4175K/5772K, paused 287ms, total 327ms
08-27 08:28:20.583: I/dalvikvm-heap(1000): Grow heap (frag case) to 5.468MB for 1319216-byte allocation
08-27 08:28:21.102: D/dalvikvm(1000): GC_CONCURRENT freed 4K, 6% free 5459K/5772K, paused 11ms+25ms, total 499ms
08-27 08:28:21.852: D/AndroidRuntime(1000): Shutting down VM
08-27 08:28:21.902: W/dalvikvm(1000): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-27 08:28:22.063: E/AndroidRuntime(1000): FATAL EXCEPTION: main
08-27 08:28:22.063: E/AndroidRuntime(1000): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.routetracker/com.example.routetracker.About}: java.lang.NullPointerException
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.os.Looper.loop(Looper.java:137)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at java.lang.reflect.Method.invokeNative(Native Method)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at java.lang.reflect.Method.invoke(Method.java:511)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at dalvik.system.NativeStart.main(Native Method)
08-27 08:28:22.063: E/AndroidRuntime(1000): Caused by: java.lang.NullPointerException
08-27 08:28:22.063: E/AndroidRuntime(1000):     at com.example.routetracker.About.onCreate(About.java:24)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at  android.app.Activity.performCreate(Activity.java:5104)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-27 08:28:22.063: E/AndroidRuntime(1000):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-27 08:28:22.063: E/AndroidRuntime(1000):     ... 11 more
08-27 08:28:22.342: W/ActivityManager(293):   Force finishing activity com.example.routetracker/.About
08-27 08:28:22.382: I/Choreographer(293): Skipped 121 frames!  The application may be doing too much work on its main thread.
08-27 08:28:22.412: W/ActivityManager(293):   Force finishing activity com.example.routetracker/.Select_destination
08-27 08:28:22.482: I/Choreographer(293): Skipped 32 frames!  The application may be doing too much work on its main thread.
08-27 08:28:22.902: W/ActivityManager(293): Activity pause timeout for ActivityRecord{41569f28 u0 com.example.routetracker/.About}
08-27 08:28:23.212: I/Choreographer(293): Skipped 246 frames!  The application may be doing too much work on its main thread.
08-27 08:28:23.232: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
08-27 08:28:23.373: I/Choreographer(293): Skipped 31 frames!  The application may be doing too much work on its main thread.
08-27 08:28:24.403: I/Choreographer(293): Skipped 39 frames!  The application may be doing too much work on its main thread.
08-27 08:28:24.523: I/Choreographer(293): Skipped 44 frames!  The application may be doing too much work on its main thread.
08-27 08:28:27.279: W/ActivityManager(293): Launch timeout has expired, giving up wake lock!
08-27 08:28:27.372: W/ActivityManager(293): Activity idle timeout for ActivityRecord{41569f28 u0 com.example.routetracker/.About}
08-27 08:28:28.053: I/Choreographer(293): Skipped 44 frames!  The application may be doing too much work on its main thread.
08-27 08:28:28.512: I/Choreographer(293): Skipped 32 frames!  The application may be doing too much work on its main thread.
4

1 回答 1

1

单击关于按钮时检查 v.getId()

Log.d("ID ::",v.getId()+"");

确认您正在获取 btn_about ID

 case R.id.btn_about:  // for this button i have problem

       if(mPlayer != null) { 
          mPlayer.stop();
       }

        Intent e=new Intent(Select_destination.this,About.class);
        startActivity(e);
        break;
于 2013-08-27T09:11:47.333 回答