2013-03-11 86 views
0

当我开始意图去下一个活动。我收到上面的错误。我无法前往下一个活动(请参阅下面的SecondActivity.java)。android:无法启动活动组件信息

我的MainActivity是:

package com.example.testflashfile; 

import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import android.app.Activity; 
import android.content.Intent; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import android.view.GestureDetector; 
import android.view.GestureDetector.SimpleOnGestureListener; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.TextView; 
import android.view.MotionEvent; 


public class MainActivity extends Activity 
{ 
    Button nextButton; 
    Button playButton; 
    private static final int SWIPE_MIN_DISTANCE = 120; 
    private static final int SWIPE_MAX_OFF_PATH = 250; 
    private static final int SWIPE_THRESHOLD_VELOCITY = 200; 

    GestureDetector gestureDetector; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
     setContentView(R.layout.activity_main); 

     gestureDetector = new GestureDetector(this.getApplicationContext(),new MyGestureDetector()); 
     View mainview = (View) findViewById(R.id.mainView); 

     // Set the touch listener for the main view to be our custom gesture listener 
     mainview.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
       if (gestureDetector.onTouchEvent(event)) { 
        return true; 
       } 
       return false; 
      } 
     }); 


     playButton=(Button)findViewById(R.id.play); 
     playButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent startAnimation=new Intent(MainActivity.this,PlayAnimationActivity.class); 
       startAnimation.putExtra("SWF_NAME","a"); 
       startActivity(startAnimation); 
      } 
     }); 


     TextView helloTxt = (TextView)findViewById(R.id.displaytext); 
     helloTxt.setText(readTxt()); 
     nextButton=(Button)findViewById(R.id.next); 
     nextButton.setOnClickListener(new OnClickListener() { 


      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(MainActivity.this,SecondActivity.class); 
       startActivity(intent); 

      } 
     }); 


    } 

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


    private String readTxt(){ 

     InputStream inputStream = getResources().openRawResource(R.raw.textone); 

     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 

     int i; 
     try { 
      i = inputStream.read(); 
      while (i != -1) 
      { 
       byteArrayOutputStream.write(i); 
       i = inputStream.read(); 
      } 

      inputStream.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     return byteArrayOutputStream.toString(); 
    } 



    class MyGestureDetector extends SimpleOnGestureListener 
    { 


     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 


      if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) { 
       return false; 
      } 

      // right to left swipe 
      if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 

       Intent i= new Intent(MainActivity.this,SecondActivity.class); 
       startActivity(i); 

       // left to right swipe 
      } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 


       Intent i= new Intent(MainActivity.this,FifthActivity.class); 
       startActivity(i); 

      } 

      return false; 
     } 


     @Override 
     public boolean onDown(MotionEvent e) { 
      return true; 
     } 



    } 

} 

第二个活动如下:

package com.example.testflashfile; 

import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 

import android.app.Activity; 
import android.content.Intent; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import android.view.GestureDetector; 
import android.view.Menu; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.Window; 
import android.view.GestureDetector.SimpleOnGestureListener; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 



public class SecondActivity extends Activity { 

    Button nextButton2; 
    Button backButton2; 
    Button playButton2; 
    private static final int SWIPE_MIN_DISTANCE = 120; 
    private static final int SWIPE_MAX_OFF_PATH = 250; 
    private static final int SWIPE_THRESHOLD_VELOCITY = 200; 
    GestureDetector gestureDetector; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
     setContentView(R.layout.second); 

     gestureDetector = new GestureDetector(this.getApplicationContext(),new MyGestureDetector()); 
     View mainview = (View) findViewById(R.id.mainView); 

