Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:57:12+00:00 2026-06-15T16:57:12+00:00

My camera activity is not working: I launch it from listActivity. I have another

  • 0

My camera activity is not working:

I launch it from listActivity.
I have another three activities from the list activity but camera activity/intent force closes.


Camera.java

              package com.alpha.beta;

               import java.io.IOException;

               import android.app.Activity;
               import android.content.Intent;
               import android.graphics.Bitmap;
               import android.os.Bundle;
               import android.view.View;
               import android.widget.ImageButton;
               import android.widget.ImageView;

               public class Camera extends Activity implements View.OnClickListener {

ImageView Image;
ImageView setWall;
ImageButton TakePic;
Bitmap bmap;
Intent i;
final static int cameraData = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.camera);
    vars();

}

private void vars() {
    // TODO Auto-generated method stub
    Image = (ImageView) findViewById(R.id.ivReturnPic);
    setWall = (ImageView) findViewById(R.id.bSetWallpaper);
    TakePic = (ImageButton) findViewById(R.id.iBTakePic);
    setWall.setOnClickListener(this);
    TakePic.setOnClickListener(this);
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.iBTakePic:
        try {
            getApplicationContext().setWallpaper(bmap);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    case R.id.bSetWallpaper:
        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();
        bmap = (Bitmap) extras.get("data");
        Image.setImageBitmap(bmap);
    }
}

     }

Logcat

       12-02 20:44:11.229: W/dalvikvm(6322): threadid=1: thread exiting with uncaught exception (group=0x40018578)
       12-02 20:44:11.229: E/AndroidRuntime(6322): FATAL EXCEPTION: main
       12-02 20:44:11.229: E/AndroidRuntime(6322): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alpha.beta/com.alpha.beta.Camera}: java.lang.ClassCastException: android.widget.Button
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.os.Handler.dispatchMessage(Handler.java:99)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.os.Looper.loop(Looper.java:130)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.ActivityThread.main(ActivityThread.java:3687)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at java.lang.reflect.Method.invokeNative(Native Method)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at java.lang.reflect.Method.invoke(Method.java:507)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at dalvik.system.NativeStart.main(Native Method)
       12-02 20:44:11.229: E/AndroidRuntime(6322): Caused by: java.lang.ClassCastException: android.widget.Button
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at com.alpha.beta.Camera.vars(Camera.java:34)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at com.alpha.beta.Camera.onCreate(Camera.java:27)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
       12-02 20:44:11.229: E/AndroidRuntime(6322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

12-02 20:44:11.229: E/AndroidRuntime(6322): … 11 more

Manifest File

      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alpha.beta"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.SET_WALLPAPER" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Splash"
        android:label="@string/title_activity_app" >
        <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/title_activity_app" >
        <action android:name="com.alpha.beta.Menu" />

        <category android:name="android.intent.category.DEFAULT" />
    </activity>
    <activity
        android:name=".App"
        android:label="@string/title_activity_app" >
    </activity>
    <activity
        android:name=".TextPlay"
        android:label="@string/title_activity_app" >
    </activity>
    <activity
        android:name=".Email"
        android:label="@string/title_activity_app" >
    </activity>
    <activity
        android:name=".Camera"
        android:label="@string/title_activity_app" >
    </activity>
</application>

    </manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:57:14+00:00Added an answer on June 15, 2026 at 4:57 pm

    You did not show your layout file and the but is there (or its origin). What you do wrong is something like this: your layout element is for example ImageView but you do findViewById() and cast the result to i.e. ImageButton. This causes cast exception. So check all your layout elements and your code to see if there’s no said mismatch.

    And unless you are not need any special feature of certain view, but want to just attach listener to it, or change its visibility etc, then you should just cast result of findViewById() to View to not need to care if this is the correct cast or not (all UI elements are children of View).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I launch an activity to capture a picture from camera: Intent i = new
I'd like to launch the camera activity and have it dump subsequent pictures into
I have an activity that calls the camera intent to capture a picture and
My camera application is not working.I tried with some existing tutorial examples. But they
I'm trying to develop my own camera activity, but I have a problem that
I am taking a high resolution picture through the default camera activity(using intent.put Extras
I've got Activity A which fires up the Camera intent via: Intent intent =
I want to access camera to record video to upload, but have come across
I have camera preview on my android app but when I add an 'id'
I have a little problem with my camera intent. As I know, when camera

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.