Android :: Dynamically Loading JAR File At Runtime

Mar 18, 2009

I am storing the required test.jar file in the /sdcard. I want to load it dynamically at runtime and want to execute a function xyz() resides in that. For this purpose I had written following code:
But got ClassCastException : dalvik.system.PathClassLoader

Following is my code ,
import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader;

import android.app.Activity; import android.os.Bundle; import android.util.Log;
public class Collabera extends Activity {
/** Called when the activity is first created. */
private static final Class[] parameters = new Class[] { URL.class };
public static void loadURLClass(String classPathURL) throws IOException {
File f = new File(classPathURL);
URL url = f.toURL();
URLClassLoader systemLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class systemLoaderClass = URLClassLoader.class;
try { Method method = systemLoaderClass.getDeclaredMethod("addURL", parameters);
method.setAccessible(true);
method.invoke(systemLoader, new Object[] { url });
} catch (Throwable t) { t.printStackTrace();
throw new IOException( "Error, could not add URL to system classloader");
} }
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("See","**************Before Loading Class Path**************");
try { Class.forName("test.Test1");
} catch (ClassNotFoundException e) { System.out.println(" Test Class Not Found ....");
} Log.i("See","**************After Loading Class Path**************");
try { loadURLClass("//sdcard//test.jar");
Class c = Class.forName("test.Test1");
Log.i("See"," Test Class Found ....");
Method method = c.getMethod("xyz", null);
Object o = c.newInstance();
String s = (String) method.invoke(o);
Log.i("See","Got method: " + s);
} catch (ClassNotFoundException e) { System.out.println(" Test Class Not Found ....");
} catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace();
} } }

Android :: Dynamically loading JAR File at Runtime


Android 2.2 Phone - Dynamically Loading External Library At Runtime?

Jul 29, 2013

I am using and android 2.2 phone for testing and getting an error.

07-27 01:24:55.692: W/System.err(14319): java.lang.ClassNotFoundException: com.shoaib.AndroidCCL.MyClass in loader dalvik.system.DexClassLoader@43abbc20

First I wrote the following class:

Code:
package org.shoaib.androidccl;
import android.util.Log;
public class MyClass {
public MyClass() {
Log.d(MyClass.class.getName(), "MyClass: constructor called.");
}
public void doSomething() {
Log.d(MyClass.class.getName(), "MyClass: doSomething() called.");
}
}

And I packaged it in a DEX file that I saved on my device's SD card as `/sdcard/testdex.jar`.

Then I wrote the program below, after having removed `MyClass` from my Eclipse project and cleaned it:

Code:

