Friday, February 28, 2014

About Android application performance problems


The software is customized client businesses, merchants upload information goods, gifts, promotions and other management systems in the background, then the client can see above, submit orders, exchange gifts. Now the test phase, the discovery process is very large power consumption, heat generation is very serious, it should be application performance problems. After a simple comparison, the power consumption is about 2 times of public comment.
The main logic is as follows:
1 resident has a background service to access the network through the service, and then return the data to the callback Activity in. Service thread loop about every 500ms (Thread.sleep (500)), if the current task is to access the network have access to the data, otherwise it will do nothing and continue the cycle.
2 Use HttpClient request data, the server returns JSON data, analyze, and display.
Content 3. Portion of the page is stored in the local database, while the picture into SD card. When re-entering the page, if not directly read local data network, if the network is properly request the network, and then update the local data, and then read the local data is displayed.
4 main interface using TabHost plus Fragment achieved.

Great God, please help analyze, those places might cause a greater impact application performance? Or recommend, what tools can be used to detect what program performance.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Average power consumption of a large personal opinion is the following reasons
A lot of data in the service logic can be passed to the client-side processing, client processing logic power.
2 client starts a lot of threads, the thread is not only occupy memory, and CPU scheduling needs.
3 a number of instances of the client object is not released.
4 client used some complex logic calculations are not suitable for handling JAVA, JNI C code should be placed in the handle.

If background service is particularly complex, it opens a separate process handled by Binder transmit data. Reduce the burden on the client process.
Reply:
http://mobile.51cto.com/android-229128.htm
Reply:
Average power consumption is caused due to network interaction too frequently, you can think of ways to try to reduce the number of network interactions.
Reply:
From your description of the analysis, it should be too frequent cause of network requests.
The first interval to extend the network request to see the results.
The second guarantee request time constant, the other operation is not performed.
This should be able to compare the results.
Reply:
Smart phone to access the network when power consumption is amazing, so your program should be the access to the network tinkering update, and then have your data requested are not so big?
Reply:
Optimizing a problem
Reply:
cited a floor birdsaction reply:
largest personal consumption generally considered to be the following reasons
A lot of data in the service logic can be passed to the client-side processing, client processing logic power.
2 client starts a lot of threads, the thread is not only occupy memory, and CPU scheduling needs.
3 a number of instances of the client object is not released.
4 client used some complex logic calculations are not suitable for handling JAVA, JNI C code should be placed in the handle.

If background service is particularly complex, it opens a separate process handled by Binder transmit data. Reduce the burden on the client process.


The first problem is certainly there, because the content of many interfaces are not standardized, the client was forced to do a lot of string manipulation, determine the type, count, etc., do not know to what extent these logic would affect performance?
Several back for my program should not be a problem.

Reply:
reference to the third floor andywujing reply:
general consumption are caused due to network interaction too frequently, you can think of ways to try to reduce the number of network interactions.


This can not reduce ah, almost every page needs to request data, even if some of the data is stored locally, and still to this page when the judgment was requested data networking updates, and then update the local database. If the data is not updated, then do not re-download images of (the data stored in the database as well as picture into the SD card). I do not know this design worth?
Reply:
references, 4th Floor hsczm reply:
analysis from your description, it should be too frequent cause of network requests.
The first interval to extend the network request to see the results.
The second guarantee request time constant, the other operation is not performed.
This should be able to compare the results.


Maybe I was not clear it, that Thread.sleep (500) thread has been running, but not always in the requested data. If no request task data, then it is equivalent to an empty circle, two times per second. This will cost electricity in the extent of it? Also, I was put into this thread with no wait when the task the way, has the task when notify, as if nothing results.
Reply:
1. The amount of data transfer over the interface is large? Or if time is too long to resolve complex data structures.
Average power consumption is too much to networking operations, such as data can do an interface to obtain, but need three interfaces to the data read.
Reply:
reference to the 10th floor birdsaction reply: data
1 pass over the interface is large? Or if time is too long to resolve complex data structures.
Average power consumption is too much to networking operations, such as data can do an interface to obtain, but need three interfaces to the data read.


For example, the application of a product list page, click on the list of goods into the product detail page.
So, is made of two interfaces, two pages were requested data is good? Or make an interface in the list of goods directly to the product details page returns come better?
Reply:
Do 2 interface for easy expansion. Also make a trip.

MotionEvent.ACTION_MOVE:


Carried MotionEvent.ACTION_MOVE: operation, and then meet certain conditions (such as Event.getX> 50). Then pop-up dialog: Pass

For example, when you move the process through had 10 points to meet the conditions, 10 times the dialog will pop up, how let him meet the first condition: problems encountered pop-up dialog A dialog box will pop up, do not do judgment behind?
Thank you. . . .<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Records about the state of the pop-up dialog, a dialog box before the judge to look at each state, if you have played and are no longer playing.
Reply:
I use AlertDialog.Builder builder dialog box pops up, how to record status, whether similar
if (! AlertDialog.Builder builder) and the like? Did not so do java, not very clear. Thank you. . .

        


Reply:

Reply:
Defined
 private boolean flag = true; 


Method in the MotionEvent.ACTION_MOVE
 if (flag) {
flag = false;
/ / Pop-up dialog
}

In MotionEvent.ACTION_UP method where then flag assignment was true.
Reply:
The code:
 case MotionEvent.ACTION_MOVE: 
{
rec.x = event.getX ();
rec.y = event.getY ();
rec.size = event.getSize ();
int nh = event.getHistorySize ();
for (int h = 0; h float hx = event.getHistoricalX (h);
float hy = event.getHistoricalY (h);
addPoint (rec, hx, hy);
}
addPoint (rec, rec.x, rec.y);
}
if (flag) {
if (rec.y> ((sh-32) * 2 +64) / 4f-16 && rec.y <((sh-32) * 2 +64) / 4f +16)
{
flag = false;
new AlertDialog.Builder (getContext ())
. SetCancelable (true)
. SetTitle ("Test Results")
. SetMessage ("2.5mm:! Fail")
. SetPositiveButton ("OK", new android.content.DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog, int whichButton) {
/ / Cancel button event
dialog.dismiss ();
}
})
. Show ();
}
}


Touch the future there will be a prompt box, then an application error occurs, to help analyze. . Thank you.
Reply:
references, 5th Floor ysleee reply:
......

Error log made up.
Reply:
references, 5th Floor ysleee reply:
. . . . . .

This code is no problem, I have already been verified. Add two points:
1 In MotionEvent.ACTION_UP method where then flag assigned to true.
Direct return true 2.MotionEvent.ACTION_MOVE the case after treatment finished.
Reply:
 10-25 11:03:19.948: W / dalvikvm (14654): threadid = 1: thread exiting with uncaught exception (group = 0x2aac8578) 
10-25 11:03:19.948: E / AndroidRuntime (14654): FATAL EXCEPTION: main
10-25 11:03:19.948: E / AndroidRuntime (14654): java.lang.IllegalArgumentException: Can't post updates without LOOPED_TICKER set
10-25 11:03:19.948: E / AndroidRuntime (14654): at org.hermit.android.core.SurfaceRunner.postUpdate (SurfaceRunner.java: 523)
10-25 11:03:19.948: E / AndroidRuntime (14654): at org.hermit.touchtest.StGridView2.onTouchEvent (StGridView2.java: 136)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.view.View.dispatchTouchEvent (View.java: 3952)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java: 1034)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java: 1034)
10-25 11:03:19.948: E / AndroidRuntime (14654): at com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent (PhoneWindow.java: 1691)
10-25 11:03:19.948: E / AndroidRuntime (14654): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java: 1125)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.app.Activity.dispatchTouchEvent (Activity.java: 2096)
10-25 11:03:19.948: E / AndroidRuntime (14654): at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent (PhoneWindow.java: 1675)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.view.ViewRoot.deliverPointerEvent (ViewRoot.java: 2219)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.view.ViewRoot.handleMessage (ViewRoot.java: 1903)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.os.Handler.dispatchMessage (Handler.java: 99)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.os.Looper.loop (Looper.java: 138)
10-25 11:03:19.948: E / AndroidRuntime (14654): at android.app.ActivityThread.main (ActivityThread.java: 3701)
10-25 11:03:19.948: E / AndroidRuntime (14654): at java.lang.reflect.Method.invokeNative (Native Method)
10-25 11:03:19.948: E / AndroidRuntime (14654): at java.lang.reflect.Method.invoke (Method.java: 507)
10-25 11:03:19.948: E / AndroidRuntime (14654): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 878)
10-25 11:03:19.948: E / AndroidRuntime (14654): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 636)
10-25 11:03:19.948: E / AndroidRuntime (14654): at dalvik.system.NativeStart.main (Native Method)

