我在下次活动时遇到一些问题 -
我做了一个按钮,当你点击它时,正在制作一个意图,然后你startActivity()
有了意图。
我声明了源类和目标类。每次我点击按钮,它都会关闭应用程序并说“不幸的是,我的第一个应用程序已停止”。有帮助吗? 提前谢谢。
package com.myfirstapplication.owner.myfirstapplication;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button nextAc;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nextAc = (Button) findViewById(R.id.nextPageButton);
nextAc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
Bundle fromMain = new Bundle();
fromMain.putString("BundleInfo","Look at that.");
i.putExtras(fromMain);
startActivity(i);
}
});
}
}
记录:
06-15 12:10:03.673 2389-2389/com.myfirstapplication.owner.myfirstapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myfirstapplication.owner.myfirstapplication, PID: 2389
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapplication.owner.myfirstapplication/com.myfirstapplication.owner.myfirstapplication.SecondActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.myfirstapplication.owner.myfirstapplication.MainActivity$1.onClick(MainActivity.java:76)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-15 12:10:06.361 2389-2389/com.myfirstapplication.owner.myfirstapplication I/Process: Sending signal. PID: 2389 SIG: 9
第二项活动:
package com.myfirstapplication.owner.myfirstapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
TextView tv = (TextView)findViewById(R.id.tvID);
Bundle fromMain = getIntent().getExtras();
tv.setText(fromMain.getString("BundleInfo"));
}
}
答案 0 :(得分:1)
在清单文件中声明您的SecondActivity。
<application>
<activity android:name=".SecondActivity" />
</application>
答案 1 :(得分:1)
我想您忘了在Manifest.xml中声明您的活动
只需在Manifest中对您的Activity类进行decalre,就可以解决您的问题:)
答案 2 :(得分:0)
如果您忘记在清单文件中添加活动,则会发生以下异常:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.myfirstapplication.owner.myfirstapplication/com.myfirstapplication.owner.myfirstapplication.SecondActivity}; have you declared this activity in your AndroidManifest.xml?
要向清单文件添加新活动,只需在下面写一行:
<activity android:name=".SecondActivity"/> // if your activity is in main package
或
<activity android:name="com.myfirstapplication.owner.myfirstapplication.SecondActivity"/> // if your activity is any other package.
您的代码之间会添加活动。
请记住,我不会在您的活动中添加任何操作或模式。如果您对自己的活动采取了某些行动,可以在此处提供。
快乐的编码!!!
答案 3 :(得分:0)
在清单文件中声明活动
<activity
android:name=".secondActivity"
/>
在应用程序标记下