2014-04-19 22 views
-3

基本上是一個Java開發人員,但現在我正在開發一個Android應用程序。在我的應用程序,我不能重定向到下一個頁面,當我點擊登錄按鈕,在這裏是我的代碼我不能重定向到下一個註冊頁面,當我點擊登錄按鈕

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.view.View; 
import android.widget.Button; 
public class MainActivity extends ActionBarActivity implements View.OnClickListener { 
Button log,sign; 



@Override 


protected void onCreate(Bundle savedInstanceState) { 


    super.onCreate(savedInstanceState); 


    setContentView(R.layout.login); 


    log = (Button) findViewById(R.id.login); 

    sign = (Button) findViewById(R.id.signup); 


    log.setOnClickListener(this); 
    sign.setOnClickListener(this); 

    } 

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

    switch(v.getId()) { 
     case R.id.login: 
     break; 
     case R.id.signup: 
      Intent open = new Intent("com.example.eblood.Register"); 
      startActivity(open); 

     break; 
    } 
} 




} 
} 

這是我的下一個頁面的Java代碼

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

public class Register extends Activity{ 
Button backlog,regg; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.register); 
    backlog = (Button) findViewById(R.id.linktologin); 
    regg = (Button) findViewById(R.id.register); 
    backlog.setOnClickListener((OnClickListener) this); 
} 
    public void onClick (View v) 
    { 

      switch(v.getId()) { 
       case R.id.register: 
       break; 
       case R.id.linktologin: 
        Intent in = new Intent("com.example.eblood.MainActivity"); 
        startActivity(in); 
       break; 
      } 
     } 
} 

這裏是我的清單代碼。

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

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

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name="com.example.eblood.home" 
     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.eblood.MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="com.example.eblood.MAINACTIVITY" /> 


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

    <activity 
     android:name="com.example.eblood.Register" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.REGISTER" /> 

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



</application> 

和錯誤我得到是android.content.ActivityNotFoundException:無活動處理意向{行動= com.example.eblood.Register}

這裏是我的家。 java的

package com.example.eblood; 

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

public class home extends Activity { 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fragment_main); 
    Thread timer = new Thread(){ 
     public void run(){ 
      try{ 
       sleep(2000); 

      } catch (InterruptedException e){ 
       e.printStackTrace(); 
      } finally { 
       Intent openMainActivity = new Intent("com.example.eblood.MAINACTIVITY"); 
       startActivity(openMainActivity); 
      } 
    } 
    }; 
    timer.start();}{ 

}

}

如果你使用 Intent open = new Intent("com.example.eblood.Register");你會得到

回答

0

試試這個..

ActivityNotFoundException改變它作爲Intent open = new Intent(MainActivity.this,Register.class);

更改此

Intent open = new Intent("com.example.eblood.Register"); 
startActivity(open); 

Intent open = new Intent(MainActivity.this,Register.class); 
startActivity(open); 

改變這種

Intent in = new Intent("com.example.eblood.MainActivity"); 
startActivity(in); 

Intent in = new Intent(Register.this,MainActivity.class); 
startActivity(in); 

編輯

改變這一點。

Intent openMainActivity = new Intent("com.example.eblood.MAINACTIVITY"); 
startActivity(openMainActivity); 

Intent openMainActivity = new Intent(home.this,MainActivity.class); 
startActivity(openMainActivity); 
+0

不過我越來越ActivityNotFoundException.i想我需要改變的東西在明顯的代碼錯誤。 –

+0

@ user3550911從清單中刪除'intent-filter'並嘗試。像我的編輯。 – Hariharan

+0

如果我粘貼上面的代碼在我的清單它給我的錯誤重複註冊的活動,因爲我alredy使用

相關問題