-2

所以,我的应用程序很简单,在主屏幕中我应该单击一个按钮,该按钮将启动另一个带有选项卡的活动,但是一旦我单击该按钮,该活动就不会启动,并且我收到错误:此日志未找到源:

Thread [<3> main] (Suspended (exception RuntimeException))  
    <VM does not provide monitor information>   
    ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2503  
    ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2519   
    ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 123 
    ActivityThread$H.handleMessage(Message) line: 1870  
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 123 
    ActivityThread.main(String[]) line: 4370    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 521  
    ZygoteInit$MethodAndArgsCaller.run() line: 868  
    ZygoteInit.main(String[]) line: 626 
    NativeStart.main(String[]) line: not available [native method]  

这是 mainActivity:Bienvenue.java:

public class Bienvenue extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_bienvenue);
    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new View.OnClickListener(){
        public void onClick(View arg0) {
             // here i call new screen;
             Intent i = new Intent(Bienvenue.this, Histoire.class);
             startActivity(i);
             } 
    });

}

这是清单的一部分:

<activity android:name=".Splash" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.category.MAIN" />

            <category android:name="android.intent.category.LUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Bienvenue" android:exported="false" android:label="@string/app_name">
        <intent-filter>
            <action android:name="com.maghribouna.amine.ters.Bienvenue" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity android:name=".Histoire" android:exported="false" android:label="@string/app_name">

    </activity>

我看不出添加其他代码的理由,所以错误必须出现在这些代码中!

4

2 回答 2

1

这就是问题所在

<activity android:name=".Splash" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.category.MAIN" />



   **<category android:name="android.intent.category.LUNCHER" />**


  </intent-filter>
</activity>

它是

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
             // Launcher!
        <category android:name="android.intent.category.LAUNCHER" />
于 2012-12-26T16:59:43.560 回答
0
final Button button1 = (Button) findViewById(R.id.buttonIdName);
button1.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        startActivity(new Intent(Activity1.this, Activity2.class));
    }
});

这是我用来切换活动的代码。您的按钮需要使用在活动的布局 xml 中设置的 ID(然后在 R.java 中引用)。如果您的按钮 ID 是“buttonStart”,请确保 findViewById() 使用该名称。

如果您的问题比这更深,一些代码会很棒。

编辑:试试这个:

public class Bienvenue extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bienvenue);

    final Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            startActivity(new Intent(Bienvenue.this, Histoire.class));
        } 
    });

}
于 2012-12-26T16:42:03.597 回答