public class Main extends Activity {
[MENTION=1299008]supp[/MENTION]ressWarnings("unchecked")
[MENTION=439709]override[/MENTION]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

[code]....

View 2 Replies View Related

Android : Load Layout Dynamically At Runtime In Droid?

Nov 20, 2010

My application requires 2 screens and for this I have created two different XML layout files using RelativeLayout. One layout file loads whenever I run my Activity. Now I want to load the second layout on to the same Activity , when user click on a button in OptionsMenu and also when user press Back button the first screen loads instead of exiting the application. So that i don't need to create another Intent in my application.

View 3 Replies View Related

Android :: Apply Styles To My Views At Runtime Dynamically?

Aug 13, 2010

I'd like to dynamically apply styles to my views at runtime.
Is there any method like View.setStyle(int style)?

View 1 Replies View Related

Android : Create FindViewById Parm Dynamically Or Programmatically At Runtime

Sep 27, 2010

I have an xml layout that will display a grid made up of textviews within tablerows. The textview names are cell00, cell01, etc. At runtime, my program will determine which cell needs to be changed.

Is there a way get format a name so that it can be passed to the findViewById method at runtime? For example, if cell00 is needed, how can I generate the parm in this code?

TextView currcell = (TextView) findViewById(R.id.cell00)

Something like "cell"+00 doesn't compile because the findViewById method doesn't accept a String type. I don't want have every textview name in the grid hardcoded in the program - there must be a better way.

View 3 Replies View Related

Android :: Loading DEX Files At Runtime From SD Card

Feb 9, 2009

I would like my users to develop their own routines for image manipulation. Lets presume that a third party has written a class which implements one of my interfaces; public abstract class PixelBinaryFilter extends BinaryFilter{protected abstract int generatePixel(int p1, int p2);}

View 3 Replies View Related

Android :: Dynamically Loading ListView

Sep 28, 2010

I want to dynamically load a ListView, for example, load them during the scrolling so its not loading all 100 posts I have. How can I achieve this?

I have looked at similiar solutions here at SO, but since I not got it to work, I asked this question.

My code:.............

I have in the same .java file, functions to download the info from the web and loop through 100 items, like this:

CODE:................

And then it add a new order correctly and so on. But now!(?) I want to have so when the first item is loaded, it should appear and when scrolling it loads gradually.

View 1 Replies View Related

Android :: Dynamically Loading Images

Aug 31, 2010

I am stuck in an peculiar scenario, while developin an app in android.

My app, downloads image from internet and populates the same in a thumbnail format in the application.

As i am not aware of the number of picture's/thumbnails at design time, i am creating image view controls dynamically by using the below mentioned code.

CODE:...................

But in this scenario, all my images gets overlapped with each other. Wherein i want 3 images to be displayed on each row, which i am able to achieve through xml.

View 2 Replies View Related

Android :: How To Loading Images (assets / Resources) Dynamically?

May 21, 2009

How do I load the image dynamically through the code? If its unclear, I mean, I want to load image files by name based on the condition in the code. If I use images as resources, the image names have to be hard coded. This is unacceptable to me. If I load image in a webview (with image src path dynamically), the time it takes to load is unacceptable to me. Can anyone suggest any other way to load the images dynamically?

View 2 Replies View Related

Android :: Orientation Problem While Dynamically Loading Views

Jul 8, 2009

I am trying to load textView and CheckBox view dynamically to a LinearLayout. i am getting some Orientation problem while doing the same.I want these two view in a single row but i its coming as in different raw.

Below is may code:

CODE:..............

layoutxml is

CODE:..................

View 3 Replies View Related

Android :: Layout Not Displayed Properly While Loading Listview Dynamically

Apr 22, 2010

I am trying to laod the listview dynamically. There are three textviews inside a listview. The text to be set in the textview is fetched from the server. All this is working fine. I am able to fetch the text and am able to display it inside the listview.

The only problem is the position of the textview. The xml layout file is as under:

CODE:.............

If I look at this xml layout in the eclipse layout tab then it is displayed properly. Problem occurs only when the text is fetched dynamically.

View 2 Replies View Related

Android :: Layout Not Displayed Properly While Dynamically Loading A Listview In Android

Apr 22, 2010

CODE:...................

This is the layout that I am inflating in the Adapter. Everything is displayed, but only the second textview which should be displayed at the bottom is getting displayed at the top. Can someone let me know the problem with this?

I I view this in the layout tab in Eclipse then it displays properly. The problem occurs only when the text is fetched dynamically.

View 1 Replies View Related

Android :: Changing Colors.XML File At Runtime

Sep 9, 2010

I have an application where I would like the users to be able to change the theme. Currently my layout have elements like this: <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/background_transparency"> what I would like to do is to change to a new colors.xml that has a different value for "@color/background_transparency" if the user selects one of the themes available. Alternatively to be able to change the value of "@color/background_transparency" in code.Is this possible? Or am I doing this the wrong way.

View 3 Replies View Related

Android :: Any Set Style Method At Runtime In Layout File?

Feb 1, 2009

I created my style in styles.xml, lets say MyStyle. I can use it in any layout file by style="@style/MyStyle". Also my generated R class have R.style.MyStyle, my question is if I can use it at runtime to "setStyle" - unfortunately View doesn't have such a method. If not what is R.style.MyStyle used for? (I already know that custom themes IDs are also in R.style and can be used to setTheme, but MyStyle is not a theme).

View 14 Replies View Related

Android : Application - At Runtime Calls An Xml File From Some Path Of The System

Jul 30, 2010

Hi, I want to create an application in android which at runtime calls an xml file from some path of the system.And make that contents of the xml file run in the same application.Could i get a feasible code because at runtime the bytecode of the activity is already created.how do i compile and run the activity and runtime.Also i was facing problem reading the xml file.Need some suggestions asap.. Thanx in advance!!

View 3 Replies View Related

Android :: Add Data To Xml File Dynamically?

Oct 1, 2010

I am new to android.What i did is i am creating a xml file with some data.Now i need to add some additional data to existing xml file dynamically.How can i done this..

View 1 Replies View Related

Android :: Getting Maps To Accept A Dynamically Generated KML File

Mar 18, 2010

I have a button that launches the google maps app on my device via an intent. I want to be able to pass it a php page that generates a KML file.

I have done this on a website before using the googlemaps api in JS - but it doesn't seem to work on Android.

My php file is as follows;

CODE:..............

Launching with:

CODE:.................

It launches maps, finds the file - but won't display it 'because it contains errors'.

Is this just not possible, or are there other ways to construct the intent that might work?

View 2 Replies View Related

Android :: Setup Background Of A TextView Dynamically From Xml File?

Oct 10, 2010

I have an XMl file like below which I will use to set background for Textview:

row.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle">

The above Xml I will set as background for TextView in main.xml as below:

main.xml

<TextView
android:id="@+id/rowtext3"
android:text="Availablity"
android:layout_height="25px"
android:layout_width="60px"
android:textSize="10px"
android:textStyle="bold"
android:textColor="@color/black"
android:gravity="center"
android:background="@drawable/row"/>

But I want this to do from code rather than Xml.I have done everything that I have done in Xml like font,width,Height,font dynamically through code , but not able to set Background that I mentioned in Xml file . How can we set content of Xml file as background to textview similar to how we set background as XML in main.xml.

In the code I have done like this:
t1=new TextView(this);
t1.setText(ed1.getText());
t1.setHeight(25);
t1.setWidth(60);
t1.setTextSize(10);
But I didn't find how to set background i.e. how to set XML content as background?

View 2 Replies View Related

Android :: Can't Find A File In Dynamically Loaded Jar / Figure Out What Is Wrong?

May 26, 2009

I'm trying to dynamically load a jar file, then load the classes inside the jar. The code is simple but I keep getting ClassNotFind exception. The class is in the jar. How can I figure out what is wrong? code...

View 3 Replies View Related

Android :: Loading From Compiled XML File

Jun 30, 2010

I have some xml files with a custom format (based on the scxml specifications) that I want my program to read. I've already written the code to read it, but I'm running into problems actually reading the file itself. I want the file to be compiled with the apk, as it will not be changed at all during run time. So I put the file (test.xml) in the res/xml/ folder, and got the inputstream by using:

getResources().openRawResource(R.xml.test);
But when I read in this inputstream it is complete jibberish, which makes me suspect it is being read in binary, as openRawResource() is often used for binary files like images, if I am correct. What is the correct way to do this?

View 11 Replies View Related

Android :: Loading HTML File On View

Nov 2, 2010

I have one html file and I want to load that html file in view for loading ping images. I was doing:
android:background="@drawable/tips"
This in xml file but how to load html file in view?

View 8 Replies View Related

Android :: Loading APK File On Device For QA / Testing

Sep 7, 2010

I'd love to get some ideas on best practices for testing our Android software, especially for AT&T devices. We're using a Samsung Captivate, on AT&T. As you know, AT&T disables sideloading (no Unknowns Sources option in Settings->Applications). We need to have our QA team load our apk file onto these devices as part of our testing and validation process. We're willing to install the SDK if needed, and upload the apk file via USB. We are not willing to root the phone.

View 2 Replies View Related

Android :: Loading More Than One Layout File For An Activity

Apr 29, 2010

How can we use more than one layout file. I have implemented a cutom dialog.That means i have created an layout file for dialog. And one layout file for my activity. But whatever the UI items in dialog layout ile if iam using them by findViewById it is giving me null

I will explain in details here @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); applicationContext=getApplicationContext();

