I'm trying to spruce up my image viewer activity by converting from an ImageView to a TouchImageView, per the answer here: How can I get zoom functionality for images?
However, I get an error when my activity is attempting to load:
Binary XML file line #15: Error inflating class TouchImageView
Here's my image_viewer.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!--
<WebView
android:id="#+id/webView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
-->
<TouchImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
And my code inside onCreate of ImageViewer.java (though I'm pretty sure that execution never even gets this far):
if(filepath != null && filepath.length() > 0 && new File(filepath).exists())
{
Bitmap myBitmap = BitmapFactory.decodeFile(filepath);
TouchImageView imgView = (TouchImageView) findViewById(R.id.imageView1);
imgView.setImageBitmap(myBitmap);
}
Any ideas as to why or what is causing this error? What I saw was the inner most exception/cause. Not sure how I can get more details about the error.
Thanks in advance.
UPDATE:
Exception gets thrown on execution of this line:
setContentView(R.layout.image_viewer);
Further detail on the error:
java.lang.ClassNotFoundException: android.view.TouchImageView in
loader dalvik.system.PathClassLoader#44bfde70
You need to have the fully qualified name to any custom view classes. e.g:
<com.kon.thing.TouchImageView ... />
The JVM can't find your class.
make sure u have entered a correct package name in xml
like..
<com.gallery.TouchImageView
android:id="#+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter" />
Related
I am trying to use Picasso Android library but i'm not able to get it working.
For starting, i am trying the simplest of the things:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basic_view);
mImageView = (ImageView) findViewById(R.id.imageView);
Picasso.with(this).setIndicatorsEnabled(true);
Picasso.with(this).setLoggingEnabled(true);
Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(mImageView);
}
the activity layout is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"/>
</RelativeLayout>
The view remains completely red.
If i set a resource in the view via setImageResource, it correctly displays.
The only relevant clue that something went wrong is a message saying:
Picasso: main errored
but i can't understand why.
I would happily paste more logcat output but it breaks the code block and becomes unreadable.
Here's a pastebin: main errored log
I believe there's something trivial i am doing wrong.
To download images from the internet, you will need the INTERNET permission in your manifest.
<uses-permission android:name="android.permission.INTERNET" />
I have got an idea to get rid of some coding when we do initializion of views.
When we create an xml layout in android. At that movement same name class is created with UpperCase Letters with a dialogue with permission. And as i created views with ids. It should create Views and initialize them automatically.
for e.g
close.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/closeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/close_img" />
<TextView
android:id="#+id/closeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Testing Text" />
</LinearLayout>
And automatically generated java code should be.
public class Close extends Activity
{
TextView CloseText;
Button CloseBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CloseText = (TextView)findViewById(R.id.closeText);
CloseBtn = (Button)findViewById(R.id.closeBtn);
}
}
I can read xml and do the other stuff as I explained. But how could i add this module to eclipse and How could i create a service which work in Background all the time in eclipse.
Suggest me how to add this module(Plugin) to eclipse and i am going to use JAXB to generate Java Objects from XML document. Is there any better option.
Here in this website i find that just paste the xml and you will get your java code ready for activity class.
i had attached the link
I try to display an ImageView into my app on a well (hopefully) defined view (XML)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activityShowLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#73C310"
android:orientation="vertical"
tools:context=".ShowActivity" >
<ImageView
android:id="#+id/mainImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/moodButton"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="12dp"
android:background="#000"
android:src="#drawable/gs_04_pic" />
<!-- ... -->
and after that in my onCreate method on the activity
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
/* ... blabla bla ... */
ImageView imageView = (ImageView) findViewById(R.id.mainImage);
Bitmap bitmap = BitmapFactory.decodeByteArray(cream.getMedia(), 0, cream.getMedia().length);
Drawable draw = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(draw);
imageView.invalidate();
}
with cream.getMedia() returning a valid byte[] (from database)
which I can log giving me:
07-18 17:41:16.812: I/app(9883): byte[] is: [B#414af0b0
But at the end the imageView is black (no image on it)
If I don't run the onCreate code it displays the resource set in the XML (on black background as set in XML too)
What is wrong?
I run into this problem, in my case the problem came from the config in:
bluid.gradle
shrinkResources true
It deleted my files because I didn't have a static reference to my resources. (images in my case)
so I found this article "Keeping Resources" in this link Resource Shrinking
In resumen it says: you should make a file in this path "/res/raw/keep.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="#layout/l_used*_c,#layout/l_used_a,#layout/l_used_b*"/>
It may be because of you are trying to load a larger bitmap into the imageview, please try to scale it down before setting.
I saw this source as layout of AlertDialog in res\layout folder of Android SDK:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/body"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:paddingLeft="8dip"
android:paddingTop="10dip"
android:paddingRight="8dip"
android:paddingBottom="10dip">
<ProgressBar android:id="#android:id/progress"
style="#android:style/Widget.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="10000"
android:layout_marginRight="12dip" />
<TextView android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
</FrameLayout>
I tried to find TextView that it's id is "message" like this:
TextView tvMessage = (TextView)dialog.findViewById(android.R.id.message);
It works fine.Then I tried to find LinearLayout that it's id is "body" like this:
LinearLayout body = (LinearLayout)dialog.findViewById(android.R.id.body);
But eclipse show this error:
body cannot be resolved or is not a field
This is snippet code:
ProgressDialog dialog = new ProgressDialog(WriteOpinionActivity.this);
dialog.setMessage("some text");
dialog.show();
TextView tvMessage = (TextView)dialog.findViewById(android.R.id.message);
LinearLayout body = (LinearLayout)dialog.findViewById(android.R.id.body);
Why this error occurs and how I can reach "body"?
Basically, not all resources are accessible to You from platforms res folder.
E.g. I'm able to find #+id/message in global_actions_item.xml, usb_storage_activity.xml, alert_dialog_holo.xml, js_prompt.xml, progress_dialog_holo.xml, progress_dialog.xml, alert_dialog.xml (for API 17), and so, there's no warranty that You get id which defined in progress_dialog.xml (it can be defined in another file and just because of the same name You is able to find it in progress dialog).
Actually, public resources are defined here, however, it looks quite outdated, so some resources might be missed. Checkout these questions about lists of all accessible resources: 1 and 2
Use this instead.
TextView tvMessage = (TextView)dialog.findViewById(R.id.message);
LinearLayout body = (LinearLayout)dialog.findViewById(R.id.body);
You weren't actually using android.R.id.message in the first place. #+id/message means you are creating a new id resource named message.
To use an id that exists in the Android framework, you can see here that you use #android:id/progress. And in source, you use it like you had it: android.R.id.progress.
Otherwise, use android:id="#=id/myIdentifier" in XML and
findViewById(R.id.myIdentifier) in code.
http://developer.android.com/guide/topics/resources/overview.html
I'm trying to implement flowtextview into bauerca / drag-sort-listview but I'm getting an error inflating a row. Could you help me?
Error line is in (ResourceDragSortCursorAdapter.java (Bauerca)):
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return mInflater.inflate(mLayout, parent, false);
}
Eclipse says:
Ecipse says "FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #8: Error inflataing class com.pagesuite.flowtext.FlowTextView"
The row layout is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="67dp"
android:orientation="horizontal">
<com.pagesuite.flowtext.FlowTextView
android:id="#+id/nuevo_ingr_row_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#id/drag_handle"
android:layout_width="wrap_content"
android:layout_height="67dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="10dip"
android:background="#drawable/ic_move" />
<ImageView
android:id="#id/click_remove"
android:layout_width="67dp"
android:layout_height="67dp"
android:layout_alignParentRight="true"
android:layout_marginTop="400dip"
android:padding="10dip"
android:background="#drawable/ic_close" />
</com.pagesuite.flowtext.FlowTextView>
</LinearLayout>
It probably fails to find your com.pagesuite.flowtext.FlowTextView class.
First check if this class is actually in that package? Did you use a library or copy this class into your own project? If you copied it, you'll need to change the package to the correct value aka point it to your own class.
You got that error just because your xml layout file is not recognise the package com.pagesuite.flowtext.FlowTextView
If you change it to right one then error will not be there.
Feel free to comments.
I wrote the FlowTextView class. The project has had quite a few bug fixes and the JAR file hasn't been updated so I would advise against using the JAR file and check the whole source out and use it as a library project.
This means you get the latest version and it will probbly solve your import issue at the same time.
IF you are not familiar with library projects in eclipse then check this