tunerfreak
Lurker
i have been trying to learn android for a whole 2 days now and i am trying to make just a bunch of little programs to get use to it but i am having a problem with this one as it keeps force closing on me.
it happens when i select case 3, it is suppose to go to another class where i inpot something into a edittext field and it will then search google for that but it never even gets to the class. I traced it to where i see that it crashes when it gets to the startActivity(intent) in the search() function. what did i miss.
i attached my code:
androidmanifest.xml
it happens when i select case 3, it is suppose to go to another class where i inpot something into a edittext field and it will then search google for that but it never even gets to the class. I traced it to where i see that it crashes when it gets to the startActivity(intent) in the search() function. what did i miss.
i attached my code:
Code:
public class hellolistview extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] countries = getResources().getStringArray(R.array.countries_array); //gets list from strings.xml
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setTextFilterEnabled(true);
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){
switch(arg2){
case 0:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.android.com/")));
break;
case 1:
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("content://contacts/people/")));
break;
case 2:
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("tel:12345678910")));
break;
case 3:
search();
break;
case 4:
startActivity(new Intent(Intent.ACTION_VOICE_COMMAND));
break;
default:
break;
}
}
});
}
private void search(){
Intent intent = new Intent(hellolistview.this, search_web.class);
[COLOR=Black]hellolistview.this.startActivity(intent);[/COLOR] [COLOR=Red]throws exception here[/COLOR]
}
}
Code:
public class search_web extends Activity {
EditText helloName;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
Button searchButton = (Button) findViewById(R.id.Button01);
searchButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
helloName = (EditText)findViewById(R.id.EditText01);
final String wsearch = helloName.getText().toString(); //saves user input to search for
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, wsearch);
startActivity(intent);
}
});
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellolistview"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".hellolistview"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>