Reply:
I think the reason is that every move when, in rec.y meet the conditions of many of the points are pop-up dialog box, resulting in data caused by gambling plug.
Reply:
reference to the 9th floor ysleee reply:
I think the reason is that every move when, in rec.y meet the conditions of many of the points are pop-up dialog, resulting in Data bet plug due.

Now every move a pop-up box will pop up ah. See log like this is the problem.
You can try to put if (flag) to advance to the case MotionEvent.ACTION_MOVE: the place to start.
Reply:
Oh, thank you for your patience reply. CSDN found this place really is not much enthusiastic person. . . Chit'd kicked a bunch of people in the workplace more. . . . .
Reply:
Get a global boolean or int value judgment on ok, stop the role play
Reply:
"OK" button, there appears a button, and then appeared again, looks like a dot on the number of responses pop a few.
Reply:
reference to the 13th floor ysleee reply:
"OK" button, a button appears there, then appeared again, seemingly in response to the number of points will pop up a few.

You send me the code has already been verified ah, specifically to see the 7th floor, did not you say a problem.
Why do not you send the full activity, I see.
Reply:
Oh, have to get is the other java short cycle call causes, tantahe positive solution, affixed to the end points.

dao method android database table structure how many packages


As many relationship problems, assuming that departments and employees. Table structure how design, dao method how the package.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Design an employee table
Design a department table

Plus a table in the middle, which contains employee ID, department ID, should be OK.

High German mobile navigation APP version of the interface?


High German navigation software Mobile APP version of the interface is what achieved? I know high German web version, Baidu mobile navigation APP, Baidu Mobile Map APP, Baidu web version of the map, such as are used in the picture display. But the study of high moral navigation phone APP interface in the form of a picture display like that is what the technology to achieve it?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Personally think is a graphical drawing out, with the underlying graphics library written in C.
Reply:
cited a floor birdsaction reply:
personally think is a graphical drawing out, with the underlying graphics library written in C.
I actually said was online navigation, navigation maps and Baidu now have high moral free download, after download navigation will find online and offline navigation, offline navigation requirements need to download the offline package, I not required to know the package off the map interface is how to achieve, I just want to know is when online loading map is what is displayed? I think it is nothing more than two, one is to get the picture from the server, and the other to get geographical data from the server to the client, the client and then to draw the map and display information based on geographic data. I do not know if the analysis is wrong, I do not know there is no other way.
Reply:
Navigation data is retrieved from the server, and then draw a map based on client data. Personally feel that this situation is more common.
Reply:
If the picture obtained from the server, traffic will be very large.
Reply:
references, 4th Floor birdsaction reply:
images retrieved from the server if the traffic will be very large.
little calculated web version of each picture before 3K, a total of 28 within the viewable area map, that is 84K, if it is mobile version should be smaller.

Time setting and file.lastModified () strange questions


1 In the system settings app in the native, the time to adjust to future
2 write in their own document management app, the new file on the sd card
3 View file.lastModified () is correct
4.adb reboot
5. Then view file.lastModified () more than the correct time of 8 hours
Note: The log is found throughout the area east of eight, time to adjust to the past will not happen, it is difficult to understand, ah, no means of positioning, which seniors pointing 12. Method creates files created: final File file = new File (filePath);<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
The reply was deleted at the moderator 2011-12-28 10:32:47

Reply:
Dinga own
Reply:
Normal, because we are eight districts in the East, then the system time is GMT time, which is GMT
New files are then calls the default time zone editor java last time, and we are Beijing, eight districts in East
Reply:
reference to the third floor ncuboy045wsq reply:
normal, because we are eight districts in the East, then the system time is GMT time, which is GMT
New files are then calls the default time zone editor java last time, and we are Beijing, eight districts in the East

When viewing before the modification time zone is east eight districts. Look after the restart time zone, or the East eight districts.
Reply:
references, 4th Floor zhlwwj1314 reply:
reference to the third floor ncuboy045wsq reply:

Normal, because we are eight districts in the East, then the system time is GMT time, which is GMT
New files are then calls the default time zone editor java last time, and we are Beijing, eight districts in Eastern

When viewing before the modification time zone is east eight districts. Look after the restart time zone, or the East eight districts.

You can change the time zone in the settings
Reply:
references, 5th Floor ncuboy045wsq reply:
references, 4th Floor zhlwwj1314 reply:

References to the third floor ncuboy045wsq reply:

Normal, because we are eight districts in the East, then the system time is GMT time, which is GMT
New files are then calls the default time zone editor java last time, and we are Beijing, eight districts in Eastern

When viewing before the modification time zone is east eight districts. Look after the restart time zone, or the East eight districts.

You can change the time zone in the settings

My question is around the time zones have not changed, why the modification time into the future, and then create a new file, reboot, lastModified file more than eight hours on?
Before the new file modification time is not the problem,
After the last modification time to the new problem is not the problem.
Reply:
reference to the third floor ncuboy045wsq reply:
normal, because we are eight districts in the East, then the system time is GMT time, which is GMT
New files are then calls the default time zone editor java last time, and we are Beijing, eight districts in the East

The current time zone is already eight districts of the East, but also why the java editor last time time zone default tune it? Virtual machines can also get the current time zone with the default time zone, justified ah? !
Reply:
Do not understand, you use examples illustrate this problem, we might be able to think quickly on the root of the problem
Reply:
reference to the 7th floor zhlwwj1314 reply:
reference to the third floor ncuboy045wsq reply:

Normal, because we are eight districts in the East, then the system time is GMT time, which is GMT
New files are then calls the default time zone editor java last time, and we are Beijing, eight districts in Eastern

The current time zone is already eight districts of the East, why java is also the last time to adjust the time zone default edit it? Virtual machines can also get the current time zone with the default time zone, justified ah? !

This is just a small problem, you do not have too tangled, which with your project needs any conflict, if not, the next time you use the correct time zone as long as you can, in fact, you do not control the time zone, usually displayed with the default time zone time
Reply:
reference to the 9th floor ncuboy045wsq reply:
This is just a small problem, you do not have too tangled, which tell you what the project needs conflict, and if not, The next time you use the correct time zone as long as you can, in fact, when you do not control the area, usually to show time

with the default time zoneI would not have come not tangle it asked. Although this is a small problem, but the test provides a single hanging in my name, resolved not to resolve the leadership can be seen, for me is very important. Brother, do not pull the time zone, the time zone is always correct:
cited landlord zhlwwj1314 replies:
NOTE: Logs are found throughout the eastern time zone eight

file.lastModified () sent 28800000 milliseconds which is eight hours before the restart and get the timestamp after the restart. In the end you know the cause of this problem.
Reply:
reference to the 8th floor yipiao729 reply:
do not understand, you use examples illustrate this problem, we might be able to think quickly on the root of the problem
< / fieldset>
Hello little brother, little brother must not read, do not understand you can ask my brother, my brother give you answers! Thank you!
Reply:
The reply was deleted at the moderator 2011-12-30 10:23:12

Reply:
Post code
Reply:
I ask you this question brothers solved? We also encountered this problem you ~

Which path system, the program can be easily used? ?


RT
Machine yard no sd card, wanted in the program where the path (like "/ data / data / com.example.XXXXX / files") which create and play amr files, but encountered a problem ...

I created in "/ data / data / com.example.XXXXX / files" inside and write amr files can be, but when the play was an error. Using MediaPlayer, when setDataSource or prepare catch the error "prepare failed:. Status = 0x1", check the seemingly insufficient permissions ...

online read, mention the right way, the test did not succeed ... anyone provide some information, connections, etc.? ?
Alternatively, there is a directory which can be used directly? ? That is not to mention the right you can read, write, create, delete, play? ? ?

Please advise, thank ~ ~ ~



<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
This directory can assert the
Reply:
What is reported is wrong? The landlord posted an error to

This case, I guess there might be need to declare AndroidManifest appropriate permissions to read media, right?
Reply:
reference to the second floor ncepu307 reply:
reported what is wrong? The landlord posted an error to

This case, I guess there might be need to declare AndroidManifest appropriate permissions to read media, right?

Permission to read and play
Reply:
 


Apart from this, but also what is not?
Reply:
references, 4th Floor CCDDzclxy reply:
 


Apart from this, but also what is not?


Program to read and write files, in addition to adding
 

, But also pay attention to the directory you want to read and write, android system does not have write permissions to be able to post operating all directories.
If there sd card, add permissions to read and write files directly after.
If there is no sd card, you can get this program private cache directory, this directory is that you can easily operate. Such as directory
Android / data / com.example / cache,
Under no circumstances sd card, you can
 context.getCacheDir (). getPath () 
to get the private cache directory
your program

Reply:
references, 5th Floor TandyT reply:
Quote: references to the 4th floor CCDDzclxy reply:

 


