Searchable interface - Application force closes
So im making an android app and once trying to go to my last activity my app crashes. Please check to see if there's something im missing.
Search1.Java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Search1 extends Activity {
String searchtype="null";
/** Called when the activity is first created. */
public void onCreate(Bundle 开发者_Go百科savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
Button ISBN = (Button) findViewById(R.id.ISBN);
ISBN.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onSearchRequested();
searchtype="ISBN";
}
});
Button Title = (Button) findViewById(R.id.Title);
Title.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onSearchRequested();
searchtype="Title";
}
//various listeners follow
});...
Searchresults.java
public class SearchResults extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
}
}
and finally the manifest for both files
<activity android:name=".SearchResults" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
and
<activity android:name=".Search1"
android:label="@string/app_name"
android:screenOrientation="portrait">
<meta-data android:name="android.app.default_searchable"
android:value=".SearchResults" />
</activity>
The Searchresults activity is still incomplete(The xml file only contains a textview) but i still dont think the app should force close when i try to enter the activity. Is there something wrong with this code?
I usually forget to put in my activity in the AndroidManifest.xml, have you checked if that's the problem? =)
精彩评论