Dialog folder=new Dialog(this); folder.setTitle("Creating folder"); folder.setContentView(R.layout.create_folder); TextView tv=findViewById(R.id.folder_text); //Here folder_text is in my second layoutfile ie in create_folder.xml //In the above statemet i got the null to tv variable. folder.show();

View 5 Replies View Related

Android :: Loading HTML File From SD Card In Web Browser

Jan 19, 2009

How to load simple html file present in sd mmc card from web browser. It is mentioned in the net that due to security reasons this is not allowed. Is there any way to access the file from sdcard? Tried modifying private String homeUrl =
"file:///sdcard/index.html";
in BrowserSettings.java file but browser throws an error "could not be loaded".

View 4 Replies View Related

Android :: Loading HTML File From Local RES Directory

Sep 29, 2010

This should be very simple, but I can't find the answer anywhere. How do I load an html file (which I assume I keep in res/raw folder) into a webview?
neither mWebView.loadUrl("file:///raw/about");
or
mWebView.loadUrl("file:///raw/about.htmal");
works.
What's the correct syntax or arrangement.

View 3 Replies View Related

Android :: Dynamic Loading Of Complete Layout File

Jul 1, 2010

I'm dealing with a problem you guys might not have faced earlier. I'm having a use-case in my Android application where the actual screen that I want to show to user is not stored in any layout file of my application. The layout of the of the screen is designed by server in this case, based on selection made by user on first screen.