Apart from this, but also what is not?


Program to read and write files, in addition to adding
 

, But also pay attention to the directory you want to read and write, android system does not have write permissions to be able to post operating all directories.
If there sd card, add permissions to read and write files directly after.
If there is no sd card, you can get this program private cache directory, this directory is that you can easily operate. Such as directory
Android / data / com.example / cache,
Under no circumstances sd card, you can
 context.getCacheDir (). getPath () 
to get the private cache directory
your program

OK, very grateful, to try to
Reply:
references, 5th Floor TandyT reply:
without the sd card case, you can
 context.getCacheDir (). getPath () 
to get the private cache directory of your program


context is not getApplicationContext () achieved?
Seemingly, nor ah ... inside the virtual machine is OK.
Reply:
reference to the 7th floor CCDDzclxy reply:
Quote: references, 5th Floor TandyT reply:

Under no circumstances sd card, you can
 context.getCacheDir (). getPath () 
to get the private cache directory of your program


context is not getApplicationContext () achieved?
Seemingly, nor ah ... inside the virtual machine is OK.


Yeah this is obtained. If you get to be null, then try the Activity onCreate function in a direct access to this:
 this.getCacheDir (). getPath () 


You say no, what steps are wrong? You get to see the actual print out the cache path there is no such path.
Reply:
reference to the 7th floor CCDDzclxy reply:
Quote: references, 5th Floor TandyT reply:

Under no circumstances sd card, you can
 context.getCacheDir (). getPath () 
to get the private cache directory of your program


context is not getApplicationContext () achieved?
Seemingly, nor ah ... inside the virtual machine is OK.


Or put your log posted, so to say too general, can not help you analyze.
Reply:
cited a floor birdsaction reply:
assert this directory is possible

People are created dynamically, assets God horse?
Reply:
Thank you, now test,

TandyT said is right, like "Android / data / com.example / cache" directory is possible,

I say the roof of "/ data / data / com.example.XXXXX / files" is also possible. Check it out when I did not pay attention to the comment, setDataSource not commenting, write new code below Shiyou setDataSource once, so have the wrong ...
Reply:
Oh, careless of @ _ @
Enough to solve the

Android xxx is not translated in zh


Report xxx is not translated in zh
play when android apk package using eclipseAfter
Eclipse> Preference> Android> Lint Error Checking of Correctness: Messages> MissingTranslate
The Severity changed from Fetal Warming
The success of the package
However, the use of automated packaging tools Ant when that report came out wrong again, but it does not take
apkGreat God seeking advice<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Eclipse - Properties - Android Lint preferences - MissingTranslate key to warning can be.
Reply:
cited a floor Eyebrows_cs reply:
Eclipse - Properties - Android Lint preferences - MissingTranslate key to warning to
.
I know ah, apk parent package is out, the test no problem, but when using packaging tools, the error still occurs
Reply:
reference to the second floor mayuanSY reply:
Quote: references to a floor Eyebrows_cs reply:

Eclipse - Properties - Android Lint preferences -. MissingTranslate key to warning to

I know ah, apk parent package is out, the test no problem, but when using packaging tools, the error still occurs



Why use a packaged tool? APK package is not already out yet? To code obfuscation it?
Reply:
reference to the third floor Eyebrows_cs reply:
Quote: references to the second floor mayuanSY reply:

Quote: references to a floor Eyebrows_cs reply:

Eclipse - Properties - Android Lint preferences -. MissingTranslate key to warning to

I know ah, apk parent package is out, the test no problem, but when using packaging tools, the error still occurs



Why use a packaged tool? APK package is not already out yet? To code obfuscation it?


APK package using the same signature and batch are not the same!

Urgent! Android devices in the SD card in the windows of more than 100M write data appears parameter error?


As stated in the Android device SD card (2G) connected via usb cable to your PC, write small data (10M) there is no problem in windowsXP, windows7, but it will prompt written 100M data parameter error, or IO device error, which is why ?
As a comparison, also connected to Linux, but this problem does not occur, 100M's, 1G of data can be written into it.
Will Andrews who did the SD card driver, and have not encountered such problems, how to solve?

              


<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
I used the USB cable to the computer before, wrote a standard definition movies, there is no problem ah.

Deathcoaster. Rmvb, file size 570M.
System WindowsXP/Sp3
SD Card 4G / Samsung, FAT32 file system.

Reply:
The landlord, do you say:
Android running on the computer program to the SD card Android devices write data.
In the Windows system, 100M data will make a mistake?


Reply:
reference to the second floor Chen8013 reply:
landlord, do you say:
Android running on the computer program to the SD card Android devices write data.
In the Windows system, 100M data will make a mistake?
No, refers to copy data to the SD card (such as direct drag files, folders on the SD card), small data (50M or less) can, but try to use more than 100 M, there will be problems. Card is not a problem, because with a card reader for reading and writing is normal.
Reply:
cited a floor Chen8013 reply:
I use the USB cable to the computer before, wrote a standard-definition movies, there is no problem ah.

Deathcoaster. Rmvb, file size 570M.
System WindowsXP/Sp3
SD Card 4G / Samsung, FAT32 file system.
may also be concerned with the equipment, but may wonder why on Linux, Windows and Linux do not know the USB Mass Storage Device driver writes what is the difference.

        


Reply:
The result is a function with f_mass_storage.c about the do_write

android null pointer exception




 package cn.example.vstdemo; 

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnFocusChangeListener,
OnClickListener {

private TextView tv_newFilm, tv_networkTV, tv_category, tv_myFavourite,
tv_application, tv_setting;
private ImageView img1, img2, img3, img4, img5, img_cursor;

private List views; / / Tab page list
private int offset = 0; / / animated pictures offset
private int currIndex = 0; / / this page card number
private int bmpW; / / animated image width
private View view1, view2, view3, view4, view5, view6;

private ViewPager viewPager;
private MyViewPagerAdapter adapter;

@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);


InitImageView ();
InitViewPager ();

}

public void init () {
tv_newFilm = (TextView) findViewById (R.id.tv_newFilm);
tv_networkTV = (TextView) findViewById (R.id.tv_networkTV);
tv_category = (TextView) findViewById (R.id.tv_category);
tv_myFavourite = (TextView) findViewById (R.id.tv_myFavourite);
tv_application = (TextView) findViewById (R.id.tv_application);
tv_setting = (TextView) findViewById (R.id.tv_setting);

img1 = (ImageView) findViewById (R.id.imageView1);
img2 = (ImageView) findViewById (R.id.imageView2);
img3 = (ImageView) findViewById (R.id.imageView3);
img4 = (ImageView) findViewById (R.id.imageView4);
img5 = (ImageView) findViewById (R.id.imageView5);
img_cursor = (ImageView) findViewById (R.id.cursor);

tv_newFilm.setOnFocusChangeListener (this);
tv_networkTV.setOnFocusChangeListener (this);
tv_category.setOnFocusChangeListener (this);
tv_myFavourite.setOnFocusChangeListener (this);
tv_application.setOnFocusChangeListener (this);
tv_setting.setOnFocusChangeListener (this);

img1.setOnClickListener (this);
img2.setOnClickListener (this);
img3.setOnClickListener (this);
img4.setOnClickListener (this);
img5.setOnClickListener (this);
}

private void InitViewPager () {
viewPager = (ViewPager) findViewById (R.id.viewPager);
views = new ArrayList ();
LayoutInflater inflater = getLayoutInflater ();
view1 = inflater.inflate (R.layout.newfilm, null);
view2 = inflater.inflate (R.layout.networktv, null);
view3 = inflater.inflate (R.layout.category, null);
view4 = inflater.inflate (R.layout.myfavourite, null);
view5 = inflater.inflate (R.layout.application, null);
view6 = inflater.inflate (R.layout.mysetting, null);

views.add (view1);
views.add (view2);
views.add (view3);
views.add (view4);
views.add (view5);
views.add (view6);

viewPager.setAdapter (new MyViewPagerAdapter (views));
viewPager.setCurrentItem (0);
viewPager.setOnPageChangeListener (new MyOnPageChangeListener ());
}

private void InitImageView () {
bmpW = BitmapFactory.decodeResource (getResources (),
R.drawable.title_selector). GetWidth () ;/ / Get image width
DisplayMetrics dm = new DisplayMetrics ();
getWindowManager () getDefaultDisplay () getMetrics (dm);..
int screenW = dm.widthPixels ;/ / get resolution width
offset = (screenW / 3 - bmpW) / 2 ;/ / calculate the offset
Matrix matrix = new Matrix ();
matrix.postTranslate (offset, 0);
img_cursor.setImageMatrix (matrix) ;/ / animate the initial position
}

