android - Unfortunately button has stopped-search dialog? -


i follow tutorial search dialog (http://devmobapps.blogspot.com/2011/10/using-android-search-dialog-part-3.html). in eclipse there no red errors, when try run application unfortunately button has stopped.

logcat

    11-12 23:31:26.499: d/androidruntime(668): checkjni on 11-12 23:31:26.573: d/dalvikvm(668): trying load lib libjavacore.so 0x0 11-12 23:31:26.593: d/dalvikvm(668): added shared lib libjavacore.so 0x0 11-12 23:31:26.663: d/dalvikvm(668): trying load lib libnativehelper.so 0x0 11-12 23:31:26.663: d/dalvikvm(668): added shared lib libnativehelper.so 0x0 11-12 23:31:27.772: d/androidruntime(668): calling main entry com.android.commands.am.am 11-12 23:31:27.823: i/activitymanager(150): start {act=android.intent.action.main cat=[android.intent.category.launcher] flg=0x10000000 cmp=com.bogdanskoric.dictionary/.mainactivity u=0} pid 668 11-12 23:31:27.833: w/windowmanager(150): failure taking screenshot (246x410) layer 21005 11-12 23:31:27.913: d/dalvikvm(679): not late-enabling checkjni (already on) 11-12 23:31:27.923: d/androidruntime(668): shutting down vm 11-12 23:31:27.933: d/dalvikvm(36): wait_for_concurrent_gc blocked 0ms 11-12 23:31:27.942: i/activitymanager(150): start proc com.bogdanskoric.dictionary activity com.bogdanskoric.dictionary/.mainactivity: pid=679 uid=10051 gids={1028} 11-12 23:31:27.993: i/androidruntime(668): note: attach of thread 'binder_3' failed 11-12 23:31:27.993: d/dalvikvm(668): gc_concurrent freed 102k, 77% free 489k/2048k, paused 1ms+1ms, total 16ms 11-12 23:31:28.013: d/jdwp(668): got wake-up signal, bailing out of select 11-12 23:31:28.013: d/dalvikvm(668): debugger has detached; object registry had 1 entries 11-12 23:31:28.114: d/dalvikvm(36): gc_explicit freed 38k, 4% free 7964k/8259k, paused 8ms+14ms, total 185ms 11-12 23:31:28.124: d/dalvikvm(36): wait_for_concurrent_gc blocked 0ms 11-12 23:31:28.303: d/dalvikvm(36): gc_explicit freed <1k, 4% free 7964k/8259k, paused 27ms+48ms, total 181ms 11-12 23:31:28.333: d/dalvikvm(36): wait_for_concurrent_gc blocked 0ms 11-12 23:31:28.453: d/dalvikvm(36): gc_explicit freed <1k, 4% free 7964k/8259k, paused 5ms+13ms, total 126ms 11-12 23:31:28.823: e/trace(679): error opening trace file: no such file or directory (2) 11-12 23:31:29.182: i/activitythread(679): pub com.bogdanskoric.dictionary.suggestionprovider: com.bogdanskoric.dictionary.suggestionprovider 11-12 23:31:29.413: d/androidruntime(679): shutting down vm 11-12 23:31:29.413: w/dalvikvm(679): threadid=1: thread exiting uncaught exception (group=0x40a13300) 11-12 23:31:29.453: e/androidruntime(679): fatal exception: main 11-12 23:31:29.453: e/androidruntime(679): java.lang.runtimeexception: unable start activity componentinfo{com.bogdanskoric.dictionary/com.bogdanskoric.dictionary.mainactivity}: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activitythread.access$600(activitythread.java:130) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 11-12 23:31:29.453: e/androidruntime(679):  @ android.os.handler.dispatchmessage(handler.java:99) 11-12 23:31:29.453: e/androidruntime(679):  @ android.os.looper.loop(looper.java:137) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activitythread.main(activitythread.java:4745) 11-12 23:31:29.453: e/androidruntime(679):  @ java.lang.reflect.method.invokenative(native method) 11-12 23:31:29.453: e/androidruntime(679):  @ java.lang.reflect.method.invoke(method.java:511) 11-12 23:31:29.453: e/androidruntime(679):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 11-12 23:31:29.453: e/androidruntime(679):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 11-12 23:31:29.453: e/androidruntime(679):  @ dalvik.system.nativestart.main(native method) 11-12 23:31:29.453: e/androidruntime(679): caused by: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list' 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.listactivity.oncontentchanged(listactivity.java:243) 11-12 23:31:29.453: e/androidruntime(679):  @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:259) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activity.setcontentview(activity.java:1867) 11-12 23:31:29.453: e/androidruntime(679):  @ com.bogdanskoric.dictionary.mainactivity.oncreate(mainactivity.java:26) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activity.performcreate(activity.java:5008) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 11-12 23:31:29.453: e/androidruntime(679):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 11-12 23:31:29.453: e/androidruntime(679):  ... 11 more 11-12 23:31:29.482: w/activitymanager(150):   force finishing activity com.bogdanskoric.dictionary/.mainactivity 11-12 23:31:29.523: w/windowmanager(150): failure taking screenshot (246x410) layer 21010 11-12 23:31:30.033: w/activitymanager(150): activity pause timeout activityrecord{413b0b80 com.bogdanskoric.dictionary/.mainactivity} 11-12 23:31:30.363: i/choreographer(272): skipped 60 frames!  application may doing work on main thread. 11-12 23:31:32.302: i/process(679): sending signal. pid: 679 sig: 9 11-12 23:31:32.493: w/inputmethodmanagerservice(150): window focused, ignoring focus gain of: com.android.internal.view.iinputmethodclient$stub$proxy@41394dc8 attribute=null 11-12 23:31:32.698: i/activitymanager(150): process com.bogdanskoric.dictionary (pid 679) has died. 11-12 23:31:41.195: w/activitymanager(150): activity destroy timeout activityrecord{413b0b80 com.bogdanskoric.dictionary/.mainactivity} 11-12 23:33:21.643: d/dalvikvm(255): gc_concurrent freed 383k, 7% free 8537k/9159k, paused 30ms+6ms, total 77ms 11-12 23:40:21.313: e/throttleservice(150): problem during onpollalarm: java.lang.illegalstateexception: problem parsing stats: java.io.filenotfoundexception: /proc/net/xt_qtaguid/iface_stat_all: open failed: enoent (no such file or directory) 11-12 23:40:50.673: d/dalvikvm(255): gc_concurrent freed 384k, 7% free 8537k/9159k, paused 24ms+6ms, total 73ms 11-12 23:48:25.913: d/dalvikvm(255): gc_concurrent freed 384k, 7% free 8537k/9159k, paused 28ms+6ms, total 71ms 11-12 23:50:00.373: d/dalvikvm(150): gc_concurrent freed 582k, 7% free 11556k/12359k, paused 38ms+52ms, total 327ms 11-12 23:50:21.313: e/throttleservice(150): problem during onpollalarm: java.lang.illegalstateexception: problem parsing stats: java.io.filenotfoundexception: /proc/net/xt_qtaguid/iface_stat_all: open failed: enoent (no such file or directory) 

mainactivity.java

package com.bogdanskoric.dictionary;   import android.app.listactivity; import android.app.searchmanager; import android.content.intent; import android.database.cursor; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.simplecursoradapter; import android.widget.toast;  public class mainactivity extends listactivity {      private edittext text;     private button add;     private recordsdbhelper mdbhelper;      @override     public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);   mdbhelper = new recordsdbhelper(this);   intent intent = getintent();   if (intent.action_search.equals(intent.getaction())) {       string query = intent.getstringextra(searchmanager.query);       showresults(query);  } else if (intent.action_view.equals(intent.getaction())){                  intent recordintent = new intent(this, recordactivity.class);                 recordintent.setdata(intent.getdata());                 startactivity(recordintent);                 finish();  }   add = (button) findviewbyid(r.id.add);  text = (edittext) findviewbyid(r.id.text);  add.setonclicklistener(new view.onclicklistener() {      public void onclick(view view) {          string data = text.gettext().tostring();   if (!data.equals("")) {       savetask(data);       text.settext("");   }      }  });      }      private void savetask(string data) {         mdbhelper.createrecord(data);     }      private void showresults(string query) {           cursor cursor = managedquery(suggestionprovider.content_uri, null, null,                                 new string[] {query}, null);         if (cursor == null) {             toast.maketext(this, "there no results", toast.length_short).show();         } else {              string[] = new string[] { recordsdbhelper.key_data };             int[] = new int[] { r.id.text1 };             simplecursoradapter records = new simplecursoradapter(this, r.layout.record, cursor, from, to);             getlistview().setadapter(records);                     }             }       public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.main, menu);         return true;      } 

