Reputation: 908
Hello guys this is my first question here, and yes I saw a lot of questions and answears like these and tried all the ways but I always get ~unable to instantiate activity componentinfo~ here I'll give my code, I'm just trying to make a simple list of Strings.
Here we come!
That's my class:
@package br.com.volkmann.volkmannbus;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class ConsultaActivity extends ListActivity {
String[] lista = {
"12:30",
"13:00"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consulta);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lista));
}
}
And this one my XML, Activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f8f18b" >
<ListView
android:id="@+id/listaHora"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Every time I start the activity there comes the error!
And this is the class that creates the Intent:
package br.com.volkmann.volkmannbus;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
public class HorarioActivity extends Activity {
private Button btConsulta;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_horario);
btConsulta = (Button) findViewById(R.id.btConsulta);
btConsulta.setOnClickListener(cliqueConsulta);
}
View.OnClickListener cliqueConsulta = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HorarioActivity.this, ConsultaActivity.class);
startActivity(intent);
}
};
}
That's the most especific I got! Sorry for bad english, I'm a Brazilian!
Upvotes: 1
Views: 967
Reputation: 76506
change
<ListView
android:id="@+id/listaHora"
to
<ListView
android:id="@android:id/list"
example code here http://developer.android.com/reference/android/app/ListActivity.html
Upvotes: 1
Reputation: 133560
You should change to
<ListView android:id="@android:id/list
Read this
http://developer.android.com/reference/android/app/ListActivity.html
In your case you get rid of setContentView(R.layout.activity_consulta);
as you have no other view's in your xml.
The ListActivity has a default layout that consists of a single, full-screen list in the center of the screen
Upvotes: 1
Reputation: 152827
With ListActivity
your layout must contain a ListView
with id @android:id/list
but you have @+id/listaHora
.
Other than that, have a look at the exception stacktrace in logcat, especially the "caused by" exception. Also when having such problems, include the full stacktrace in the question.
Upvotes: 1