gpt4 book ai didi

android - 不幸的是,我的应用程序停止了,我该怎么办?

转载 作者:行者123 更新时间:2023-11-29 14:49:35 26 4
gpt4 key购买 nike

我在 AVD 中收到类似的消息 - 不幸的是已经停止,请帮助我解决这个错误,我想在 android 中了解更多信息但被这个错误搞砸了。

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" >

<ImageView
android:id="@+id/iv"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:src="@drawable/ic_launcher"
android:contentDescription="@null"
/>

<ImageButton
android:id="@+id/ib"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_launcher"
android:contentDescription="@null"

/>

<Button
android:id="@+id/bt"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="set wallpaper" />

</LinearLayout>

java代码

    package com.example.second;
public class photo extends Activity implements View.OnClickListener {

ImageView iv;
Button bt;
ImageButton ib;
Intent i ;
Bitmap bmp;
final static int cameraData =0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
intsallttion();
InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
bmp = BitmapFactory.decodeStream(is);

}
private void intsallttion() {
// TODO Auto-generated method stub
iv = (ImageView) findViewById(R.id.iv);
bt = (Button) findViewById(R.id.bt);
ib = (ImageButton) findViewById(R.id.ib);

bt.setOnClickListener(this);
ib.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.bt:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;

case R.id.ib:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,cameraData);
break;
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
iv.setImageBitmap(bmp);
}
}

}

主要节日

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.second"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


<activity
android:name=".omar"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.second.MENU" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>



<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.second.MAIN" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>



<activity
android:name=".TextPlay"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Email"
android:label="@string/app_name" >
</activity>
<activity
android:name=".photo"
android:label="@string/app_name" >
</activity>

</application>

</manifest>

最佳答案

你忘了添加 .xml 文件声明像

setContentView(R.layout.activity_main);

onCreate() 方法中,在这一行之后

super.onCreate(savedInstanceState);

由于您忘记添加 .xml,您的 Activity 无法获取 ImageView、Button 和 ImageButton 等组件的详细信息。

关于android - 不幸的是,我的应用程序停止了,我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22962275/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com