Let me elaborate here,
1st Screen : List of check box with different biller names. (Imagine I've selected 2 billers from this screen)
2nd Screen : (The screen that server has decided how it should look like)
* Header,
* 1st Biller name (Label)
* Amount for 1st Biller TextBox
* Image (a Separator image)
* 2st Biller name (Label)
* Amount for 2st Biller TextBox.
* Here there can be a checbox/radio/another TextBox anything.
* Image (a Separator image)
* Button (to submit above form back to server)

I hope makes some sense in what I'm planning to design. The current issues I'm dealing with are as below.
1). How to draw this dynamic widgets?
2). How to fetch user Inputs from this dynamically created widgets?

View 3 Replies View Related

Android :: Loading 3D Models - OBJ File Into My Own Model Class

Mar 11, 2009

How are people here loading in their models? I'm just manually parsing a OBJ file into my own model class and drawing that.

View 4 Replies View Related

Android :: Loading Raw Resource Text File / Out Of Memory Error

Sep 15, 2010

I use this method couples of occasion to load text file to display as help file. But I don't know why the following code didn't work. It seems to hang and logcat says "OutOfMemoryError"? All I did was break this out as an separate activity.

---xml---
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/helptab"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/helptext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>

---code---
import java.io.DataInputStream;
import java.io.IOException; import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Help extends Activity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
InputStream iFile = getResources().openRawResource(R.raw.help);
try { TextView helpText = (TextView) findViewById(R.id.helptext);
String strFile = inputStreamToString(iFile);
helpText.setText(strFile);
} catch (Exception e) {
} }
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);
String strLine = "";
while ((strLine = dataIO.readLine()) != "") {
sBuffer.append(strLine + " ");
} dataIO.close();
is.close();
return sBuffer.toString();
}

View 6 Replies View Related

Android :: Loading External Data On Local File In WebView

May 27, 2009

when I load external web page, image or javascript file from local webpage. I can't see external image and can't load javascript or webpage. But I can only see local image. Why I can't load external javascript, webpage or image? Here is the HTML source. (of course, I filled right [daum open API key])

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta
http-equiv ="Content-Type" content="text/html;
charset=UTF-8"> <title>Daum 지도 API</title>
<script type="text/javascript"
src="http://apis.daum.net/maps/maps.js?
apikey=[daum open API key]" charset="utf-8"></script> </head> <body>
<div id="map" style="width:600px;
height:400px;
" style="border:1px solid #000">
</div> <img src="http://4.bp.blogspot.com/_2-7AdSkZA7I/RlCnDhD3ZfI/ AAAAAAAAE9U/LEHMtyVLdY8/s400/CutyTale10.jpg">
<img src="file:///android_asset/coffeebean.jpg">
<script type="text/javascript">
var map = new DMap("map", {point:new DLatLng(37.48879895934866, 127.03130020103005), level:2} );
</script> <iframe src="http://www.daum.com" width="300" height="150"></iframe> </body> </html>

and I use this Activity source
package bo.my.android.test;
import android.app.Activity;
import android.os.Bundle; import android.webkit.WebView;
public class OpenAPITest extends Activity {
WebView webView;
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new DaumMapClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/daummap.html");
//webView.loadUrl("http://www.daum.net");
} }

View 3 Replies View Related

Android :: Loading String Values From File Instead Of List In Class

Nov 1, 2010

I think I have a pretty easy problem to solve, but I have been beating my head against the wall for hours trying to get past it! I have an adapter that loads a list of URLS:
adapter=new MyAdapter(this, lStrings);
list.setAdapter(adapter);

The list of URLS looks like this:
private String[] lStrings={
"http://www.domain.com/file1.jpg",
"http://www.domain.com/file2.jpg",
"http://www.domain.com/file3.jpg",
};

What I want instead is to load these values from a text file that lies on the SD card. For that matter, I would be okay with loading the values from a text file into a String, and then load the String into the list as I imagine that would be the "cleaner approach". However, all attempts to do this have failed. For instance, I replaced the above snippet with this:

private String[] lStrings=
{ MainActivity.this.getString(R.string.myurllist) };
but then I get a Forced Close on loading.

I'm a bit new to Java, Android, and development in general.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved