下面是我的代码,每当我运行它时,它都会崩溃........
我正在尝试将一个字符串列表放入ListView,但每当我收到错误消息时:
致命异常:主要 无法启动活动ComponentInfo {com.ss.website/com.ss.website.MainActivity}:java.lang.ClassCastException:android.widget.SlidingDrawer无法在android.app中强制转换为android.support.v4.widget.DrawerLayout。 ActivityThread.performLaunchActivity(ActivityThread.java:2338)
提前致谢。
package com.ss.website;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
public class MainActivity extends ActionBarActivity {
private DrawerLayout drawer;
private ListView listview;
private String[] planets;
private LinearLayout linearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawer = (DrawerLayout) findViewById(R.id.slidingDrawer1);
planets=getResources().getStringArray(R.array.planets);
linearLayout = (LinearLayout)findViewById(R.id.content);
listview= (ListView) findViewById(R.id.listView1);
listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, planets));
}
}
答案 0 :(得分:0)
简单:DrawerLayout不是SlidingDrawer的子类或超类。