I have a problem in my application. I am developing software for a Windows CE .NET device. It is a bar code reader and I have the library that includes the control of the bar code scanner
When I try to create an object of ScannerServicesDriver type I get a MissingManifestResourceException and no additional information is given.
I don´t understand why can I create the object scanner1 correctly and not the scannerServicesDriver1.
The path of reference to the library is correct
This is the code I have:
public class FormA200 : System.Windows.Forms.Form
{
...
private PsionTeklogix.Barcode.ScannerServices.ScannerServicesDriver scannerServicesDriver1;
private PsionTeklogix.Barcode.Scanner scanner1;
public FormA200()
{
InitializeComponent();
}
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormA200));
this.lCant = new System.Windows.Forms.Label();
.....
this.scanner1 = new PsionTeklogix.Barcode.Scanner();
//at this point the exception happens!
this.scannerServicesDriver1 = new PsionTeklogix.Barcode.ScannerServices.ScannerServicesDriver();
// scanner1
this.scanner1.Driver = this.scannerServicesDriver1;
this.scanner1.ScanCompleteEvent += new PsionTeklogix.Barcode.ScanCompleteEventHandler(this.scanner1_ScanCompleteEvent);
this.Load += new System.EventHandler(this.FormA200_Load);
}
private void scanner1_ScanCompleteEvent(object sender, PsionTeklogix.Barcode.ScanCompleteEventArgs e)
{
}
}
Any ideas??
I am using and android 2.2 phone for testing and getting an error which is driving me crazy
07-27 01:24:55.692: W/System.err(14319): java.lang.ClassNotFoundException: com.shoaib.AndroidCCL.MyClass in loader [email protected]
Can someone help me what to do now..i have tried various suggested solutions on different posts
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 {
[user=1299008]@supp[/user]ressWarnings("unchecked")
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
final String libPath = Environment.getExternalStorageDirectory() + "/testdex.jar";
final File tmpDir = getDir("dex", 0);
final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader());
final Class<Object> classToLoad = (Class<Object>) classloader.loadClass("org.shoaib.androidccl.MyClass");
final Object myInstance = classToLoad.newInstance();
final Method doSomething = classToLoad.getMethod("doSomething");
doSomething.invoke(myInstance);
} catch (Exception e) {
e.printStackTrace();
}
}
}
As far as I know you can't load external dex classes (and certainly not a jar file), the only ones that can be loaded are the ones packaged in the classes.dex file inside the APK and protected by its signature and certificate.
This would be quite a security flaw if your app could be "clean" at install but then download malicious classes and execute them.
hello friends i'm new here and sorry for my question i'm big beginner and an autolearner.
i'm doing an app for android basicaly mock up. and i created a projectwith drawer menu and menu item are stocked in string not in array.
when i run it if i click on an item the number of row of the item appear in the mainactivity.xml what i realy want is to start a new activity here is my code i hope i can get help here,
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
canempire said:
hello friends i'm new here and sorry for my question i'm big beginner and an autolearner.
i'm doing an app for android basicaly mock up. and i created a projectwith drawer menu and menu item are stocked in string not in array.
when i run it if i click on an item the number of row of the item appear in the mainactivity.xml what i realy want is to start a new activity here is my code i hope i can get help here,
Click to expand...
Click to collapse
Modify your onNavigationDrawerItemSelected method as follows
PHP:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
Fragment yourfragment = new Yourfragment();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
,beginTransaction();
fragmentTransaction.replace(R.id.container, yourfragment );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,destination.class);
startActivity(intent);
break;
case 2:
//To do something else like a dialog or a toast
Toast.maketext(context,"Sample Toast",Tosat.LENGTH_LONG).show();
break;
}
}
hello friend thank you very much for your response i edited my code like this
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
FragmentVue1 FragmentVue1 = new FragmentVue1();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentManager fragmentTransaction = fragmentManager;
beginTransaction();
fragmentTransaction.replace(R.id.container, FragmentVue1 );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity.intent();
break;
FragmentVue1 is the name of my activity 1 and the activity load the layout, the code i posted up is little edited than than that you gave me on up reply, because eclipse stress it that suggested me some code to change for exemple
HTML:
Fragment Frgment1 = new FragmentVue1();
raplace in this code is still empty and eclipse ask me to Add cast method receiver
HTML:
fragmentTransaction.replace(R.id.container, FragmentVue1 );
and in this code too fro commit
HTML:
fragmentTransaction.commit();
for this code
HTML:
startActivity.intent();
eclipse is asking me to crete local variable startActivity, create field starActivity,create parameter startActivity create class, and constant .
i'm sorry if i bring to difficult place i really need it to change layout(fragment) to start it just for show a mock up
canempire said:
hello friend thank you very much for your response i edited my code like this
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
FragmentVue1 FragmentVue1 = new FragmentVue1();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentManager fragmentTransaction = fragmentManager;
beginTransaction();
fragmentTransaction.replace(R.id.container, FragmentVue1 );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity.intent();
break;
FragmentVue1 is the name of my activity 1 and the activity load the layout, the code i posted up is little edited than than that you gave me on up reply, because eclipse stress it that suggested me some code to change for exemple
HTML:
Fragment Frgment1 = new FragmentVue1();
raplace in this code is still empty and eclipse ask me to Add cast method receiver
HTML:
fragmentTransaction.replace(R.id.container, FragmentVue1 );
and in this code too fro commit
HTML:
fragmentTransaction.commit();
for this code
HTML:
startActivity.intent();
eclipse is asking me to crete local variable startActivity, create field starActivity,create parameter startActivity create class, and constant .
i'm sorry if i bring to difficult place i really need it to change layout(fragment) to start it just for show a mock up
Click to expand...
Click to collapse
I guess using
"startActivity(intent);"
instead of
"startActivity.intent();" will please eclipse
and not to mention will solve the issue
I bet u didn google that
Sent from my GT-S5302 using Tapatalk 2
canempire said:
hello friend thank you very much for your response i edited my code like this
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
switch (position) {
case 0:
//For loading a fragment
FragmentVue1 FragmentVue1 = new FragmentVue1();
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentManager fragmentTransaction = fragmentManager;
beginTransaction();
fragmentTransaction.replace(R.id.container, FragmentVue1 );
onSectionAttached(0);
fragmentTransaction.commit();
break;
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity.intent();
break;
FragmentVue1 is the name of my activity 1 and the activity load the layout, the code i posted up is little edited than than that you gave me on up reply, because eclipse stress it that suggested me some code to change for exemple
HTML:
Fragment Frgment1 = new FragmentVue1();
raplace in this code is still empty and eclipse ask me to Add cast method receiver
HTML:
fragmentTransaction.replace(R.id.container, FragmentVue1 );
and in this code too fro commit
HTML:
fragmentTransaction.commit();
for this code
HTML:
startActivity.intent();
eclipse is asking me to crete local variable startActivity, create field starActivity,create parameter startActivity create class, and constant .
i'm sorry if i bring to difficult place i really need it to change layout(fragment) to start it just for show a mock up
Click to expand...
Click to collapse
you don't need to use any code present in case 0 if you are not loading a fragment. I just wrote that to make sure you know the difference between starting an activity and a fragment.
If you just want too start an activity just use what is inside case 1.
and as @sak-venom1997 said it should be startActivity(intent) instead of startActivity.intent(). My bad (i am a confused person )
so suppose FragmentVue1 is your activity's name and you want to open it on clicking nth item of navigation drawer use
PHP:
case n:
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
gh0stslayer said:
you don't need to use any code present in case 0 if you are not loading a fragment. I just wrote that to make sure you know the difference between starting an activity and a fragment.
If you just want too start an activity just use what is inside case 1.
and as @sak-venom1997 said it should be startActivity(intent) instead of startActivity.intent(). My bad (i am a confused person )
so suppose FragmentVue1 is your activity's name and you want to open it on clicking nth item of navigation drawer use
PHP:
case n:
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
Click to expand...
Click to collapse
thank you very much for yours reply both are usefully @sak-venom1997
yes FragmentVue1 is my activity it load a layout the reality is i know difference between Activity and Layout but no the both with Fragment.
now it working but the MainActivity is empty when i start the app and i find a warning in code below case 1 break i copied the warning in message in the below code in the line of warning
PHP:
private void onSectionAttached(int i) {
// TODO Auto-generated method stub
}
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
canempire said:
thank you very much for yours reply both are usefully @sak-venom1997
yes FragmentVue1 is my activity it load a layout the reality is i know difference between Activity and Layout but no the both with Fragment.
now it working but the MainActivity is empty when i start the app and i find a warning in code below case 1 break i copied the warning in message in the below code in the line of warning
PHP:
private void onSectionAttached(int i) {
// TODO Auto-generated method stub
}
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
Click to expand...
Click to collapse
If i understand you the right way, you are extending Fragment. In this case you are overriding some methods, but dont modify them. How did you get the code? Via the eclipse menu saying "override/implement methods"? Or did you copy the code from somewhere? If you really need to keep the code, i think you have to call super in the method.
Gesendet von meinem SM-N9005 mit Tapatalk
GalaxyInABox said:
If i understand you the right way, you are extending Fragment. In this case you are overriding some methods, but dont modify them. How did you get the code? Via the eclipse menu saying "override/implement methods"? Or did you copy the code from somewhere? If you really need to keep the code, i think you have to call super in the method.
Gesendet von meinem SM-N9005 mit Tapatalk
Click to expand...
Click to collapse
the code is generated when i created the project it is a part of MainActivity.java code it didn't have warning message before i add
PHP:
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
but why the main activity (fragment) is empty?? now :crying:
can someone help me please???
FragmentVue1 isi an Activity it is FragmentVue1.java and the code is
PHP:
package com.projectmockup.cypruscityguide;
import com.projectmockup.cypruscityguide.R;
import android.app.Activity;
import android.os.Bundle;
public class FragmentVue1 extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.hotel);
}
}
please help when i start the application the Fragment_main.xml is empty but before i use this code in MainActivity
PHP:
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
the content of Fragment_main.xml was visible
i check below in the MainActivity and i found this code with alert
PHP:
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
canempire said:
FragmentVue1 isi an Activity it is FragmentVue1.java and the code is
PHP:
package com.projectmockup.cypruscityguide;
import com.projectmockup.cypruscityguide.R;
import android.app.Activity;
import android.os.Bundle;
public class FragmentVue1 extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.hotel);
}
}
please help when i start the application the Fragment_main.xml is empty but before i use this code in MainActivity
PHP:
case 1:
//To start a new activity
Intent intent = new Intent(this,FragmentVue1.class);
startActivity(intent);
break;
the content of Fragment_main.xml was visible
i check below in the MainActivity and i found this code with alert
PHP:
private void beginTransaction() { // WARNING: The method beginTransaction() from the type MainActivity is never used locally
// TODO Auto-generated method stub
}
private FragmentManager getSupportFragmentManager() {//WARNING:The method getSupportFragmentManager() from the type MainActivity is never used locally
// TODO Auto-generated method stub
return null;
}
Click to expand...
Click to collapse
You don't need to add these lines, they are for opening a fragment. I just provided them to help you know how to open a fragment from navigation drawer.
Synopsis:
Have you ever wanted as root apps developer to use your favourite Java codes instead of bash/shell commands?
Have you grown tired of Runtime.getRuntime.exec("su") and ProcessBuilder("su").start()?
I did and still do, that's why I've been searching for a solution for my problem until I found out in AOSP source code that some of *.java files run with root access, tracking the way they execute them with root access led me to make this simple library.
Description:
Cmd library -short for Command- is an open source (licensed under Apache licence V2) that allows you to execute java commands with root access privileges by passing package name, full class name and whether your app is a system app or not in just two lines of codes.
For instance, suppose you want to flash a *.img recovery image, the first thing comes to your mind is this code:
Code:
busybox dd if=/path/to/recovery.img of=/path/to/recoveryPartition
lets say /sdcard/recovery.img is the file path and /dev/block/mmcblk0p12 is the partition (Samsung GALAXY Ace Plus GT-S7500)
Here is how to implement it:
Code:
...
Proccess proc = Runtime.getRuntime().exec("su");
OutputStream stream = proc.getOutputStream();
stream.write("busybox dd if=/sdcard/recovery.img of=/dev/block/mmcblk0p12".getBytes());
stream.flush();
...
Pretty simple isn't it, now suppose you don't know anything about bash codes, what will you do?
Let me answer this question:
1) Learn some bash.
2) Use Cmd library with java codes.
Here is the same implementaion with Cmd library:
Code:
...
JavaRoot root = JavaRoot.newInstance(getPackageName(), RootCommands.class.getName(), false);
root.execute("/sdcard/recovery.img", "/dev/block/mmcblk0p12")
...
And in RootCommands.java file (should not be an inner class):
Code:
package com.bassel.example;
import com.bassel.cmd.Command;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Main extends Command
{
private byte[] buffer;
private File recovery, partition;
private FileInputStream in;
private FileOutputStream out;
//static main method implementation is a must
@Override
public static void main(String[] args)
{
//required to start
new Main().run(args);
}
//the begging just like onCreate
@Override
public void onRun()
{
if(argsCount() < 2) showUsage();
System.out.println(String.format("Flashing %s to %s", getArg(0), getArg(1)));
recovery = new File(nextArg());
partition = new File(nextArg());
buffer = new byte[1024 * 1024];
try
{
in = new FileInputStream(recovery);
out = new FileOutputStream(partition);
while(in.read(buffer) > 0)
{
out.write(buffer);
out.flush();
}
in.close();
out.close();
System.out.println("Flashed successfully!");
}
catch (Exception e)
{e.printStackTrace(System.err);}
}
//called upon calling showUsage()
@Override
public void onShowUsage()
{
System.err.println("Two args are needed!");
}
//called once an exception is caught
@Override
public void onExceptionCaught(Exception exception)
{
exception.printStackTrace(System.err);
}
}
Quite lengthy but sometimes we prefer using Java codes to bash ones, don't we?
Here is another example for listing /data files:
Code:
package com.bassel. example;
import java.io.File;
//Without extending Command.class
public class Main
{
@Override
public static void main(String[] args)
{
String[] files = new File("/data").list();
for(String file : files)
{
System.out.println(file);
}
}
}
Usage in depth:
Check root access:
Cmd.root();
No root:
Cmd.SH.ex(String command, String... args);
Cmd.SH.ex(String[] commands);
Cmd.SH.ex(List commands);
With root access:
Cmd.SU.ex(String command, String... args);
Cmd.SU.ex(String[] commands);
Cmd.SU.ex(List commands);
JavaRoot java = JavaRoot.newInstance(String packageName, String className, boolean isSystemApp);
java.execute(String... args);
java.executeInBackground(String... args);
All previous methods aside of the last one:
java.executeInBackground(String... args);
return an instance of type Output that has the following methods:
Code:
boolean success() //returns true if process exit value = 0 else false
String getString() //returns output in String format
String[] getArray() //returns output in String Array format
List getList() //returns output in String List format
int getExitValue() //returns process exit value
String toString() //returns process status and output in String format
Converting:
String string = ...;
String[] array = ...;
List list = ...;
String s1 = Convert.array2string(array);
String s2 = Convert.list2string(list);
String[] a1 = Convert.list2array(list);
String[] a2 = Convert.string2array(string);
List l1 = Convert.array2list(array);
List l2 = Convert.string2list(string);
Library GitHub link:
Cmd (licensed under Apache License, Version 2.0)
Examples:
Window Manipulator
Hello
I have a repetitive function that I want to complete in a loop. The loop will be based upon an array of numbers that will be used to form variables.
This is what I have so far, but it wont work
int aNums[] = { 2, 3, 4, 8 };
for (int n : aNums) {
if(buttonState + n == 1){
btn + n.setBackgroundColor(Color.GREEN);
buttonState + n = 2;
}
}
It keeps telling me it cannot resolve symbol buttonState and btn
Please let me know if you need more information.
We need more code.
But if your IDE say it cannot resolve symbol buttonState and btn, declare your variables in global, it's like that:
Code:
public class Main extends Activity {
int buttonState, btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Your code...
}
// Your code...
}