public class MyViewPagerAdapter extends PagerAdapter {
private List mListViews;

public MyViewPagerAdapter (List mListViews) {
this.mListViews = mListViews;
}

@ Override
public void destroyItem (ViewGroup container, int position, Object object) {
container.removeView (mListViews.get (position));
}

@ Override
public Object instantiateItem (ViewGroup container, int position) {
container.addView (mListViews.get (position), 0);
return mListViews.get (position);
}

@ Override
public int getCount () {
return mListViews.size ();
}

@ Override
public boolean isViewFromObject (View arg0, Object arg1) {
return arg0 == arg1;
}
}

public class MyOnPageChangeListener implements OnPageChangeListener {

int one = offset * 2 + bmpW ;/ / Page Card 1 -> Page 2 offset
cardint two = one * 2 ;/ / Page Card 1 -> Page 3 card offset

public void onPageScrollStateChanged (int arg0) {

}

public void onPageScrolled (int arg0, float arg1, int arg2) {

}

public void onPageSelected (int arg0) {

Animation animation = new TranslateAnimation (one * currIndex, one
* Arg0, 0, 0) ;/ / Obviously, this is relatively simple, only one line of code.
currIndex = arg0;
animation.setFillAfter (true) ;/ / True: stop animated images in end position
animation.setDuration (300);
img_cursor.startAnimation (animation);
Toast.makeText (MainActivity.this,
"You have selected" + viewPager.getCurrentItem () + "page card",
. Toast.LENGTH_SHORT) show ();
}

}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.main, menu);.
return true;
}

@ Override
public void onClick (View v) {
Intent intent = new Intent ();
intent.setClass (MainActivity.this, DetailActivity.class);

switch (v.getId ()) {
case R.id.imageView1:
/ / Img1.setAlpha (200);
startActivity (intent);
break;
case R.id.imageView2:
/ / Img2.setAlpha (200);
startActivity (intent);
break;
case R.id.imageView3:
/ / Img3.setAlpha (200);
startActivity (intent);
break;
case R.id.imageView4:
startActivity (intent);
break;
case R.id.imageView5:
startActivity (intent);
break;
default:
;
}
}

@ Override
public void onFocusChange (View v, boolean hasFocus) {
switch (v.getId ()) {
case R.id.tv_newFilm:
/ / Tv_newFilm.setBackgroundResource (R.drawable.select);
tv_newFilm.requestFocus ();
tv_newFilm.setAlpha (200);
tv_newFilm.setNextFocusRightId (R.id.tv_networkTV);
tv_newFilm.setNextFocusDownId (R.id.imageView1);

/ /
tv_newFilm.setNextFocusRightId (R.id.tv_networkTV);
case R.id.tv_networkTV:
tv_networkTV.requestFocus ();
tv_networkTV.setNextFocusLeftId (R.id.tv_newFilm);
tv_networkTV.setNextFocusRightId (R.id.tv_category);
case R.id.tv_category:
tv_category.requestFocus ();
tv_category.setNextFocusLeftId (R.id.tv_networkTV);
tv_category.setNextFocusRightId (R.id.tv_myFavourite);
case R.id.tv_myFavourite:
tv_myFavourite.requestFocus ();
tv_myFavourite.setNextFocusLeftId (R.id.tv_category);
tv_myFavourite.setNextFocusRightId (R.id.tv_application);
case R.id.tv_application:
tv_application.requestFocus ();
tv_application.setNextFocusLeftId (R.id.tv_myFavourite);
tv_application.setNextFocusRightId (R.id.tv_setting);
case R.id.tv_setting:
tv_setting.requestFocus ();
tv_setting.setNextFocusLeftId (R.id.tv_application);
default:
;
}
}

/ / Private class MyViewPagerAdapter extends FragmentPagerAdapter {
/ /
/ / Public MyViewPagerAdapter () {
/ / Super (getSupportFragmentManager ());
/ /}
/ /
/ / @ Override
/ / Public Fragment getItem (int pageNumber) {
/ / Switch (pageNumber) {
/ / Case 0:
/ / Return new newFilmFragment ();
/ / Case 1:
/ / Return new networkTVFragment ();
/ / Case 2:
/ / Return new categoryFragment ();
/ / Case 3:
/ / Return new myFavouriteFragment ();
/ / Case 4:
/ / Return new applicationFragment ();
/ / Case 5:
/ / Return new mysettingFragment ();
/ / Default:
/ / Return null;
/ /}
/ /}

}


This error has been running on the crash, I do not know how to solve, seeking God, you big<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
See error messages should be the place of the exception. Check BitmapFactory.decodeResource
private void InitImageView () {
bmpW = BitmapFactory.decodeResource (getResources (),
R.drawable.title_selector). GetWidth () ;/ / Get image width
DisplayMetrics dm = new DisplayMetrics ();
getWindowManager () getDefaultDisplay () getMetrics (dm);..
int screenW = dm.widthPixels ;/ / get resolution width
offset = (screenW / 3 - bmpW) / 2 ;/ / calculate the offset
Matrix matrix = new Matrix ();
matrix.postTranslate (offset, 0);
img_cursor.setImageMatrix (matrix) ;/ / animate the initial position
}

Reply:
 bmpW = BitmapFactory.decodeResource (getResources (), 
R.drawable.title_selector). GetWidth () ;/ / Get image width

Reported null pointer exception here, check the position title_selector put the picture right, etc.
Reply:
reference to the second floor tantahe reply:
 bmpW = BitmapFactory.decodeResource (getResources (), 
R.drawable.title_selector). GetWidth () ;/ / Get image width

Reported null pointer exception here, check the position title_selector put the picture right, etc.


Just want to be viewpager sliding effect, drawable wrote that no problem ah. What is that reason? Commented tried this, no problem
Reply:
Found,,
 private void InitImageView () {
img_cursor = (ImageView) findViewById (R.id.cursor);
bmpW = BitmapFactory.decodeResource (getResources (),
R.drawable.select). GetWidth () ;/ / Get image width
DisplayMetrics dm = new DisplayMetrics ();
getWindowManager () getDefaultDisplay () getMetrics (dm);..
int screenW = dm.widthPixels ;/ / get resolution width
offset = (screenW / 6 - bmpW) / 2 ;/ / calculate the offset
Matrix matrix = new Matrix ();
matrix.postTranslate (offset, 0);
img_cursor.setImageMatrix (matrix) ;/ / animate the initial position
}


Write the first line in this function, we can, in the prior written another function.
Reply:
 bmpW = BitmapFactory.decodeResource (getResources (), 
R.drawable.title_selector). GetWidth () ;/ / Get image width

The landlord here:
 BitmapFactory.decodeResource (getResources (), 
R.drawable.title_selector)

Return to this picture when decoding an empty Bitmap object, perhaps the problem is in title_selector this picture, this picture you put what?
Are xml files? Just one. Png format images?

In the program folder does not have permission to write files prompt


I want to write a program folder configuration file, the same code, before running no problem, how can today afford to create the file, suggesting that there is no authority to ask the heroes who know how it is, thank you, the following code :
 
FloatWindowService.AppPath = getApplicationContext (). GetFilesDir ()
. GetAbsolutePath ();
flipper_getdata = (ViewFlipper) findViewById (R.id.flipper_getdata);
bar = (ProgressBar) findViewById (R.id.progressBar1);
/ / Create a settings file
here
/ / Check directory exists
File file = new File (FloatWindowService.AppPath);
FloatWindowService.AppPath = FloatWindowService.AppPath
+ "/ Set_data.tyzj";
/ / Set the file to see if there is

file = new File (FloatWindowService.AppPath);
if (! file.exists ()) / / if it does not exist create
{/ / Create a file

try
{File.createNewFile () ;/ / phrase wrong, e.getMessage () is "Permission denied"
Log.v ("message", "file has been created successfully.") ;/ / Not execute the sentence
FloatWindowService.SetFileWrite = openFileOutput (
"Set_data.tyzj", MODE_PRIVATE);
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Yellow error message as follows:

10-26 10:21:38.363: W / System.err (5410): java.io.IOException: Permission denied
10-26 10:21:38.364: W / System.err (5410): at java.io.File.createNewFileImpl (Native Method)
10-26 10:21:38.364: W / System.err (5410): at java.io.File.createNewFile (File.java: 1288)
10-26 10:21:38.365: W / System.err (5410): at com.TianYe.ZhiNengJiaJu.MainActivity.onCreate (MainActivity.java: 60)
10-26 10:21:38.365: W / System.err (5410): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1082)
10-26 10:21:38.365: W / System.err (5410): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 1692)
10-26 10:21:38.365: W / System.err (5410): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 1747)
10-26 10:21:38.366: W / System.err (5410): at android.app.ActivityThread.access $ 1500 (ActivityThread.java: 155)
10-26 10:21:38.366: W / System.err (5410): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 993)
10-26 10:21:38.366: W / System.err (5410): at android.os.Handler.dispatchMessage (Handler.java: 130)
10-26 10:21:38.366: W / System.err (5410): at android.os.Looper.loop (SourceFile: 351)
10-26 10:21:38.366: W / System.err (5410): at android.app.ActivityThread.main (ActivityThread.java: 3814)
10-26 10:21:38.367: W / System.err (5410): at java.lang.reflect.Method.invokeNative (Native Method)
10-26 10:21:38.367: W / System.err (5410): at java.lang.reflect.Method.invoke (Method.java: 538)
10-26 10:21:38.367: W / System.err (5410): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 901)
10-26 10:21:38.368: W / System.err (5410): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 659)
10-26 10:21:38.368: W / System.err (5410): at dalvik.system.NativeStart.main (Native Method)

