2013-01-21 40 views
-1

我刚刚开始一个新的应用程序,我添加了一个按钮,过去我没有问题,但由于某种原因,它现在不工作。我只是简单地试图将该按钮指向另一个页面。你认为问题是什么? (只是忽略纺纱我没有设置这些了吗)当按下按钮时,应用程序关闭

TextingprojectActivity

public class TextingprojectActivity 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) { 
       // TODO Auto-generated method stub 

       startActivity(new Intent("practice.practice.TUTORIALONE ")); 
      } 
     }); 
    } 
} 

教程1的Java

public class TutorialOne extends Activity 
{ 

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

} 

主要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" > 

    <Spinner 
     android:id="@+id/spinner1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:entries="@array/place_arrays" 
     android:prompt="@string/Place"/> 
    <Spinner 
     android:id="@+id/spinner2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
    <Button 
     android:id="@+id/tutorial1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/save" 
     /> 


</LinearLayout> 

教程1 XML

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


</LinearLayout> 

Android清单

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

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

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".TextingprojectActivity" 
      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=".TutorialOne" 
      android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="practice.practice.TUTORIALONE" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
      </activity> 
    </application> 

</manifest> 
+0

发布logcat,那里应该有一个堆栈跟踪。 –

+0

当您创建新的Intent时,尝试在'“practice.practice.TUTORIALONE”'末尾取出空格。 –

+0

只是把@Override onclick方法 –

回答

1

变化像

Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class); 
     startActivity(n); 

而且你的意图的呼叫从maniefst剩余活性的delaration删除intent-filter

<intent-filter> 
      <action android:name="practice.practice.TUTORIALONE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 

改变它喜欢...

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

     </activity> 
</application> 
+0

谢谢你,这解决了问题。 –

1

更改你的意图调用

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

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      Intent n = new Intent(TextingprojectActivity.this,TutorialOne.class); 
      startActivity(n); 
     } 
    }); 
0

如果只需要重定向到第二活动更改代码

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

    public void onClick(View v) { 
     // TODO Auto-generated method stub 

     startActivity(new Intent(TextingprojectActivity.this,TutorialOne.class);); 
    } 
}); 

,并删除此块从你的清单XML

 <intent-filter> 
      <action android:name="practice.practice.TUTORIALONE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 

这是什么practice.practice.TUTORIALONE???

相关问题