sugianto
sugianto

Reputation: 107

JAVA - Android error: The application has stopped unexpectedly please try again

I made an app which is just working fine. But when i click on "cancel" or "ok" button when i run the program, instead of linking me to result.java, the simulator give me "The application has stopped unexpectedly please try again" Here's the code

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.database.CursorJoiner.Result;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;

public class lib_main extends Activity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onAddClick (View botton){

AutoCompleteTextView title = (AutoCompleteTextView)findViewById(R.id.Title);
AutoCompleteTextView author = (AutoCompleteTextView)findViewById(R.id.Author); 
AutoCompleteTextView isbn = (AutoCompleteTextView)findViewById(R.id.ISBN);

Intent intent = new Intent();
intent.setClass(this,Result.class);

intent.putExtra("Title", title.getText().toString());
intent.putExtra("Author", author.getText().toString()); 
intent.putExtra("ISBN", isbn.getText().toString());
startActivity(intent);
}

public void onCancelClick(View botton){



Intent intent = new Intent();
intent.setComponent(new ComponentName(this,Result.class));

intent.putExtra("Cancel","Cancel");
startActivity(intent);
}

}

this is Result.java

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView;

public class Result extends Activity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);

TextView resultText=(TextView)findViewById(R.id.resultText);

Bundle bundle =getIntent().getExtras();
if(bundle.getString("Cancel")!= null)
{resultText.setText("operation cancel");}
else
{  String book =bundle.getString ("Title");
   String title =bundle.getString ("Author");
   String isbn =bundle.getString ("ISBN");
   resultText.setText(
     getString (R.string.resultOk)+""+book+""+ title+""+isbn);


 }
 }
 }

the error log write "No command output when running:'am start-n com.Library.doc/com.Library.doc.lib_main-a android.intent.action.MAIN-c android.intent.category.LAUNCHER' in device emulator-5554"

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.Library.doc"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".lib_main"
              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=".Result"
              android:label="@string/result">

    </activity>
</application>
<uses-sdk android:minSdkVersion="8" />

Can anyone help me with this problem?

Upvotes: 0

Views: 3930

Answers (1)

wheaties
wheaties

Reputation: 35970

Quick question, have you registered both Activities? If you only provide for one in your manifest file you're going to get this error every time you attempt to do something involving the unregistered activity.

Upvotes: 1

Related Questions