开发者

Why does my application keep getting "The application <ClassName> (<package.ClassName>) has stopped unexpectedly. Please try again later." error?

开发者 https://www.devze.com 2022-12-20 07:19 出处:网络
I followed the developer guides on the Android website. It is working fine for a Hello World application but when I try and transition between Activities, my application keeps giving an \"The applicat

I followed the developer guides on the Android website. It is working fine for a Hello World application but when I try and transition between Activities, my application keeps giving an "The application () has stopped unexpectedly. Please try again later." error and the application then quits. This happens when I click the button in the Subscribe Activity.

Subscribe.java

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

    Button subButton = (Button)findViewById(R.id.subscribe);
    subButton.setOnClickListener(this);
}

public void onClick(View v) {
    Intent subIntent = new Intent(Subscribe.this,Subscribed.class);
    startActivity(subIntent);
    }
}

Subscribed.java

public class Subscribed extends Act开发者_高级运维ivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subscribed);
 }

}

Logcat Log File


The Application Name has stopped unexpectedly message is displayed when an uncaught exception occurs. This exception will be in the logcat output, along with a Stack Trace.

Looking at the output you posted I found:

02-11 02:16:00.951: ERROR/AndroidRuntime(188): android.content.ActivityNotFoundException:
Unable to find explicit activity class {org.ghoshna/org.ghoshna.Subscribed}; have you declared this activity in your AndroidManifest.xml?

So the problem looks to be that you haven't defined your Subscribed Activity in your AndroidManifest.xml file.

You need to add a line like the following to the file:

<activity android:name=".Subscribed"/>


Please provide a little bit more data - what is the logcat-output for this error?

You get the logcat either in eclipse by going to the DDMS-Perspective, choosing the device the error occurred on and then looking at the LogCat-View.

Or

by invoking adb -d logcat (for hardware devices) or adb -e logcat (for emulators) on the commandline. The adb-executable is in your android-sdk-directory in the subdirectory ./tools.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号