Reply:
I have always been connected to the real machine, the virtual machine tried it, can create a file, I do not know where my phone has been met, before the normal procedure, in order to test the application in the local management to clear the data, and then unloaded, After it is not alright
Reply:
Manifest in plus permission to try
  

Reply:
Look no authority added


Then open the android emulator to check in the creation of this simulator sd card has not been created
Reply:
Thanks to the above two friends, but I did not write sd card, but the private folder to write the program, the program does have to write another sd card, so this permission is yes. There is a virtual machine is no problem, but the problem is real machine, fax machine and no problem before, only appeared recently, I feel very strange.

android in the database content is written to an external txt file


database = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
Cursor c = database.rawQuery ("select * from t_firstcheckinfo", null);
if (c.moveToFirst ())
{
while (! c.isAfterLast ())
{
int id = c.getInt (0);
. ((Declare) getApplication ()) setId (id);
String barcode = c.getString (1);
. ((Declare) getApplication ()) setBarcode (barcode);
int number = c.getInt (2);
. ((Declare) getApplication ()) setNumber (number);
String firstemployee = c.getString (3);
. ((Declare) getApplication ()) setUser (firstemployee);
String shopname = c.getString (4);
. ((Declare) getApplication ()) setShopname (shopname);
String shelfno = c.getString (5);
. ((Declare) getApplication ()) setShelfno (shelfno);
String firsttime = c.getString (6);
. ((Declare) getApplication ()) setTime (firsttime);
String firstposition = c.getString (7);
. ((Declare) getApplication ()) setPosition (firstposition);
String goodsname = c.getString (8);
. ((Declare) getApplication ()) setGoodsname (goodsname);
c.moveToNext ();

}
}
Intent intent = new Intent (DataexportActivity.this, WritetxtActivity.class);
startActivity (intent);


}

});


Then WritetxtActivity.class code

public class WritetxtActivity extends Activity {
private SQLiteDatabase database;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
try {
database = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
Cursor c1 = database.rawQuery ("select * from t_firstcheckinfo", null);
FileOutputStream fos = new FileOutputStream ("D: \ \ checkinfo.txt");
OutputStreamWriter osw = new OutputStreamWriter (fos);
BufferedWriter bf = new BufferedWriter (osw);
for (int i = 0; i {
bf.newLine () ;/ / first wrap
int id = ((Declare) getApplicationContext ()) getId ();.
bf.write (id + "\ t");
bf.flush ();
String goodsname = ((Declare) getApplicationContext ()) getGoodsname ();.
bf.write (goodsname + "\ t");
bf.flush ();
. String barcode = ((Declare) getApplicationContext ()) getBarcode ();
bf.write (barcode + "\ t");
bf.flush ();
. int number = ((Declare) getApplicationContext ()) getNumber ();
bf.write (number + "\ t");
bf.flush ();
String employee = ((Declare) getApplicationContext ()) getUser ();.
bf.write (employee + "\ t");
bf.flush ();
String shopname = ((Declare) getApplicationContext ()) getShopname ();.
bf.write (shopname + "\ t");
bf.flush ();
String shelfno = ((Declare) getApplicationContext ()) getShelfno ();.
bf.write (shelfno + "\ t");
bf.flush ();
String time = ((Declare) getApplicationContext ()) getTime ();.
bf.write (time + "\ t");
bf.flush ();
String position = ((Declare) getApplicationContext ()) getPosition ();.
bf.write (position + "\ t");
bf.flush ();
bf.newLine ();
bf.flush ();


}
bf.close ();
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}

}
}
Now the problem is whenever I debug, after entering WritetxtActivity, do not go for the cycle, the program went directly to where the catch, logcat then prompts the following information:

I do not know how to solve ah, beg solutions.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
The problem is clear, but can not find the files in the D drive, why do you want to write files to the D drive?
Reply:
No permission, Manifest, adding a
  

Also note that the txt file path is correct.
Reply:
cited a floor q445697127 reply:
question is very clear, but could not find the files in the D drive, why do you want to write files to the D drive?

I am now trying to android read out the contents of the database program, convert txt, and then save the file to a folder inside your computer, in order to facilitate the user to view.
Reply:
reference to the second floor tantahe reply:
no authority, Manifest years plus
  

Also note that the txt file path is correct.

I've added in the Manifest permissions, but the problem still occurs, really do not know what the problem is Kazakhstan. The help of experts to look at Kazakhstan.
Reply:
Your program can run in android file output to the D drive?? You should save the file to SDCard top anti ..
Reply:
reference to the third floor lhx200610930202 reply:
Quote: references to a floor q445697127 reply:

The problem is clear, but can not find the files in the D drive, why do you want to write files to the D drive?

I am now trying to android read out the contents of the database program, convert txt, and then save the file to a folder inside your computer, in order to facilitate the user to view.

When exporting data to a computer in the past I thought derived (not sure I can do that), not all conventional cooking guide to the SD card it?
Reply:
reference to the 6th floor q445697127 reply:
Quote: references to the third floor lhx200610930202 reply:

Quote: references to a floor q445697127 reply:

The problem is clear, but can not find the files in the D drive, why do you want to write files to the D drive?

I am now trying to android read out the contents of the database program, convert txt, and then save the file to a folder inside your computer, in order to facilitate the user to view.

When exporting data to a computer in the past I thought derived (not sure I can do that), not all conventional cooking guide to the SD card it?

I'm also not sure can not do that, my database tables are imported from outside, and then re-generate a new database table in the code, I just want this new database table guide, and to facilitate the user to view content. What if the guide to the sd card, how to achieve it? We look to enlighten
Reply:
http://blog.csdn.net/q445697127/article/details/7519761
This is an example I wrote before, you can probably look
Reply:
reference to the third floor lhx200610930202 reply:
Quote: references to a floor q445697127 reply:

The problem is clear, but can not find the files in the D drive, why do you want to write files to the D drive?

I am now trying to android read out the contents of the database program, convert txt, and then save the file to a folder inside your computer, in order to facilitate the user to view.

Android can not access the computer's hard drive, save it to your sdcard
Reply:
reference to the 8th floor q445697127 reply:
http://blog.csdn.net/q445697127/article/details/7519761
This is an example I wrote before, you can probably look

/ / Convert the content type of the array of bytes byte [] message = txt.getBytes ();
I want to save the data has type int and string, and now my code is like this
try {
database = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
Cursor c = database.rawQuery ("select * from t_firstcheckinfo", null);



FileOutputStream fos = new FileOutputStream ("/ sdcard / checkinfo.txt");

OutputStreamWriter osw = new OutputStreamWriter (fos);
BufferedWriter bf = new BufferedWriter (osw);


for (int i = 0; i {
bf.newLine () ;/ / first wrap
int id = ((Declare) getApplicationContext ()) getId ();.
bf.write (id + "\ t");
bf.flush ();
String goodsname = ((Declare) getApplicationContext ()) getGoodsname ();.
bf.write (goodsname + "\ t");
bf.flush ();
. String barcode = ((Declare) getApplicationContext ()) getBarcode ();
bf.write (barcode + "\ t");
bf.flush ();
. int number = ((Declare) getApplicationContext ()) getNumber ();
bf.write (number + "\ t");
bf.flush ();
String employee = ((Declare) getApplicationContext ()) getUser ();.
bf.write (employee + "\ t");
bf.flush ();
String shopname = ((Declare) getApplicationContext ()) getShopname ();.
bf.write (shopname + "\ t");
bf.flush ();
String shelfno = ((Declare) getApplicationContext ()) getShelfno ();.
bf.write (shelfno + "\ t");
bf.flush ();
String time = ((Declare) getApplicationContext ()) getTime ();.
bf.write (time + "\ t");
bf.flush ();
String position = ((Declare) getApplicationContext ()) getPosition ();.
bf.write (position + "\ t");
bf.flush ();
bf.newLine ();
bf.flush ();


}
bf.flush ();
bf.close ();


} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}



}
After write code or jump directly to catch at the fundamental intermediate code is not executed, but also added the authority. Really do not know why, anxious dead.
Reply:
sdcard path is wrong, the "/ sdcard / checkinfo.txt" into android.os.Environment.getExternalStorageDirectory () + "/ checkinfo.txt"
Reply:
reference to the 11th floor tantahe reply:
sdcard wrong path, the "/ sdcard / checkinfo.txt" into android.os.Environment.getExternalStorageDirectory () + "/ checkinfo.txt"