     // Set the touch listener for the main view to be our custom gesture listener 
     mainview.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
       if (gestureDetector.onTouchEvent(event)) { 
        return true; 
       } 
       return false; 
      } 
     }); 


     TextView helloTxt = (TextView)findViewById(R.id.displaytexttwo); 
     helloTxt.setText(readTxt()); 
     nextButton2=(Button)findViewById(R.id.nexttwo); 
     nextButton2.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(SecondActivity.this,ThirdActivity.class); 
       startActivity(intent); 

      } 
     }); 

     playButton2=(Button)findViewById(R.id.play); 
     playButton2.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent startAnimation=new Intent(SecondActivity.this,PlayAnimationActivity.class); 
       startAnimation.putExtra("SWF_NAME","b"); 
       startActivity(startAnimation); 
      } 
     }); 

     backButton2=(Button)findViewById(R.id.backtwo); 
     backButton2.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(SecondActivity.this,MainActivity.class); 
       startActivity(intent); 

      } 
     }); 


    } 

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



    private String readTxt(){ 

     InputStream inputStream = getResources().openRawResource(R.raw.texttwo); 

     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 

     int i; 
     try { 
      i = inputStream.read(); 
      while (i != -1) 
      { 
       byteArrayOutputStream.write(i); 
       i = inputStream.read(); 
      } 
      inputStream.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     return byteArrayOutputStream.toString(); 
    } 


    class MyGestureDetector extends SimpleOnGestureListener 
    { 


     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 


      if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) { 
       return false; 
      } 

      // right to left swipe 
      if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 

       Intent i= new Intent(SecondActivity.this,ThirdActivity.class); 
       startActivity(i); 

       // left to right swipe 
      } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 


       Intent i= new Intent(SecondActivity.this,MainActivity.class); 
       startActivity(i); 

      } 

      return false; 
     } 


     @Override 
     public boolean onDown(MotionEvent e) { 
      return true; 
     } 



    } 
} 

我不明白的地方我要去错在这里。我检查了与此错误相关的堆栈溢出的类似线程。但解释并不明确。任何帮助/建议表示赞赏。提前感谢您抽出时间阅读这样一篇冗长的文章。

日志猫:

03-11 10:03:18.599: D/dalvikvm(336): GC_EXTERNAL_ALLOC freed 66K, 52% free 2585K/5379K, external 2032K/2137K, paused 92ms 
03-11 10:03:18.729: D/AndroidRuntime(336): Shutting down VM 
03-11 10:03:18.729: W/dalvikvm(336): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
03-11 10:03:18.749: E/AndroidRuntime(336): FATAL EXCEPTION: main 
03-11 10:03:18.749: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testflashfile/com.example.testflashfile.SecondActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.os.Looper.loop(Looper.java:123) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.ActivityThread.main(ActivityThread.java:3683) 
03-11 10:03:18.749: E/AndroidRuntime(336): at java.lang.reflect.Method.invokeNative(Native Method) 
03-11 10:03:18.749: E/AndroidRuntime(336): at java.lang.reflect.Method.invoke(Method.java:507) 
03-11 10:03:18.749: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-11 10:03:18.749: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-11 10:03:18.749: E/AndroidRuntime(336): at dalvik.system.NativeStart.main(Native Method) 
03-11 10:03:18.749: E/AndroidRuntime(336): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content 
03-11 10:03:18.749: E/AndroidRuntime(336): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.Activity.requestWindowFeature(Activity.java:2729) 
03-11 10:03:18.749: E/AndroidRuntime(336): at com.example.testflashfile.SecondActivity.onCreate(SecondActivity.java:35) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-11 10:03:18.749: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
03-11 10:03:18.749: E/AndroidRuntime(336): ... 11 more 
03-11 10:03:21.539: I/Process(336): Sending signal. PID: 336 SIG: 9 
03-11 12:37:51.179: D/dalvikvm(382): GC_EXTERNAL_ALLOC freed 67K, 53% free 2581K/5379K, external 2032K/2137K, paused 199ms 
03-11 12:37:51.478: D/AndroidRuntime(382): Shutting down VM 
03-11 12:37:51.479: W/dalvikvm(382): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
03-11 12:37:51.722: E/AndroidRuntime(382): FATAL EXCEPTION: main 
03-11 12:37:51.722: E/AndroidRuntime(382): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testflashfile/com.example.testflashfile.SecondActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.os.Looper.loop(Looper.java:123) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.ActivityThread.main(ActivityThread.java:3683) 
03-11 12:37:51.722: E/AndroidRuntime(382): at java.lang.reflect.Method.invokeNative(Native Method) 
03-11 12:37:51.722: E/AndroidRuntime(382): at java.lang.reflect.Method.invoke(Method.java:507) 
03-11 12:37:51.722: E/AndroidRuntime(382): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-11 12:37:51.722: E/AndroidRuntime(382): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-11 12:37:51.722: E/AndroidRuntime(382): at dalvik.system.NativeStart.main(Native Method) 
03-11 12:37:51.722: E/AndroidRuntime(382): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content 
03-11 12:37:51.722: E/AndroidRuntime(382): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.Activity.requestWindowFeature(Activity.java:2729) 
03-11 12:37:51.722: E/AndroidRuntime(382): at com.example.testflashfile.SecondActivity.onCreate(SecondActivity.java:35) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-11 12:37:51.722: E/AndroidRuntime(382): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
03-11 12:37:51.722: E/AndroidRuntime(382): ... 11 more 
03-11 12:37:57.159: I/Process(382): Sending signal. PID: 382 SIG: 9 
03-11 12:40:41.579: W/ActivityThread(418): Application com.example.testflashfile is waiting for the debugger on port 8100... 
03-11 12:40:41.649: I/System.out(418): Sending WAIT chunk 
03-11 12:40:42.381: I/dalvikvm(418): Debugger is active 
03-11 12:40:42.499: I/System.out(418): Debugger has connected 
03-11 12:40:42.499: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:42.703: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:43.011: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:43.209: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:43.419: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:43.619: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:43.869: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:44.070: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:44.269: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:44.469: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:44.720: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:44.925: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:45.140: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:45.339: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:45.559: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:45.793: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:46.031: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:46.261: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:46.468: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:46.669: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:46.875: I/System.out(418): waiting for debugger to settle... 
03-11 12:40:47.109: I/System.out(418): debugger has settled (1505) 
03-11 12:49:24.089: D/dalvikvm(418): GC_EXTERNAL_ALLOC freed 68K, 52% free 2583K/5379K, external 2032K/2137K, paused 212ms 
03-11 12:51:01.819: D/AndroidRuntime(418): Shutting down VM 
03-11 12:51:01.839: W/dalvikvm(418): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
03-11 12:51:07.499: E/AndroidRuntime(418): FATAL EXCEPTION: main 
03-11 12:51:07.499: E/AndroidRuntime(418): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testflashfile/com.example.testflashfile.SecondActivity}: java.lang.NullPointerException 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.os.Looper.loop(Looper.java:123) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.ActivityThread.main(ActivityThread.java:3683) 
03-11 12:51:07.499: E/AndroidRuntime(418): at java.lang.reflect.Method.invokeNative(Native Method) 
03-11 12:51:07.499: E/AndroidRuntime(418): at java.lang.reflect.Method.invoke(Method.java:507) 
03-11 12:51:07.499: E/AndroidRuntime(418): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-11 12:51:07.499: E/AndroidRuntime(418): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-11 12:51:07.499: E/AndroidRuntime(418): at dalvik.system.NativeStart.main(Native Method) 
03-11 12:51:07.499: E/AndroidRuntime(418): Caused by: java.lang.NullPointerException 
03-11 12:51:07.499: E/AndroidRuntime(418): at com.example.testflashfile.SecondActivity.onCreate(SecondActivity.java:69) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-11 12:51:07.499: E/AndroidRuntime(418): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
03-11 12:51:07.499: E/AndroidRuntime(418): ... 11 more 
03-11 12:56:07.749: I/Process(418): Sending signal. PID: 418 SIG: 9 
03-11 14:17:47.570: D/dalvikvm(457): GC_EXTERNAL_ALLOC freed 68K, 53% free 2581K/5379K, external 2032K/2137K, paused 116ms 
03-11 14:17:47.699: D/AndroidRuntime(457): Shutting down VM 
03-11 14:17:47.699: W/dalvikvm(457): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
03-11 14:17:47.729: E/AndroidRuntime(457): FATAL EXCEPTION: main 
03-11 14:17:47.729: E/AndroidRuntime(457): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testflashfile/com.example.testflashfile.SecondActivity}: java.lang.NullPointerException 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.os.Looper.loop(Looper.java:123) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.ActivityThread.main(ActivityThread.java:3683) 
03-11 14:17:47.729: E/AndroidRuntime(457): at java.lang.reflect.Method.invokeNative(Native Method) 
03-11 14:17:47.729: E/AndroidRuntime(457): at java.lang.reflect.Method.invoke(Method.java:507) 
03-11 14:17:47.729: E/AndroidRuntime(457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-11 14:17:47.729: E/AndroidRuntime(457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-11 14:17:47.729: E/AndroidRuntime(457): at dalvik.system.NativeStart.main(Native Method) 
03-11 14:17:47.729: E/AndroidRuntime(457): Caused by: java.lang.NullPointerException 
03-11 14:17:47.729: E/AndroidRuntime(457): at com.example.testflashfile.SecondActivity.onCreate(SecondActivity.java:44) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-11 14:17:47.729: E/AndroidRuntime(457): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
03-11 14:17:47.729: E/AndroidRuntime(457): ... 11 more 

清单是:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.testflashfile" 
    android:versionCode="1" 
    android:versionName="1.0" 
    > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" 
     /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     android:hardwareAccelerated="true" 
     android:debuggable="true"> 
     <activity 
      android:screenOrientation="portrait" 
      android:name="com.example.testflashfile.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name="com.example.testflashfile.SecondActivity" 
      android:screenOrientation="portrait"></activity> 
     <activity android:name="com.example.testflashfile.ThirdActivity" 
      android:screenOrientation="portrait"></activity> 
      <activity android:name="com.example.testflashfile.FourthActivity" 
       android:screenOrientation="portrait"></activity> 
      <activity android:name="com.example.testflashfile.FifthActivity" 
       android:screenOrientation="portrait"></activity> 

<activity android:name="com.example.testflashfile.PlayAnimationActivity" 
       android:screenOrientation="portrait"></activity> 

    </application> 

</manifest> 
+2

请发布完整的Logcat输出 – sebastian 2013-03-11 09:24:52

+0

是您在AndroidManifest.xml中标记的第二个活动吗? – Oren 2013-03-11 09:27:17

+0

请发布您的Logcat和清单。 – staaar 2013-03-11 09:28:01

回答

1

嗨,我的问题已解决。但我似乎无法确定我的代码是否错误,但我会喜欢向大家介绍一些对我有用的东西(可能有比这更好的解决方案。随时可以编辑这篇文章)。

这是我现在的MainActivity:

package com.example.testflashfile; 

import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import android.app.Activity; 
import android.content.Intent; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import android.view.GestureDetector; 
import android.view.GestureDetector.SimpleOnGestureListener; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.TextView; 
import android.view.MotionEvent; 
import com.example.testflashfile.GlobalVariables; 


public class MainActivity extends Activity 
{ 
    Button nextButton; 
    Button playButton; 
    Button backButton; 


    GestureDetector gestureDetector; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
     setContentView(R.layout.activity_main); 

     TextView helloTxt = (TextView)findViewById(R.id.displaytext); 
     helloTxt.setText(readTxt()); 


     gestureDetector = new GestureDetector(this.getApplicationContext(),new MyGestureDetector()); 
     View mainview = (View) findViewById(R.id.mainView); 

     // Set the touch listener for the main view to be our custom gesture listener 
     mainview.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
       if (gestureDetector.onTouchEvent(event)) { 
        return true; 
       } 
       return false; 
      } 
     }); 


     playButton=(Button)findViewById(R.id.play); 
     playButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent startAnimation=new Intent(MainActivity.this,PlayAnimationActivity.class); 
       startAnimation.putExtra("SWF_NAME","a"); 
       startActivity(startAnimation); 
      } 
     }); 



     nextButton=(Button)findViewById(R.id.next); 
     nextButton.setOnClickListener(new OnClickListener() { 


      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(MainActivity.this,SecondActivity.class); 
       startActivity(intent); 

      } 
     }); 

     backButton=(Button)findViewById(R.id.back); 
     backButton.setOnClickListener(new OnClickListener() { 


      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(MainActivity.this,FifthActivity.class); 
       startActivity(intent); 

      } 
     }); 


    } 

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


    private String readTxt(){ 

     InputStream inputStream = getResources().openRawResource(R.raw.textone); 

     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 

     int i; 
     try { 
      i = inputStream.read(); 
      while (i != -1) 
      { 
       byteArrayOutputStream.write(i); 
       i = inputStream.read(); 
      } 

      inputStream.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     return byteArrayOutputStream.toString(); 
    } 



    public class MyGestureDetector extends SimpleOnGestureListener 
    { 


     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 


      if (Math.abs(e1.getY() - e2.getY()) > GlobalVariables.SWIPE_MAX_OFF_PATH) { 
       return false; 
      } 

      // right to left swipe 
      if(e1.getX() - e2.getX() > GlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > GlobalVariables.SWIPE_THRESHOLD_VELOCITY) { 

       Intent i= new Intent(MainActivity.this,SecondActivity.class); 
       startActivity(i); 

       // left to right swipe 
      } else if (e2.getX() - e1.getX() > GlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > GlobalVariables.SWIPE_THRESHOLD_VELOCITY) { 


       Intent i= new Intent(MainActivity.this,FifthActivity.class); 
       startActivity(i); 

      } 

      return false; 
     } 


     @Override 
     public boolean onDown(MotionEvent e) { 
      return true; 
     } 



    } 

} 

