我正在创建一个应用程序,其中包含一个用于启动Prov.java活动的图像按钮。
此应用程序以前一直在运行,但今天我尝试在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();
}
});
}
答案 0 :(得分:0)
显然,我尝试将我的背景图像应用于prov.java的onCreate方法中的id“might”。这是错的,正确的id是“bakgrund”。谢谢你的时间。
回答问题。