我是android的新手
我有2个文件login.java和depan.java 当我点击按钮登录它是正常的文件depan.java加载成功
当我输入此代码时,似乎错误开始
buttonuser = (ImageButton) findViewById(R.id.BtnUser);
depan.class无法加载,应用程序崩溃。
depan.class
public class Depan extends Activity{
ImageButton buttonuser, buttonvlan;
@Override
public void onCreate(Bundle wibi) {
// TODO Auto-generated method stub
super.onCreate(wibi);
setContentView (R.layout.depan);
buttonuser = (ImageButton) findViewById(R.id.BtnUser);
depan.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<ImageView
android:id="@+id/BtnUser"
android:layout_width="150dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/manajemenuser" />
<ImageView
android:id="@+id/BtnVlan"
android:layout_width="150dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/manajemenvlan" />
</LinearLayout>
清单
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".login"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Depan"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".user"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".vlan"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
答案 0 :(得分:1)
buttonuser = (**ImageButton**) findViewById(R.id.BtnUser);
<**ImageView**
android:id="@+id/**BtnUser**"
android:layout_width="150dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/manajemenuser" />
ImageView BtnUser ....你为什么把它投射到ImageButton ???
答案 1 :(得分:0)
将xml中的ImageView更改为ImageButton