This approach also tried, or not, the code runs to FileOutputStream fos = new FileOutputStream (android.os.Environment.getExternalStorageDirectory () + "/ checkinfo.txt"); this one, then there would just jump catch a.
Reply:
You posted the logcat error
Reply:
Is not to add conditions, if the file does not exist, create it
Reply:
pc android how to access the D drive thiophene? suggest you first wrote on the sdcard and then uploaded to the server on the line pc thiophene
Reply:
try {
database = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
/ / List = new ArrayList ();
Cursor c = database.rawQuery ("select * from t_firstcheckinfo", null);
/ / String fileNameString = "checkinfo.txt";
/ / Determine whether there sd card Environment.getExternalStorageState () to get the current state
sd card/ / File file = new File (Environment
/ /. GetExternalStorageDirectory (),
/ / FileNameString);

boolean sdCardExist = Environment.getExternalStorageState ()
. Equals (android.os.Environment.MEDIA_MOUNTED); / / determine whether there
sd card
if (sdCardExist)
{
String baseDir = Environment.getExternalStorageDirectory () getAbsolutePath ();.
FileOutputStream fos;
fos = openFileOutput (baseDir, MODE_WORLD_READABLE);
String fileName = "checkinfo.txt";
File f = new File (baseDir + File.separator + fileName);
if (! f.getParentFile (). exists ()) {
. f.getParentFile () mkdirs () ;/ / create a folder, such as: Create / TXT folder f disk / testTXT / two folders.
}
if (! f.exists ()) {
f.createNewFile () ;/ / create a txt file as: testData.txt file
}
FileWriter fileWriter = new FileWriter (f, true);
BufferedWriter bf = new BufferedWriter (fileWriter);
for (int i = 0; i {
bf.newLine ();
int id = ((Declare) getApplicationContext ()) getId ();.
bf.write (id + "\ t");
bf.flush ();
String goodsname = ((Declare) getApplicationContext ()) getGoodsname ();.
/ / Byte [] goodsname1 = goodsname.getBytes ();
bf.write (goodsname + "\ t");
bf.flush ();
. String barcode = ((Declare) getApplicationContext ()) getBarcode ();
bf.write (barcode + "\ t");
bf.flush ();
. int number = ((Declare) getApplicationContext ()) getNumber ();
bf.write (number + "\ t");
bf.flush ();
String employee = ((Declare) getApplicationContext ()) getUser ();.
bf.write (employee + "\ t");
bf.flush ();
String shopname = ((Declare) getApplicationContext ()) getShopname ();.
bf.write (shopname + "\ t");
bf.flush ();
String shelfno = ((Declare) getApplicationContext ()) getShelfno ();.
bf.write (shelfno + "\ t");
bf.flush ();
String time = ((Declare) getApplicationContext ()) getTime ();.
bf.write (time + "\ t");
bf.flush ();
String position = ((Declare) getApplicationContext ()) getPosition ();.
bf.write (position + "\ t");
bf.flush ();
bf.newLine ();
bf.flush ();
}
bf.flush ();
bf.close ();
}

} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
I now put into this program, logcat information

Reply:
Big thank you God's answer above, I already solved the problem, first my right code stickers, encountered the same problem for future friends to learn together.
Reply:
The correct code is try {
database = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
/ / List = new ArrayList ();
Cursor c = database.rawQuery ("select * from t_firstcheckinfo", null);
/ / String fileNameString = "checkinfo.txt";
/ / Determine whether there sd card Environment.getExternalStorageState () to get the current state
sd card/ / File file = new File (Environment
/ /. GetExternalStorageDirectory (),
/ / FileNameString);

boolean sdCardExist = Environment.getExternalStorageState ()
. Equals (android.os.Environment.MEDIA_MOUNTED); / / determine whether there
sd card
if (sdCardExist)
{
String baseDir = Environment.getExternalStorageDirectory (). GetAbsolutePath () ;/ / get SDCard directory
File f = new File (baseDir + "/ /" + "firstcheckinfo.txt");
if (! f.getParentFile (). exists ()) {
. f.getParentFile () mkdirs () ;/ / create a folder, such as: Create / TXT folder f disk / testTXT / two folders.
}
if (! f.exists ()) {
f.createNewFile () ;/ / create a txt file as: testData.txt file
}
FileWriter fileWriter = new FileWriter (f, true);
BufferedWriter bf = new BufferedWriter (fileWriter);
if (c.moveToFirst ())
{
while (! c.isAfterLast ())
{

int id = c.getInt (0);

bf.write (id + "\ t");
bf.flush ();
String goodsname = c.getString (8);
bf.write (goodsname + "\ t");
bf.flush ();
String barcode = c.getString (1);

int number = c.getInt (2);
bf.write (barcode + "\ t");
bf.flush ();

String firstemployee = c.getString (3);
bf.write (firstemployee + "\ t");
bf.flush ();

String shopname = c.getString (4);
bf.write (shopname + "\ t");
bf.flush ();

String shelfno = c.getString (5);
bf.write (shelfno + "\ t");
bf.flush ();

String firsttime = c.getString (6);
bf.write (firsttime + "\ t");
bf.flush ();

String firstposition = c.getString (7);
bf.write (firstposition + "\ t");
bf.flush ();

bf.newLine ();
bf.flush ();
/ / System.out.println (id + ":" + goodsname + ":" + barcode + ":" + number + ":" + firstemployee + ":" + shopname + ":" + shelfno + ":" + firsttime + ":" + firstposition + " : ");
c.moveToNext ();

}
}

; showDialog ("inventory files are stored in / mnt / sdcard in it!")}
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}

ksoap2 call WCF interfaces Tip Cannot serialize: 11.0


I am learning to develop Andriod program, we encounter a very depressed, I was in the top of the server-side WCF service implements a simple addition, subtraction four functions, parameters are two double type data. For example, I would like to achieve 11 + 12 =? But when the client calls the phone always throws an exception,

e RuntimeException (id = 830082723416)
cause RuntimeException (id = 830082723416)
detailMessage "Cannot serialize: 11.0" (id = 830082724304)
stackState (id = 830082724336)
stackTrace null
Server-side code is as follows:
 
public class Demo: Interface
{

# Region Interface Members

public double Add (double a, double b)
{
return a + b;
}

public double subtract (double a, double b)
{
return a - b;
}

public double Multiply (double a, double b)
{
return a * b;
}

public double Divide (double a, double b)
{
if (b == 0)
return 0;
else return a / b;
}

# Endregion
}

Interface:
 
[ServiceContract]
public interface Interface
{
[OperationContract]
double Add (double a, double b);
[OperationContract]
double subtract (double a, double b);
[OperationContract]
double Multiply (double a, double b);
[OperationContract]
double Divide (double a, double b);
}


This is the complete code for the client:
 
public class Android_WCF_CalculateActivity extends Activity {

private static final String [] m_Operators = {"+", "-", "*", "/"};
private static final String m_Namespace = "http://tempuri.org/";
private static final String m_URL = "http://192.168.1.97:8000/Post/Service/Demo";
private static final String m_Soap = "http://tempuri.org/Interface/";

private TextView m_TextA, m_TextB, m_TextResult;
private Spinner m_SpOperators;
private Button m_BtnOK, m_BtnCancel;

private ArrayAdapter adapter;

/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);

Init ();
}

private void Init () {
m_TextA = (TextView) this.findViewById (R.id.editText1);
m_TextB = (TextView) this.findViewById (R.id.editText2);
m_TextResult = (TextView) this.findViewById (R.id.editText3);
m_SpOperators = (Spinner) this.findViewById (R.id.spinner1);
m_BtnOK = (Button) this.findViewById (R.id.button2);
m_BtnCancel = (Button) this.findViewById (R.id.button1);

adapter = new ArrayAdapter (this, android.R.layout.simple_spinner_item,
m_Operators);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
m_SpOperators.setAdapter (adapter);

BtnOK_Click ();
BtnCancel_Click ();
}

