0
我正在製作一個應用程序,其中包含用於啓動活動Prov.java的imagebutton。Imagebutton不工作
這個程序一直在工作之前,但今天我嘗試在xml中激活觸覺反饋,但然後再次刪除它。突然之間「Prov.java」的按鈕不起作用,並給我一個nullpointerexception。請告訴我該怎麼做來解決它!
的ImageButton:
<ImageButton
android:id="@+id/a6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/a5"
android:layout_below="@+id/a5"
android:background="@null"
android:contentDescription="@string/app_name"
android:src="@drawable/iconprov" />
Android清單:
<activity
android:name=".Prov"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="com.felectronix.kyrkeror.PROV" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
主菜單:
public class Huvudmeny extends Activity {
ImageButton imageButton;
int bak;
int em;
SharedPreferences data;
public static String filename = "bg";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
em = R.drawable.bakgrund;
data = getSharedPreferences(filename, 0);
bak = data.getInt("bakgrund", em);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
RelativeLayout bg = (RelativeLayout) findViewById(R.id.might);
bg.setBackgroundResource(bak);
ConnectivityManager connectivityManager = (ConnectivityManager) this
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
addListenerOnButton();
addListenerOnButton1();
addListenerOnButton2();
addListenerOnButton3();
addListenerOnButton4();
addListenerOnButton5();
addListenerOnButton6();
addListenerOnButton7();
addListenerOnButton8();
addListenerOnButton9();
addListenerOnButton10();
addListenerOnButton11();
if (networkInfo != null && networkInfo.isConnected()) {
} else {
startActivity(new Intent("com.felectronix.kyrkeror.NOINTERNET"));
finish();
}
}
主菜單onclicklistener:
public void addListenerOnButton9() {
imageButton = (ImageButton) findViewById(R.id.a6);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent("com.felectronix.kyrkeror.PROV"));
finish();
}
});
}
您是否在恢復更改後「清理」了您的項目? – waqaslam 2012-02-19 16:48:10
清理項目?因爲我不知道它是什麼......可能不會:-)明天會看看。謝謝。 – 2012-02-19 17:18:24
選擇**項目 - >清潔**來清潔您的項目 – waqaslam 2012-02-19 20:27:12