这里是SecondActivity:

package com.example.testflashfile; 

import java.io.ByteArrayOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 



import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.GestureDetector; 
import android.view.Menu; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.GestureDetector.SimpleOnGestureListener; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 


public class SecondActivity extends Activity 
{ 
    Button nextButton,backButton,playButton; 
    GestureDetector gestureDetector; 

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

     TextView helloTxt = (TextView)findViewById(R.id.displaytexttwo); 
     helloTxt.setText(readTxt()); 


     gestureDetector = new GestureDetector(this.getApplicationContext(),new MyGestureDetector()); 
     View mainview = (View) findViewById(R.id.mainViewtwo); 

     // Set the touch listener for the main view to be our custom gesture listener 
     mainview.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
       if (gestureDetector.onTouchEvent(event)) { 
        return true; 
       } 
       return false; 
      } 
     }); 


     playButton=(Button)findViewById(R.id.playtwo); 
     playButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent startAnimation=new Intent(SecondActivity.this,PlayAnimationActivity.class); 
       startAnimation.putExtra("SWF_NAME","b"); 
       startActivity(startAnimation); 
      } 
     }); 



     nextButton=(Button)findViewById(R.id.nexttwo); 
     nextButton.setOnClickListener(new OnClickListener() { 


      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(SecondActivity.this,ThirdActivity.class); 
       startActivity(intent); 

      } 
     }); 

     backButton=(Button)findViewById(R.id.backtwo); 
     backButton.setOnClickListener(new OnClickListener() { 


      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       Intent intent=new Intent(SecondActivity.this,MainActivity.class); 
       startActivity(intent); 

      } 
     }); 
    } 

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


    private String readTxt(){ 

     InputStream inputStream = getResources().openRawResource(R.raw.texttwo); 

     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 

     int i; 
     try { 
      i = inputStream.read(); 
      while (i != -1) 
      { 
       byteArrayOutputStream.write(i); 
       i = inputStream.read(); 
      } 

      inputStream.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     return byteArrayOutputStream.toString(); 
    } 

    public class MyGestureDetector extends SimpleOnGestureListener 
    { 


     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 


      if (Math.abs(e1.getY() - e2.getY()) > GlobalVariables.SWIPE_MAX_OFF_PATH) { 
       return false; 
      } 

      // right to left swipe 
      if(e1.getX() - e2.getX() > GlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > GlobalVariables.SWIPE_THRESHOLD_VELOCITY) { 

       Intent i= new Intent(SecondActivity.this,ThirdActivity.class); 
       startActivity(i); 

       // left to right swipe 
      } else if (e2.getX() - e1.getX() > GlobalVariables.SWIPE_MIN_DISTANCE && Math.abs(velocityX) > GlobalVariables.SWIPE_THRESHOLD_VELOCITY) { 


       Intent i= new Intent(SecondActivity.this,MainActivity.class); 
       startActivity(i); 

      } 

      return false; 
     } 


     @Override 
     public boolean onDown(MotionEvent e) { 
      return true; 
     } 

    } 
} 

我创建了一个全球可变因素类我的活动,因为他们使用刷卡方式相同varibales

package com.example.testflashfile;

公共类GlobalVariables {

static final int SWIPE_MIN_DISTANCE = 120; 
static final int SWIPE_MAX_OFF_PATH = 250; 
static final int SWIPE_THRESHOLD_VELOCITY = 200; 

}

这一变化在某种程度上解决了我的问题。我仍然不知道如何。但这是有效的。

我想知道这项工作的实际原因是什么。目前代码正在运行,并且正在继续。

谢谢大家的帮助和指示。

0

在你的清单中删除 从标签“screenOrientation =“肖像”的第二次活动,您已设置的取向性,活动前呼叫请求...方法。

+0

Manifest已发布。在我看来这很好。这段代码做了什么?它给我错误,如“令牌上的语法错误”无效“,@预计” – 2013-03-11 09:57:23

+0

我看你的清单后,我改变了我的答案。 – magirtopcu 2013-03-11 10:14:18

+0

这不是一个错误。但我照你的话说。它仍然给我同样的错误。 – 2013-03-11 11:09:25

相关问题