![在此处输入图片说明] [1]我的应用程序出现问题。我需要更改 AppTheme ,我使用 name =" AppTheme" parent =" Theme.AppCompat.Light",但是当我改为 android:Theme.Holo 时,我的应用程序无效。
单击添加位置或我的适配器位置中的项目时出现错误。
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.example.pedropaulo.tp2.EditLocationActivity.onCreate(EditLocationActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1128)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
我的主要活动是:
public class SortedLocationsListActivity extends ListActivity implements AdapterView.OnItemClickListener {
LocationAdapter adapter;
InputStream inputStream;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new LocationAdapter(this,R.layout.row_location);
try
{
inputStream = getResources().openRawResource(R.raw.locations);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String recebe_string;
while ( (recebe_string = bufferedReader.readLine()) != null )
{
String[] a= recebe_string.split(";");
adapter.addLocation(a[0],a[1],a[2]);
}
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
inputStream.close();
}
catch (IOException e)
{
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_sorted_locations_list, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
switch (item.getItemId())
{
case R.id.action_settings:
Intent loc = new Intent(this,EditLocationActivity.class);
startActivityForResult(loc, 1);
// Lancez votre EditLocationActivity
return true;
default:
return super.onMenuItemSelected(featureId, item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 1)
{
if(resultCode == RESULT_OK)
{
String Adres = data.getStringExtra("Address");
String Nom = data.getStringExtra("Name");
Calendar c = Calendar.getInstance();
long la = c.getTimeInMillis();
String Dat = Long.toString(la);
adapter.addLocation(Nom, Adres, Dat);
adapter.notifyDataSetChanged();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LocationAdapter.Location loca = (LocationAdapter.Location) adapter.getItem(position);
Intent intent1;
intent1 = new Intent(SortedLocationsListActivity.this, MapActivity.class);
intent1.putExtra("nome",loca.name);
intent1.putExtra("endereco",loca.address);
intent1.putExtra("datis",loca.date);
Log.d("teste ", loca.name);
startActivityForResult(intent1, 1);
}
}
答案 0 :(得分:1)
appcompat-v7
个活动(包括ActionBarActivity
)仅支持AppCompat
个主题。如果您不想使用AppCompat
主题,则需要扩展其他类,例如Activity
。