private void BtnOK_Click () {
m_BtnOK.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
String methodName;
String item = m_SpOperators.getSelectedItem () toString ();.
if ("+" == item)
methodName = "Add";
else if ("-" == item)
methodName = "subtract";
else if ("*" == item)
methodName = "Multiply";
else
methodName = "Divide";
double value1 = Double.parseDouble (m_TextA.getText () toString ().);
double value2 = Double.parseDouble (m_TextB.getText () toString ().);
SoapObject requet = new SoapObject (m_Namespace, methodName);
requet.addProperty ("a", value1);
requet.addProperty ("b", value2);

SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope (SoapEnvelope.VER11);
envelope.bodyOut = requet;
envelope.dotNet = true;
HttpTransportSE transport = new HttpTransportSE (m_URL);
transport.debug = true;
try {
transport.call (m_Soap + methodName, envelope);
SoapObject response = (SoapObject) envelope.bodyIn;
m_TextResult.setText (response.toString ());
} Catch (Exception e) {
e.printStackTrace ();
}
}
});
}

private void BtnCancel_Click () {
m_BtnCancel.setOnClickListener (new OnClickListener () {
public void onClick (View v) {
Android_WCF_CalculateActivity.this.finish ();
}
});
}
}


This is the WSDL file:
 



< br />























































































http://192.168.1.97:8000/Post/Service/Demo




The above is a complete code, I hope to help find out why. .<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Answered. . . . Their top
Reply:
. . Halo nobody. . Today, the last one. . Saying, moderators save Jia
Reply:
I advise you a ah, you are now the best way is to rewrite the server-side code string into the receiver, and then cast. ksoap ills, can not transmit double type, those who know, please tell me, I want to know for a long time, and once I program encountered this situation, we must do a lot of trouble.
Reply:
I advise you a ah, you are now the best way is to rewrite the server-side code string into the receiver, and then cast. ksoap ills, can not transmit double type, those who know, please tell me, I want to know for a long time, and once I program encountered this situation, we must do a lot of trouble.
Reply:
Thank you, I'll try that too pulled. .
Reply:
The reply was deleted at the moderator 2012-04-16 16:44:00

Reply:
Too thank the 3rd floor, the problem is solved
Reply:
Why do I call transport.call () always being given it
Reply:
No problem with java main function test, put android Underneath there is a problem
Reply:
Code does
Reply:
reference to the 7th floor a175059525 reply:
too thank the 3rd floor, the problem is solved
ask how to solve? Seeking to share, I have encountered this problem
Reply:
I'm not the type of transmission line LIST, the landlord how to solve

NDK using dynamic library (shared library problem)


posts by Thomas082 edited 2012-03-20 23:47:15
(1) to generate dynamic library

Build a file folder named JNI, after which add two documents, namely add.c and Android.mk,
shown below
add.c
 # include  

int add (int a, int b)
{
return a + b;
}


Android.mk
 LOCAL_PATH: = $ (call my-dir) 

include $ (CLEAR_VARS)

LOCAL_MODULE: = add
LOCAL_SRC_FILES: = add.c

include $ (BUILD_SHARED_LIBRARY)


After ndk-build, got libadd.so


(2) modify the hello-jni project

is as follows
hello-jni comes Lie, I tried to return the string before calling about the dynamic library add (int, int) method, the modified
hello-jni.c
 # include  
# Include
# Include
# Include

jstring
Java_com_example_hellojni_HelloJni_stringFromJNI (JNIEnv * env,
jobject thiz)
{
add (1, 2);
return (* env) -> NewStringUTF (env, "Hello from JNI!");
}


Android.mk
 LOCAL_PATH: = $ (call my-dir) 

include $ (CLEAR_VARS)

LOCAL_MODULE: = add
LOCAL_SRC_FILES: = libadd.so
LOCAL_EXPORT_C_INCLUDES: = $ (LOCAL_PATH) / include

include $ (PREBUILT_SHARED_LIBRARY)

include $ (CLEAR_VARS)

LOCAL_MODULE: = hello-jni
LOCAL_SRC_FILES: = hello-jni.c
LOCAL_SHARED_LIBRARIES: = add

include $ (BUILD_SHARED_LIBRARY)


Yes, I'm still include files add a simple add.h
 int add (int a, int b) 


Of course, I also added a JNI directory libadd.so

Finally, I would certainly use the NDK 7 compiled through, and \ hello-jni \ libs \ armeabi have two libraries libadd.so and libhello-jni.so
Library libadd.so, is automatically in the past, not the past
I manually copy copy
Originally feel that this should be no problem under the bar, but throw an error:
03-20 23:17:30.434: D / dalvikvm (192): Trying to load lib / data / data / com.example.hellojni / lib / libhello-jni.so 0x43757ca8
03-20 23:17:30.474: I / dalvikvm (192): Unable to dlopen (/ data / data / com.example.hellojni / lib / libhello-jni.so): Cannot load library: link_image [1638]: 30 could not load needed library 'libadd.so' for 'libhello-jni.so' (load_library [984]: Library 'libadd.so' not found) < br />

I do not understand why? We have encountered this problem? How to solve it?

<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
LOCAL_SHARED_LIBRARIES: =-ladd plus-l
Reply:


LOCAL_SHARED_LIBRARIES: = add this right

Reply:
To add System.loadLibrary ("add");
Reply:
Later I ask is how to solve it? I also encountered the same problem, please enlighten me ~ Thank you
Reply:
Thomas082 answer right, to System.loadLibrary ("add");
Reply:
The landlord Hello, may I ask "
you mentioned in the articleYes, I'm still include files add a simple add.h "
This include file is where what is meant? ? ? ?

Consult the android on View: onClick problem


In the following add android: onClick always wrong
 android: id = "@ + id / txtsex" 
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: ems = "10"
android: text = ""
android: onClick = "setSex" />

Error message:
 
java.lang.NullPointerException
at android.widget.AutoCompleteTextView $ PassThroughClickListener.access $ 302
at android.widget.AutoCompleteTextView.setOnClickListener
at android.view.View.
at android.widget.TextView.
at android.widget.EditText.
at android.widget.AutoCompleteTextView.
at android.widget.AutoCompleteTextView.
at java.lang.reflect.Constructor.newInstance
at android.view.LayoutInflater.createView
at android.view.LayoutInflater.onCreateView
at android.view.LayoutInflater.createViewFromTag
at android.view.LayoutInflater.rInflate_Original
at android.view.LayoutInflater_Delegate.rInflate
at android.view.LayoutInflater.rInflate
at android.view.LayoutInflater.rInflate_Original
at android.view.LayoutInflater_Delegate.rInflate
at android.view.LayoutInflater.rInflate
at android.view.LayoutInflater.rInflate_Original
at android.view.LayoutInflater_Delegate.rInflate
at android.view.LayoutInflater.rInflate
at android.view.LayoutInflater.inflate
at android.view.LayoutInflater.inflate

Function
corresponding java page
 public void setSex (View view) 
{
final EditText txtsex = (EditText) this.findViewById (R.id.txtsex);
String [] strSex = getResources () getStringArray (R.array.sex);.
AlertDialog.Builder builder;
builder = new AlertDialog.Builder (this);
builder.setTitle ("sex selection");
builder.setCancelable (false);
builder.setSingleChoiceItems (strSex, 0, new DialogInterface.OnClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which) {
/ / TODO Auto-generated method stub
index = which;
}
});
builder.setPositiveButton (R.string.confirm, new DialogInterface.OnClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which) {
/ / TODO Auto-generated method stub
txtsex.setText (getResources () getStringArray (R.array.sex) [index].);
}
});
builder.setNegativeButton (R.string.cancel, new DialogInterface.OnClickListener () {

@ Override
public void onClick (DialogInterface dialog, int which) {
/ / TODO Auto-generated method stub
txtsex.setText ("");
}
});
builder.create () show ();.
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
xml defined android: onClick will report this error, the code will not be registered, is a bit strange.
Your registration code in it.
Reply:
cited a floor tantahe reply:
xml defined android: onClick will report this error, the code will not be registered, is a bit strange.
Your registration code in it.
Where do? Please enlighten me!
Reply:
The android: onClick = "setSex" remove the onCreate method in activity rearmost plus
 ((AutoCompleteTextView) findViewById (R.id.txtsex)) setOnClickListener (new OnClickListener () {. 

@ Override
public void onClick (View v) {
setSex (v);
}
});

Reply:
reference to the third floor tantahe reply:
the android: onClick = "setSex" removed, the activity's onCreate method rearmost plus
 ((AutoCompleteTextView) findViewById (R.id.txtsex)) setOnClickListener (new OnClickListener () {

@ Override
public void onClick (View v) {
setSex (v);
}
});


Yo West, I try
Reply:
Seemingly defined in xml android: onClick only for the Button class (including subclasses), otherwise an error, the best landlord is registered onClick event in code, 3rd Floor, positive solution!
Reply:
references, 5th Floor ncepu307 reply:
seemingly defined in xml android: onClick only for the Button class (including its sub-class), otherwise it will error, The best landlord is registered onClick event in code, 3rd Floor, positive solution!

