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

  • Home
  • SEARCH
  • 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 7421095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:21:00+00:00 2026-05-29T08:21:00+00:00

import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.os.Bundle;

  • 0
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;


    public class DrawingActivity extends Activity {
        private ArrayList _graphics = new ArrayList();
        private Paint mPaint;
        Handler myHandler = new Handler() {

        public void handleMessage(android.os.Message msg) {
        myview.invalidate();

        };
        };
        Myview myview;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(new DrawingPanel(this));
        mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(0xFFFFFF00);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(3);
        myview = new Myview(this);
        myview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
        LayoutParams.FILL_PARENT));
        setContentView(myview);
        myHandler = new Handler();

        }

        class Myview extends View {

        public Myview(Context context) {
        super(context);

        }

        Path path;

        @Override
        public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
        path = new Path();
        path.moveTo(event.getX(), event.getY());
        path.lineTo(event.getX(), event.getY());
        _graphics.add(path);
        } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        path.lineTo(event.getX(), event.getY());
        } else if (event.getAction() == MotionEvent.ACTION_UP) {
        path.lineTo(event.getX(), event.getY());
        }
        invalidate();
        return true;
        }

        @Override
        protected void onDraw(Canvas canvas) {
        for (Path path :_graphics) {
        // canvas.drawPoint(graphic.x, graphic.y, mPaint);
        canvas.drawPath(path, mPaint);
        }
        }
        }

        }

Here the compiler shows the error in that line Type mismatch: cannot convert from element type Object to Path ———- for (Path path :_graphics) { what problem occurs here

  • 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-05-29T08:21:01+00:00Added an answer on May 29, 2026 at 8:21 am

    Your ArrayList is untyped, so even though you might only ever put objects of those type in there, the compiler doesn’t know it. You either need to use generics (if Java on Android supports it) e.g.

    ArrayList<Path> _graphics = new ArrayList<Path>();
    

    Or rewrite the loop so you can cast the elements as you get them from the list.

    for (int c=0; c< _graphic.size(); ++c ) {
        Path p = (Path)_graphics.get(c);
        ....
    }
    

    Good luck.

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

Sidebar

Related Questions

package com.VRG; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Context; import android.media.MediaPlayer;
package com.crumbin.tabs; //java package import java.io.IOException; import java.util.ArrayList; import org.json.JSONException; import android.app.Activity; import android.app.AlertDialog;
Here is my code... import java.util.ArrayList; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; import android.content.Intent;
package com.example.helloandroid; import java.util.ArrayList; import java.util.Arrays; import android.app.TabActivity; import android.os.Bundle; import android.view.Window; import android.widget.ArrayAdapter;
here is my Arrival.java package one.two; import java.io.IOException; import java.util.ArrayList; import java.util.List; import android.app.ListActivity;
Android crashes whenever this activity is started. here is the code. import java.util.ArrayList; import
I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
When running the following class the ExecutionService will often deadlock. import java.util.ArrayList; import java.util.Collection;

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.