Я знаю, что этот вопрос уже задан много раз, но ни одно из решений, похоже, не работает для меня. Пожалуйста, помогите.java.lang.RuntimeException: Не удалось запустить активность ComponentInfo в searchview
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="abhimanyu.example.com.seed" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.MyCompatTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchResultsActivity" />
</activity>
<activity
android:name=".SearchResultsActivity"
android:label="@string/app_name"
android:theme="@style/Theme.MyCompatTheme">
<!-- to identify this activity as "searchable" -->
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
</application>
</manifest>
MainActivity.java
package abhimanyu.example.com.seed;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import abhimanyu.example.com.seed.adater.CustomListAdapter;
import abhimanyu.example.com.seed.app.AppController;
import abhimanyu.example.com.seed.model.Movie;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
// Movies json url
private static final String url="http://api.androidhive.info/json/movies.json";
private ProgressDialog pDialog;
private List<abhimanyu.example.com.seed.model.Movie> movieList = new ArrayList<Movie>();
private ListView listView;
private CustomListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
adapter = new CustomListAdapter(this,movieList);
listView.setAdapter(adapter);
pDialog = new ProgressDialog(this);
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
// changing action bar color
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#00897B")));
getActionBar().setHomeButtonEnabled(true);
getActionBar().setTitle("Abhimanyu");
getActionBar().setIcon(R.drawable.pp);
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
// hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("title"));
movie.setThumbnailUrl(obj.getString("image"));
movie.setRating(((Number) obj.get("rating"))
.doubleValue());
movie.setYear(obj.getInt("releaseYear"));
// Genre is json array
JSONArray genreArry = obj.getJSONArray("genre");
ArrayList<String> genre = new ArrayList<String>();
for (int j = 0; j < genreArry.length(); j++) {
genre.add((String) genreArry.get(j));
}
movie.setGenre(genre);
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
// hidePDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(movieReq);
}
@Override
public void onDestroy() {
super.onDestroy();
//hidePDialog();
}
/*
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
/* public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
// Inflate menu to add items to action bar if it is present.
inflater.inflate(R.menu.menu_main, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search_action).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
}*/
}
SearchResultActivity.java
package abhimanyu.example.com.seed;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuInflater;
public class SearchResultsActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
handleIntent(getIntent());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search_action).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return true;
}
@Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
//use the query to search
}
}
}
Я новичок в андроид развития, пожалуйста, помогите мне для этого исключения. Здесь Logcat
12-18 15: 57: 19,319 6757-6757/info.androidhive.customlistviewvolley Е/AndroidRuntime: неустранимый: Основной процесс: info.androidhive.customlistviewvolley, ПИД: 6757 java.lang.NullPointerException на info.androidhive.customlistviewvolley.MainActivity.onCreateOptionsMenu (MainActivity.java:142) на android.app.Activity.onCreatePanelMenu (Activity.java:2538) на com.android.internal.policy .impl.PhoneWindow.pre parePanel (PhoneWindow.java:436) на com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu (PhoneWindow.java:800) в com.android.internal.policy.impl.PhoneWindow $ 1.Run (PhoneWindow .java: 221) на android.view.Choreographer $ CallbackRecord.run (Choreographer.java:761) в android.view.Choreographer.doCallbacks (Choreographer.java:574) в android.view.Choreographer.doFrame (Хореограф.java:543) at android.view.Choreographer $ FrameDisplayEventReceiver.run (Хореограф.java:747) у androi d.os.Handler.handleCallback (Handler.java:733) на android.os.Handler.dispatchMessage (Handler.java:95) на android.os.Looper.loop (Looper.java:136) на android. app.ActivityThread.main (ActivityThread.java:5001) по адресу java.lang.reflect.Method.invokeNative (собственный метод) по адресу java.lang.reflect.Method.invoke (Method.java:515) at com. android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:601) в dalvik.system.NativeStart.main (собственный метод)
Разместите стек LogCat след .. – fractalwrench
отправил LogCat –
Ваш SearchView перекодировки неисправного в onCreateOptionsMenu(), убедитесь, что элемент с правильным идентификатором существует в R.menu.menu_main – fractalwrench