button and other controls or a little different, I had to add Button in GridView in each sub-View, click the event turned out to be useful for wood
Reply:
cited a floor tantahe reply:
xml defined android: onClick will report this error, the code will not be registered, is a bit strange.
Your registration code in it.
Well, it. Another question, do you have used Android-studio, why compiled program which characters will be garbled ah
Reply:
reference to the 7th floor leyo6yilin reply:
Quote: references to a floor tantahe reply:

xml defined android: onClick will report this error, the code will not be registered, is a bit strange.
Your registration code in it.
Well, it. Another question, do you have used Android-studio, why compiled program which characters will be garbled ah

Never used, I have been using eclipse
Reply:
reference to the 8th floor tantahe reply:
Quote: references to the 7th floor leyo6yilin reply:

Quote: references to a floor tantahe reply:

xml defined android: onClick will report this error, the code will not be registered, is a bit strange.
Your registration code in it.
Well, it. Another question, do you have used Android-studio, why compiled program which characters will be garbled ah

Never used, I have been using eclipse
ah! ! ! Well, finally, all in English, not to force ah (although the finished package, but I do not have to exercise their own). . . . . . . . . . . . . . . . . . . . . Recommend you use this software, Google themselves than Eclipse smooth
Reply:
reference to the 7th floor leyo6yilin reply:
Quote: references to a floor tantahe reply:

xml defined android: onClick will report this error, the code will not be registered, is a bit strange.
Your registration code in it.
Well, it. Another question, do you have used Android-studio, why compiled program which characters will be garbled ah

Never used, Google introduced the IDE did not take long, according to some feedback and some bug, need to be improved. I am from eclipse to Intellij IDEA, I feel stronger than Eclipse, easy to use and more, stdio Based on this, and the idea to support Chinese encoding, and it's smart tips, integrated version control is very powerful, it is recommended to use the landlord!

About dp help ......


Google allows use dp units instead of px for display icons or. Png file when that design icon to submit it? Or what other format? Or to be divided into ldpi, mdpi, hdpi and xhdpi it? Or submit only one file can be? ,,, Do not understand, seek guidance <-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
The unit is dp or px, there is no relationship with the pictures, images or use png, it is best to prepare dpi different different picture, so you can get the best display, and in the absence of scaling, displayed image size you put the folder with the picture size is the same. If in order to save space, try to use a little high-resolution pictures, so reduce the display without distortion.
ldpi = 120dpi, mdpi = 160dpi, hdpi = 240dpi, xhdpi = 320dpi.
The formula sized pictures in other dpi display is: target dpi / Original dpi × original size
Assuming you have only one picture, put xhdpi directory, image size is 100 × 200:
Is reduced in a ldpi under: 120/320 = 0.375 times, i.e., 38 × 75
In mdpi is reduced to: 160/320 = 0.5 times, i.e., 50 × 100
In hdpi is reduced to: 240/320 = 0.75 times, i.e., 75 × 150
Assuming you have only one picture on ldpi directory, image size is 100 × 200:
Is amplified in a lower mdpi: 160/120 = 1.33 times, i.e., 133 × 267
Is amplified in a lower hdpi: 240/120 = 2 times, i.e., 200 × 400
In xhdpi is magnified under a: 320/120 = 2.67 times, ie 267 × 533


Reply:
cited landlord maxuan_530 reply:
Google or png file so that when you use dp instead of px display icons for units that design icon you want to submit. ? Or what other format? Or to be divided into ldpi, mdpi, hdpi and xhdpi it? Or submit only one file can be? ,,, Do not understand, seek guidance

Sorry, did not quite understand, that to do with with the previous unit provides designers with px for style icons What difference does it? Or for a change in the common dp is the code for the icon design personnel did not change, or 36 x 36 px 48 x 48 px 72 x 72 px? Trouble. . .
Reply:
cited a floor tantahe reply:
unit is dp or px, there is no relationship with the pictures, images or use png, preferably by dpi, Different prepare different pictures, so you can get the best display, and in the absence of scaling, the image size is displayed with the folder you put the picture size is the same. If in order to save space, try to use a little high-resolution pictures, so reduce the display without distortion.
ldpi = 120dpi, mdpi = 160dpi, hdpi = 240dpi, xhdpi = 320dpi.
The formula sized pictures in other dpi display is: target dpi / Original dpi × original size
Assuming you have only one picture, put xhdpi directory, image size is 100 × 200:
Is reduced in a ldpi under: 120/320 = 0.375 times, i.e., 38 × 75
In mdpi is reduced to: 160/320 = 0.5 times, i.e., 50 × 100
In hdpi is reduced to: 240/320 = 0.75 times, i.e., 75 × 150
Assuming you have only one picture on ldpi directory, image size is 100 × 200:
Is amplified in a lower mdpi: 160/120 = 1.33 times, i.e., 133 × 267
Is amplified in a lower hdpi: 240/120 = 2 times, i.e., 200 × 400
In xhdpi is magnified under a: 320/120 = 2.67 times, ie 267 × 533

Sorry, did not quite understand, that to do with with the previous unit provides designers with px for style icons What difference does it? Or for a change in the common dp is the code for the icon design personnel did not change, or 36 x 36 px 48 x 48 px 72 x 72 px? Trouble. . .
Reply:
Landlord, "Google allows use dp instead of px units to display the icon for" this sentence would like to express is the height and width in xml configuration picture displayed, for example:
android: layout_width = "100dp"
android: layout_height = "100dp"
Or px, meaning that this control to display images in the width and height of dp, then 1dp converted into px, for example, for hdpi screens, 1dp generally equal 1.5px, for xhdpi, 1dp = 2px (screen pixel density of 2) .
When the icon design is based. Png format or 9.png stored in drawable, drawable-mdpi, drawable-hdpi and other directories, is designed to adapt to different screen sizes, for example, with an application installed on mdpi, hdpi, xhdpi resolution on a different screen phone, it will read to each icon resource mdpi, hdpi, xhdpi directory, you can do so include more phones, of course, if you just put the picture hdpi directory, then all resolutions mobile phones are likely to only use images hdpi directory, this will result in differences on display, either feeling magnified or reduced sensation.
Therefore, third-party applications will generally consider drawable, drawable-mdpi, drawable-hdpi, drawable-xhdpi different pixel sizes, such as directory decentralization with an icon resource (. Png or .9. Png), to accommodate different resolutions of the market phone.
Do not know that the landlord did not understand?
Reply:
dp good, px good, is used in the code, with your real picture size does not matter. Dp units can be used to do to improve application compatibility for different dpi devices, reducing the workload.
dp for a universal code after the change is for the icon design personnel did not change, or 36 x 36 px 48 x 48 px 72 x 72 px? almost mean.

I said that section, meaning that if you have a map, but placed under a certain dpi directory, then on other devices dpi, images are automatically scaled to display out of the picture size is not the same with the original. If you have various dpi directory under this picture, then on different dpi devices, the size of the picture displayed with your original images are the same, will not go zoom.
On different dpi devices, 1dp corresponding px is not the same, the formula is: dips = (pixs * 160) / densityDpi
Reply:
Also, the landlord said: 36 x 36 px 48 x 48 px 72 x 72 px icon resources in three resolutions on different dpi phones, for example, were placed mdpi, hdpi, xhdpi, because xhdpi relative in mdpi, the same size screen size (note the screen size) the need for greater pixel image to display the same size, or else such as 36 X 36 px mdpi this picture on the screen may be relatively normal, but put On xhdpi screen is very small, and this is why.

Reply:
Understand it ~ ~ Thanks meow ~

reference to the 6th floor ncepu307 reply:
Also, the landlord said: 36 x 36 px 48 x 48 px 72 x 72 px three resolution of icon resource is on a different dpi phones, for example, were placed mdpi, hdpi, xhdpi, because xhdpi relative mdpi, the same size as the screen size (note the screen size) require larger pixels in order to display the same image sizes, such as 36 X 36 px otherwise this picture on mdpi screen may be more normal, but put on xhdpi screen is very small, and this is why.

Reply:
reference to the 6th floor ncepu307 reply:
Also, the landlord said: 36 x 36 px 48 x 48 px 72 x 72 px three resolution of icon resource is on a different dpi phones, for example, were placed mdpi, hdpi, xhdpi, because xhdpi relative mdpi, the same size as the screen size (note the screen size) require larger pixels in order to display the same image sizes, such as 36 X 36 px otherwise this picture on mdpi screen may be more normal, but put on xhdpi screen is very small, and this is why.


Huh! Understand it meow ~ ~ ~ Thanks