recordshelper.java

import java.util.hashmap;  import android.app.searchmanager; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.database.sqlite.sqlitequerybuilder; import android.provider.basecolumns; import android.util.log;  public class recordsdbhelper {       public static final string key_data = searchmanager.suggest_column_text_1;      private static final string tag = "recordsdbhelper";     private databasehelper mdbhelper;     private sqlitedatabase mdb;      private static final string database_name = "datas";     private static final string database_table = "records";     private static final int database_version = 2;       private static final string database_create =   "create virtual table " + database_table +                 " using fts3 (" + key_data + ");";       private static final hashmap<string,string> mcolumnmap = buildcolumnmap();       public cursor getrecord(string rowid, string[] columns) {         string selection = "rowid = ?";         string[] selectionargs = new string[] {rowid};          return query(selection, selectionargs, columns);     }       public cursor getrecordmatches(string query, string[] columns) {         string selection = key_data + " match ?";         string[] selectionargs = new string[] {query+"*"};          return query(selection, selectionargs, columns);     }        private static hashmap<string,string> buildcolumnmap() {         hashmap<string,string> map = new hashmap<string,string>();         map.put(key_data, key_data);         map.put(basecolumns._id, "rowid " +                 basecolumns._id);         map.put(searchmanager.suggest_column_intent_data_id, "rowid " +                 searchmanager.suggest_column_intent_data_id);         return map;     }       private cursor query(string selection, string[] selectionargs, string[] columns) {          sqlitequerybuilder builder = new sqlitequerybuilder();         builder.settables(database_table);         builder.setprojectionmap(mcolumnmap);          cursor cursor = builder.query(mdbhelper.getreadabledatabase(),                 columns, selection, selectionargs, null, null, null);         if (cursor == null) {             return null;         } else if (!cursor.movetofirst()) {             cursor.close();             return null;         }         return cursor;     }           private static class databasehelper extends sqliteopenhelper {          databasehelper(context context) {   super(context, database_name, null, database_version);  }   @override  public void oncreate(sqlitedatabase db) {      db.execsql(database_create);  }   @override  public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {      log.w(tag, "upgrading database version " + oldversion + " "    + newversion + ", destroy old data");      db.execsql("drop table if exists records");      oncreate(db);  }     }      public recordsdbhelper(context context) {         mdbhelper = new databasehelper(context);     }       public long createrecord(string data) {         mdb = mdbhelper.getwritabledatabase();  contentvalues initialvalues = new contentvalues();  initialvalues.put(key_data, data);  return mdb.insert(database_table, null, initialvalues);     } } 

