Когда я запускаю свое приложение на устройствах Android 2.3
.Я получаю java.lang.ClassCastException: android.widget.ImageView
. Но он отлично работает в других устройствах.java.lang.ClassCastException только на Android 2.3?
Если я комментирую приведенные ниже строки, он работает. Но я не могу найти ошибки в этих строках. Любые предложения ???
up = (Button) findViewById(R.id.up);
down = (Button) findViewById(R.id.down);
start = (Button) findViewById(R.id.start);
stop = (Button) findViewById(R.id.stop);
up.setOnClickListener(this);
down.setOnClickListener(this);
start.setOnClickListener(this);
stop.setOnClickListener(this);
активность
public class Presentation extends MainActivity implements ControllerDroidActionReceiver, OnClickListener
{
Button up, down, start, stop;
private ControllerDroid application;
private ControlView controlView;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.application = (ControllerDroid) this.getApplication();
ActionBar ab = getSupportActionBar();
ab.setTitle("Presentation");
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View contentView = inflater.inflate(R.layout.presentation, null, false);
mDrawer.addView(contentView, 0);
up = (Button) findViewById(R.id.up);
down = (Button) findViewById(R.id.down);
start = (Button) findViewById(R.id.start);
stop = (Button) findViewById(R.id.stop);
up.setOnClickListener(this);
down.setOnClickListener(this);
start.setOnClickListener(this);
stop.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
if (v == up)
{
application.sendAction(new KeyboardAction(19));
// Log.i("Button", "UP");
}
else if (v == down)
{
application.sendAction(new KeyboardAction(20));
}
else if (v == start)
{
application.sendAction(new KeyboardAction(26));
// Log.i("Button", "STARTED PPT");
}
else if (v == stop)
{
application.sendAction(new KeyboardAction(23));
}
}
@Override
protected void onResume()
{
super.onResume();
this.application.registerActionReceiver(this);
}
protected void onPause()
{
super.onPause();
this.application.unregisterActionReceiver(this);
}
public void receiveAction(ControllerDroidAction action)
{
if (action instanceof ScreenCaptureResponseAction)
{
this.controlView.receiveAction((ScreenCaptureResponseAction) action);
}
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="UP" />
<Button
android:id="@+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="DOWN" />
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="start" />
<Button
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="Stop" />
</LinearLayout>
Как выглядит ваш взгляд на XML? –
Это, безусловно, один из четырех вызовов 'findViewById' - узнать, какой из них комментирует один за раз. Затем проверьте свой XML, чтобы убедиться, что вы используете правильные идентификаторы. –
действительно, что ** HARD **, чтобы узнать, почему у вас ClassCastException? – pskink