cannot resolve symbol PreviewCallback - java

I created a class in java for capturing pictures from a phone camera and I get the following error cannot resolve the PreviewCallback symbol.

Because you are using incorrect Camera class.
First remove this line
import android.graphics.Camera;
Then add this line
import android.hardware.Camera;

Related

Trouble using cardslib with existing Eclipse Android project

I'm trying to use this card library for the UI of the Android app I'm trying to build, but I'm running into some problems.
The author has this guide for using the library with an existing Eclipse project which I've followed throughly, but I'm getting multiple errors.
I'm importing the library as an "Existing project" under the Import options in Eclipse, and including the project in my existing project's build path, but I keep getting errors regarding missing methods (specifically the getContext() argument specified in the constructor), even after importing the entire library.
Here is a snippet of my code:
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardHeader;
public class MainActivity extends Activity {
Card card = new Card(getContext());
CardHeader header = new CardHeader(getContext());
card.addCardHeader(header);
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo);
cardView.setCard(card);
I get the following errors for each respective line in my code snippet:
The method getContext() is undefined for the type MainActivity
The method getContext() is undefined for the type MainActivity
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on token "header", VariableDeclaratorId expected after
Multiple markers at this line
- CardView cannot be resolved to a type
- CardView cannot be resolved to a type
- The method getActivity() is undefined for the type
MainActivity
Multiple markers at this line
- Syntax error on token "card", VariableDeclaratorId expected after
this token
- Syntax error on token(s), misplaced construct(s)
I know this is a very specific question, but I'm hoping I can get an answer here!
Your error has nothing to do with Cardslib. Card construction accepts Context of your current Activity. There's no function as getContext() in Android. The correct function is getBaseContext().
There are two ways to send it.
Card card = new Card(getBaseContext());
or
Card card = new Card(this);

Red line error with correct code

image
Well i have this problem when the code is correct, but it gives me red line error!
can anybody help me.
Main.java
package com.example.sout;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import
~
import android.widget.ImageView;
public class Main extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
ImageView iv = (ImageView) findViewById(R.id.img1);
iv.setBackgroundResource (R.anim.animation);
~~~~~~~~~~~~~~~~
iv.setOnClickListener(new OnClickListener());
~~~~~~~~~~~~~~~ ~
}
in (note the ~ characters above):
iv.setBackgroundResource (R.anim.animation);
iv.setOnClickListener(new OnClickListener());
The setBackgroundResource and setOnClickListener are red too.
The error in iv.setBackgroundResource (R.anim.animation); comes because that method takes integer as a parameter .So change it to the following,
iv.setBackgroundResource (R.drawable.image1); //image1 is a drawable which is inside your drawable folder.
and the second error comes because you have not imported the required package and have not overridden the methods required for that. Change it to the following,
iv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//do your task here
}
});
after changing press ctrl+shift+p to import the required packages.
Sometimes, at least with Eclipse, it gets it into it head that there's an error and it won't let it go. But, with Eclipse, you can at least put the cursor over a marker and it will explain what the problem is (or what it thinks it is). I'd try to hover over the errant lines to see if a popup box appears telling you what it thinks.
If you're sure it's wrong, often I've found that saving the file (or all files) will fix it. Sometimes adding then deleting a space on the errant line will fix it.
However, I notice that you have an incomplete import at the top of your file and this may be preventing the syntax checker from properly analysing the source file.
My advice is to fix that first, then try those other two tricks (save then, if that doesn't work, edit and undo on the errant line). Hopefully that will make it disappear.
Of course, you may want to check, just in case, your R.java file to ensure that member exists in there somewhere. I've been bitten by my own misspellings before.

Drawing an image in android

I'm trying to just draw a simple image from the drawable-mdpi folder in android but I keep getting an error saying droid_1 cannot be resolved or is not a field, droid_1 is the name of the image, this is my code,
thanks for any help.
import android.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class GameView extends View {
private Bitmap bmp;
public GameView(Context context) {
super(context);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.droid_1);
}
#Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(bmp, 10, 10, null);
}
}
Change "import android.R;" to "import "import com.your.package.R;" where com.your.package is your package name...
You are importing android.R the android.R file won't contain your resources
You say that your image is in the drawable-mdpi folder. If you aren't using an MDPI display, Android won't be able to find an image to show on the screen. Make sure you have an image in each of the drawable-... folders, or a single image in the drawable folder, so that at least it will be able to find an image to use regardless of the screen resolution.
Also, you're trying to import the standard android.R package. Try removing this import line completely and let Eclipse suggest the correct R package to import - it'll be something like import com.yourapp.R;

android app test error

When I run my first app, I got error.
Code of the activity:
package com.pradeep.ulc;
import android.app.Activity;
import android.os.Bundle;
public class New1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Error:
R cannot be resolved to a variable New1Activity.java /new1/src/com/pradeep/ulc line 11 Java Problem
How can I fix it?
1) Make sure the package name is correctly set everywhere
2) Try doing a clean build to regenerate R.java.
If you must use a different package, import the R.java from the package specified in the manifest.
It means that you have problem in your resources, so R file cannot be generated.
What do you have in res/layout/main.xml file?

android "main cannot be resolved or is not a field"

i m new to this platform, please help me to find what is the error...
setContentView(R.layout.main); // this line shows the error.
Code:
package com.example.helloandroid;
import android.R;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Try deleting the line import android.R then clean your project.
Just adding more details on why the error is coming.
As there is an import of android.R so setContentView() is looking for a layout file 'android.R.layout.main' and there is no main.xml in the layout files that come along with SDK. So, using the correct R.java import will work.
clean Project then try To Run because i faced same problem before a month and remember layout/main.xml must be their and it must not contains any error.
you can Also Do this
import android.R;
or
import your.application.packagename.R; Now Clear Project and Run it.
You must have to simply change the
setContentView(R.layout.main);
... to:
setContentView(R.layout.activity_main);
... because Layout contains this .xml file.
I hope your problem will be solved.
First remove import android.R;
After any change on xml fiels you must clean project.
Build > Clean Project
after that every things corrects.

Categories