sugestionprovider.java

import android.app.searchmanager; import android.content.contentprovider; import android.content.contentresolver; import android.content.contentvalues; import android.content.urimatcher; import android.database.cursor; import android.net.uri; import android.provider.basecolumns;  public class suggestionprovider extends contentprovider{      private recordsdbhelper mdbhelper;      public static string authority = "com.example.search.suggestionprovider";     public static final uri content_uri = uri.parse("content://" + authority + "/records");       public static final string records_mime_type = contentresolver.cursor_dir_base_type +                                                   "/vnd.example.search";     public static final string record_mime_type = contentresolver.cursor_item_base_type +                                                   "/vnd.example.search";       private static final int search_records = 0;     private static final int get_record = 1;     private static final int search_suggest = 2;     private static final urimatcher surimatcher = makeurimatcher();      @override     public boolean oncreate() {         mdbhelper = new recordsdbhelper(getcontext());         return true;     }       @override     public cursor query(uri uri, string[] projection, string selection,        string[] selectionargs, string sortorder) {          switch (surimatcher.match(uri)) {             case search_suggest:                 if (selectionargs == null) {                     throw new illegalargumentexception(                         "selectionargs must provided uri: " + uri);                 }                 return getsuggestions(selectionargs[0]);             case search_records:                 if (selectionargs == null) {                     throw new illegalargumentexception(                         "selectionargs must provided uri: " + uri);                 }                 return search(selectionargs[0]);             case get_record:                 return getrecord(uri);             default:                 throw new illegalargumentexception("unknown uri: " + uri);         }  }      private cursor getsuggestions(string query) {         query = query.tolowercase();         string[] columns = new string[] {              basecolumns._id,              recordsdbhelper.key_data,              searchmanager.suggest_column_intent_data_id};         return mdbhelper.getrecordmatches(query, columns);     }      private cursor search(string query) {         query = query.tolowercase();         string[] columns = new string[] {             basecolumns._id,             recordsdbhelper.key_data};          return mdbhelper.getrecordmatches(query, columns);     }      private cursor getrecord(uri uri) {         string rowid = uri.getlastpathsegment();         string[] columns = new string[] {             recordsdbhelper.key_data};          return mdbhelper.getrecord(rowid, columns);     }       private static urimatcher makeurimatcher() {         urimatcher matcher =  new urimatcher(urimatcher.no_match);          matcher.adduri(authority, "records", search_records);         matcher.adduri(authority, "records/#", get_record);          matcher.adduri(authority, searchmanager.suggest_uri_path_query, search_suggest);         matcher.adduri(authority, searchmanager.suggest_uri_path_query + "/*", search_suggest);         return matcher;     }       @override     public string gettype(uri uri) {         switch (surimatcher.match(uri)) {             case search_records:                 return records_mime_type;             case search_suggest:              return searchmanager.suggest_mime_type;             case get_record:                 return record_mime_type;             default:                 throw new illegalargumentexception("unknown url " + uri);         }      }      @override     public int update(uri uri, contentvalues values, string selection,                    string[] selectionargs) {         throw new unsupportedoperationexception();     }      @override     public uri insert(uri uri, contentvalues values) {         throw new unsupportedoperationexception();     }      @override     public int delete(uri uri, string selection, string[] selectionargs) {         throw new unsupportedoperationexception();     } } 

