问题描述
两个Activity,FirstActivity(有个跳转的按钮,和一个TextView和一个EditText)和SecondActivity(有个返回的按钮和一个TextView,和一个EditText),我知道通过Bundle可以从FirstActivity像SecondActivity跳转并将数据从FirstActivity传送到SecondActivity中并且用TextView'显示出来,但是我现在面临了一个问题就是我搜索的结果就是null空值,怎样才能调用到我的lucene的包的结果并输出?
解决方案
解决方案二:
我的部分代码~!packagecom.samples;importandroid.app.Activity;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.util.Log;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.TextView;publicclassAndLucextendsActivity{/**Calledwhentheactivityisfirstcreated.*/EditTextinputEditText;TextViewresulTextView;ButtongoButton;//Stringresult;ThreadLucthread;publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);inputEditText=(EditText)findViewById(R.id.search);resulTextView=(TextView)findViewById(R.id.result);goButton=(Button)findViewById(R.id.BTN_LAUNCH);goButton.setOnClickListener(newOnClickListener(){publicvoidonClick(Viewv){//TODOAuto-generatedmethodstubStringinput=inputEditText.getText().toString();thread=newThreadLuc(input,handler);thread.start();}});}Handlerhandler=newHandler(){publicvoidhandleMessage(Messagemsg){Log.i("Luc","Luc-handle");Bundlebundle=msg.getData();Stringresult=bundle.getString("result");resulTextView.setText("检索结果:"+result);super.handleMessage(msg);}};}
解决方案三:
packagecom.samples;importjava.io.IOException;importorg.apache.lucene.index.CorruptIndexException;importorg.apache.lucene.queryParser.ParseException;importorg.apache.lucene.search.highlight.InvalidTokenOffsetsException;importorg.apache.lucene.store.LockObtainFailedException;importtest.test;importandroid.os.Bundle;importandroid.os.Handler;importandroid.os.Message;importandroid.util.Log;publicclassThreadLucextendsThread{Stringinput;Handlerhandler;Stringresult;publicThreadLuc(Stringinput,Handlerhandler){//TODOAuto-generatedconstructorstubthis.input=input;this.handler=handler;//Log.i("Luc","ThreadLuc");}publicvoidrun(){//Bundlebundle=newBundle();//bundle.putString("result",result);//Messagemsg=newMessage();//msg.setData(bundle);//handler.sendMessage(msg);//Log.i("Luc","thread-->run");//try{//testtempTest=newtest();//result=tempTest.search(input);//}catch(CorruptIndexExceptione){////TODOAuto-generatedcatchblock//e.printStackTrace();//Log.i("Luc","ThreadLuc---1");//}catch(LockObtainFailedExceptione){////TODOAuto-generatedcatchblock//Log.i("Luc","ThreadLuc---2");//e.printStackTrace();//}catch(IOExceptione){////TODOAuto-generatedcatchblock//Log.i("Luc","ThreadLuc---3");//e.printStackTrace();//}catch(ParseExceptione){////TODOAuto-generatedcatchblock//Log.i("Luc","ThreadLuc---4");//e.printStackTrace();//}catch(InvalidTokenOffsetsExceptione){////TODOAuto-generatedcatchblock////Log.i("Luc","ThreadLuc---5");e.printStackTrace();//}Bundlebundle=newBundle();bundle.putString("result",result);Messagemsg=handler.obtainMessage();msg.setData(bundle);handler.sendMessage(msg);}}
解决方案四:
调用这里的result~!packagetest;importjava.io.IOException;importjava.util.Date;importorg.apache.lucene.index.CorruptIndexException;importorg.apache.lucene.queryParser.ParseException;importorg.apache.lucene.search.highlight.InvalidTokenOffsetsException;importorg.apache.lucene.store.LockObtainFailedException;importFunction.addIndex;importFunction.createIndex;importFunction.define;importFunction.search;publicclasstest{publicStringsearch(Stringargs)throwsCorruptIndexException,LockObtainFailedException,IOException,ParseException,InvalidTokenOffsetsException{//定义一下data和Index的位置defined=newdefine();d.setDataPath("/mnt/Sdcard/Data");d.setIndexPath("/mnt/Sdcard/Index");d.setSearchString(args);Datestart=newDate();createIndexcrtidx=newcreateIndex();crtidx.cIndex(d);//addIndexadidx=newaddIndex();//adidx.aIndex(d);Dateend=newDate();System.out.println(end.getTime()-start.getTime());searchsrh=newsearch();srh.sIndex(d);Stringresult=srh.getresult();if(result==null){return"error";}else{returnresult;}}}