Android图库无法合并自定义标题

发布于 2024-12-04 20:38:19 字数 8165 浏览 0 评论 0原文

这是我的代码,我正在尝试打开图库。我收到了如上所述的错误

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import java.io.ByteArrayOutputStream;

public class ChangeUserImageActivity extends Activity {

private static final int SELECT_PICTURE = 1;

private static final int CAMERA_PIC_REQUEST = 1337;
private Bitmap thumbnail = null;
String img = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.changeuserimage);
}

public void camera_click(View view) {
    Intent cameraIntent = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}

public void gallery_click(View v) {
    // select a file
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),
            SELECT_PICTURE);
}

private byte[] imagetoArray() {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.PNG, 100, stream);
    return stream.toByteArray();
}

public void backHome_click(View view) {
    Intent myIntent = new Intent(view.getContext(), Tabs.class);
    startActivityForResult(myIntent, 0);
}

private String decodeUTF8(byte[] bytes) {
    return Base64.encodeToString(bytes, Base64.NO_WRAP);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == -1) {
        thumbnail = (Bitmap) data.getExtras().get("data");
        ImageView image = (ImageView) findViewById(R.id.newuserimg);
        image.setImageBitmap(thumbnail);
    }

}
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.AgricultureTrading"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name="MainActivity"
                  android:label="@string/app_name"
                        android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>            
        </activity>        
                        <activity android:name=".Tabs"  android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar"></activity>

                <activity android:name=".PestManagementHomeActivity"  android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar"></activity>
        <activity android:name=".BuySellHomeActivity" 
        android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar"></activity>
                <activity android:name=".EnvironmentAdviceActivity" ></activity>
        <activity android:name=".ProfileActivity"></activity>
        <activity android:name=".AddPestActivity"></activity>
        <activity android:name=".AddEnvironmentActivity"></activity>
        <activity android:name=".SelectAdviceActivity"></activity>
        <activity android:name=".PestAdviceActivity"></activity>
        <activity android:name=".SellPriceActivity"></activity>
        <activity android:name=".SellActivity"></activity>
        <activity android:name=".AddEventActivity"></activity>
        <activity android:name=".ChangeUserImageActivity" android:theme="@android:style/Theme.Dialog"></activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />

</manifest>

错误

16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime  FATAL EXCEPTION: main
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gallery/com.android.camera.ImageGallery}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.access$500(ActivityThread.java:122)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.os.Looper.loop(Looper.java:132)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:4123)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:491)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime  Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:204)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2338)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2545)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:219)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.Activity.setContentView(Activity.java:1786)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.camera.ImageGallery.onCreate(ImageGallery.java:113)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.Activity.performCreate(Activity.java:4397)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      ... 11 more

this is my code and I am trying to open gallery.. I got error as stated above

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import java.io.ByteArrayOutputStream;

public class ChangeUserImageActivity extends Activity {

private static final int SELECT_PICTURE = 1;

private static final int CAMERA_PIC_REQUEST = 1337;
private Bitmap thumbnail = null;
String img = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.changeuserimage);
}

public void camera_click(View view) {
    Intent cameraIntent = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}

public void gallery_click(View v) {
    // select a file
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"),
            SELECT_PICTURE);
}

private byte[] imagetoArray() {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.PNG, 100, stream);
    return stream.toByteArray();
}

public void backHome_click(View view) {
    Intent myIntent = new Intent(view.getContext(), Tabs.class);
    startActivityForResult(myIntent, 0);
}

private String decodeUTF8(byte[] bytes) {
    return Base64.encodeToString(bytes, Base64.NO_WRAP);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == -1) {
        thumbnail = (Bitmap) data.getExtras().get("data");
        ImageView image = (ImageView) findViewById(R.id.newuserimg);
        image.setImageBitmap(thumbnail);
    }

}
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.AgricultureTrading"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name="MainActivity"
                  android:label="@string/app_name"
                        android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>            
        </activity>        
                        <activity android:name=".Tabs"  android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar"></activity>

                <activity android:name=".PestManagementHomeActivity"  android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar"></activity>
        <activity android:name=".BuySellHomeActivity" 
        android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar"></activity>
                <activity android:name=".EnvironmentAdviceActivity" ></activity>
        <activity android:name=".ProfileActivity"></activity>
        <activity android:name=".AddPestActivity"></activity>
        <activity android:name=".AddEnvironmentActivity"></activity>
        <activity android:name=".SelectAdviceActivity"></activity>
        <activity android:name=".PestAdviceActivity"></activity>
        <activity android:name=".SellPriceActivity"></activity>
        <activity android:name=".SellActivity"></activity>
        <activity android:name=".AddEventActivity"></activity>
        <activity android:name=".ChangeUserImageActivity" android:theme="@android:style/Theme.Dialog"></activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />

</manifest>

Error

16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime  FATAL EXCEPTION: main
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gallery/com.android.camera.ImageGallery}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.access$500(ActivityThread.java:122)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.os.Looper.loop(Looper.java:132)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:4123)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:491)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime  Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:204)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2338)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2545)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:219)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.Activity.setContentView(Activity.java:1786)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at com.android.camera.ImageGallery.onCreate(ImageGallery.java:113)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.Activity.performCreate(Activity.java:4397)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
16:17:28.781    1604    com.android.gallery ERROR   AndroidRuntime      ... 11 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谎言月老 2024-12-11 20:38:19

请从您的清单文件中删除它
android:theme="@android:style/Theme.Dialog" 为活动 ChangeUserImageActivity 然后尝试

Please remove this from your manifest file
android:theme="@android:style/Theme.Dialog" for the activity ChangeUserImageActivity and then try

你列表最软的妹 2024-12-11 20:38:19

将 onActivity 结果更改为以下:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
            System.out.println("Image Path : " + selectedImagePath);
            img.setImageURI(selectedImageUri);
        }
    }
}

change onActivity result to below:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
            System.out.println("Image Path : " + selectedImagePath);
            img.setImageURI(selectedImageUri);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文