recordactivity.java

package com.bogdanskoric.dictionary;  import android.app.activity; import android.database.cursor; import android.net.uri; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.widget.textview;  public class recordactivity extends activity {   @override  public void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      setcontentview(r.layout.record_activity);        uri uri = getintent().getdata();             cursor cursor = managedquery(uri, null, null, null, null);          if (cursor == null) {             finish();         } else {              cursor.movetofirst();              textview record = (textview) findviewbyid(r.id.record_header);             int rindex = cursor.getcolumnindexorthrow(recordsdbhelper.key_data);              record.settext(cursor.getstring(rindex));         }     }       @override     public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.main, menu);         return true;     } } 

activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="horizontal" >      <edittext         android:id="@+id/text"         android:layout_width="wrap_content"         android:layout_height="50dp"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="16dp"         android:layout_weight="10"         android:ems="10"         android:text="@string/text" >          <requestfocus />     </edittext>      <button         android:id="@+id/add"         android:layout_width="70dp"         android:layout_height="50dp"         android:layout_above="@+id/empty"         android:layout_torightof="@+id/text"         android:ems="5"         android:text="@string/add"         android:textsize="15dp" />      <textview         android:id="@+id/empty"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/text"         android:layout_toleftof="@+id/add"         android:text="@string/no_records" />      <listview         android:id="@+id/list"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignleft="@+id/empty"         android:layout_below="@+id/empty"         android:layout_margintop="16dp" >     </listview>  </relativelayout> 

record_activity.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"        android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:padding="10dp">       <textview             android:id="@+id/record_header"             android:textsize="25dp"             android:textcolor="?android:textcolorprimary"             android:layout_width="wrap_content"             android:layout_height="wrap_content"/>  </linearlayout> 

record.xml

<?xml version="1.0" encoding="utf-8"?>    <textview      android:id ="@+id/text1"     xmlns:android ="http://schemas.android.com/apk/res/android"     android:layout_width ="wrap_content"     android:layout_height ="wrap_content"     /> 

string.xml

<?xml version="1.0" encoding="utf-8"?> <resources>      <string name="app_name">dictionary</string>     <string name="add">add</string>     <string name="text">enter text</string>     <string name="no_records">there no records in table</string>     <string name="search_hint">add</string>     <string name="search">search</string>     <string name="action_settings">settings</string>  </resources> 

xml/searchable.xml

<?xml version="1.0" encoding="utf-8"?>      <searchable xmlns:android="http://schemas.android.com/apk/res/android"     android:label="@string/app_name"     android:hint="@string/search_hint"      android:searchmode="queryrewritefromtext"     android:includeinglobalsearch="true"     android:searchsuggestauthority="com.example.search.suggestionprovider"      android:searchsuggestintentaction="android.intent.action.view"     android:searchsuggestintentdata="content://com.example.search.suggestionprovider/records"     android:searchsuggestthreshold="1"     android:searchsuggestselection=" ?"> </searchable> 

use xml list

<listview     android:id="@android:id/list"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignleft="@+id/empty"     android:layout_below="@+id/empty"     android:layout_margintop="16dp" > </listview> 

since using listactivity xml file must specify keyword android while mentioning id.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -