2012-04-11 27 views
0

Hier ist der gesamte Code innerhalb des Projekts aus dem Youtube-Tutorial, dem ich gefolgt bin. (Hauptteil) ProjectActivity:App beim Klicken auf die Schaltfläche einfrieren

package justinehume.Project; 

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



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

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

      public void onClick(View v) { 

      startActivity(new Intent("android.intent.action.TUTORIALONE")); 

      } 
     }); 

    } 
    protected void onPause(){ 
     super.onPause(); 
    } 
} 

main.xml

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

    <Button android:id="@+id/tutorial1" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="Button" /> 



</LinearLayout> 

ProjectManifest

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

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

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".ProjectActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
       <activity 
      android:label="@string/app_name" 
      android:name=".Tutorialone" > 
      <intent-filter > 
       <action android:name="android.intent.action.TUTORIALONE" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

Tutorialone.java

package justinehume.Project; 

import android.app.Activity; 
import android.os.Bundle; 

public class Tutorialone extends Activity { 

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

} 

E Wenn ich gerade auf die Schaltfläche klicke, wenn die App im SDK ausgeführt wird, stürzt die App ab und die Anwendung wird geschlossen. Irgendwelche Ideen? Vielen Dank!

Logcat

> 04-11 16:19:54.799: D/AndroidRuntime(344): Shutting down VM 04-11 
> 16:19:54.809: W/dalvikvm(344): threadid=1: thread exiting with 
> uncaught exception (group=0x4001d800) 04-11 16:19:54.819: 
> E/AndroidRuntime(344): FATAL EXCEPTION: main 04-11 16:19:54.819: 
> E/AndroidRuntime(344): android.content.ActivityNotFoundException: No 
> Activity found to handle Intent { 
> act=android.intent.action.TUTORIALONE } 04-11 16:19:54.819: 
> E/AndroidRuntime(344): at 
> android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408) 
> 04-11 16:19:54.819: E/AndroidRuntime(344): at 
> android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 
> 04-11 16:19:54.819: E/AndroidRuntime(344): at 
> android.app.Activity.startActivityForResult(Activity.java:2817) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> android.app.Activity.startActivity(Activity.java:2923) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> justinehume.Project.ProjectActivity$1.onClick(ProjectActivity.java:23) 
> 04-11 16:19:54.819: E/AndroidRuntime(344): at 
> android.view.View.performClick(View.java:2408) 04-11 16:19:54.819: 
> E/AndroidRuntime(344): at 
> android.view.View$PerformClick.run(View.java:8816) 04-11 16:19:54.819: 
> E/AndroidRuntime(344): at 
> android.os.Handler.handleCallback(Handler.java:587) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> android.os.Handler.dispatchMessage(Handler.java:92) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> android.os.Looper.loop(Looper.java:123) 04-11 16:19:54.819: 
> E/AndroidRuntime(344): at 
> android.app.ActivityThread.main(ActivityThread.java:4627) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> java.lang.reflect.Method.invokeNative(Native Method) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> java.lang.reflect.Method.invoke(Method.java:521) 04-11 16:19:54.819: 
> E/AndroidRuntime(344): at 
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
> 04-11 16:19:54.819: E/AndroidRuntime(344): at 
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-11 
> 16:19:54.819: E/AndroidRuntime(344): at 
> dalvik.system.NativeStart.main(Native Method) 
+0

posten Sie bitte den LogCat-Ausgang. – Abhijit

+1

Versuchen Sie, Ihre Aktivität mit 'new Intent (ProjectActivity.this, Tutorialon.class) 'zu starten, anstelle von dem, was Sie gerade verwenden. Veröffentlichen Sie auch Ihre Logcat-Stack-Ablaufverfolgung der Force schließen. –

+0

logcat jetzt vorhanden – JTH

Antwort

0

Okay, auf Wunsch, da dies eine grundlegende Anwendung ist, dass ich den vollständigen Code bin Entsendung.

ProjectActivity.java

package justinehume.Project; 

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

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

     Button tut1 = (Button) findViewById(R.id.tutorial1); 
     tut1.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       // Jean-Philippe Roy's correction     
       startActivity(new Intent(ProjectActivity.this, Tutorialone.class)); 
      } 
     }); 

    } 
} 

Tutorialone.java

package justinehume.Project; 

import android.app.Activity; 
import android.os.Bundle; 

public class Tutorialone extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tutorial1); 
    } 
} 

AndroidManifest.xml

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

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

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:name=".ProjectActivity" 
     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:label="@string/app_name" android:name=".Tutorialone"/> 

</application> 

</manifest> 

Hinweis: Ich habe dies auf einem Emulator getestet und es stürzt nicht ab. Ich würde empfehlen, dass Sie mehr Tutorials lesen/lesen, um ein besseres Verständnis zu haben. Viel Glück!

0

Tutorialone ‚s Absicht Filter sollte Kategorie haben "android.intent.category.DEFAULT" statt "android.intent.category.LAUNCHER"

Verwandte Themen