若有一組電話字串,該如何比對其中幾個數(如308)
package com.example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sun.corba.se.spi.orbutil.fsm.Input;
public class StringPattern1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String inputString = "0911308380"; //原始字串
Pattern pattern = Pattern.compile("308"); //比對字串308
Matcher matcher = pattern.matcher(inputString); //要拿原始字串和比對字串做比較
if(matcher.find()){
System.out.println("got it");
}else{
System.out.println("no match");
}
}
}
參考Gossip
2012年4月26日 星期四
2012年4月25日 星期三
android Permission denied
今天好不容易解決了android project使用外部jar(clink210.jar)的問題,原因是在java build path裡的Order and Export,需將加入的外部jar打勾,預設是沒有勾選的。
但實作上發現,upnp control point並沒有啟動
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tView = (TextView)findViewById(R.id.resultTV);
ControlPoint cPoint = new ControlPoint();
tView.append(String.valueOf(cPoint.start())); --> false,表示沒有start( )成功
tView.append(String.valueOf(cPoint.stop())); --> true
於是使用logcat查看,其中CyberGarage被permission denied
04-26 10:57:03.010: I/System.out(12701): CyberGarage warning : Permission denied
04-26 10:57:03.010: I/System.out(12701): java.net.SocketException: Permission denied
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getAllInterfaceAddressesImpl(Native Method)
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getNetworkInterfacesImpl(NetworkInterface.java:62)
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getNetworkInterfacesList(NetworkInterface.java:241)
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getNetworkInterfaces(NetworkInterface.java:237)
谷歌的結果,是說因CyberGarage會使用到internet服務,需將internet service打開。
在AndroidManifest.xml裡,將權限加入即可,如下:
參考
但實作上發現,upnp control point並沒有啟動
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tView = (TextView)findViewById(R.id.resultTV);
ControlPoint cPoint = new ControlPoint();
tView.append(String.valueOf(cPoint.start())); --> false,表示沒有start( )成功
tView.append(String.valueOf(cPoint.stop())); --> true
於是使用logcat查看,其中CyberGarage被permission denied
04-26 10:57:03.010: I/System.out(12701): CyberGarage warning : Permission denied
04-26 10:57:03.010: I/System.out(12701): java.net.SocketException: Permission denied
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getAllInterfaceAddressesImpl(Native Method)
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getNetworkInterfacesImpl(NetworkInterface.java:62)
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getNetworkInterfacesList(NetworkInterface.java:241)
04-26 10:57:03.010: I/System.out(12701): at java.net.NetworkInterface.getNetworkInterfaces(NetworkInterface.java:237)
谷歌的結果,是說因CyberGarage會使用到internet服務,需將internet service打開。
在AndroidManifest.xml裡,將權限加入即可,如下:
Ann's雜誌
android的apk該如解壓縮
今日將cyberlink的clink210.jar丟到android project去跑時,出現錯誤如下
04-25 17:15:50.130: W/dalvikvm(8918): threadid=1: thread exiting with uncaught exception (group=0x40275578)
04-25 17:15:50.130: E/AndroidRuntime(8918): FATAL EXCEPTION: main
04-25 17:15:50.130: E/AndroidRuntime(8918): java.lang.IllegalStateException: Could not execute method of the activity
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View$1.onClick(View.java:2178)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View.performClick(View.java:2574)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View$PerformClick.run(View.java:9223)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.os.Handler.handleCallback(Handler.java:587)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.os.Looper.loop(Looper.java:130)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.app.ActivityThread.main(ActivityThread.java:3691)
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 17:15:50.130: E/AndroidRuntime(8918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-25 17:15:50.130: E/AndroidRuntime(8918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-25 17:15:50.130: E/AndroidRuntime(8918): at dalvik.system.NativeStart.main(Native Method)
04-25 17:15:50.130: E/AndroidRuntime(8918): Caused by: java.lang.reflect.InvocationTargetException
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View$1.onClick(View.java:2173)
04-25 17:15:50.130: E/AndroidRuntime(8918): ... 11 more
04-25 17:15:50.130: E/AndroidRuntime(8918): Caused by: java.lang.NoClassDefFoundError: org.cybergarage.upnp.ControlPoint
04-25 17:15:50.130: E/AndroidRuntime(8918): at com.android.example.UpnpOnAndroidActivity.searchOnClick(UpnpOnAndroidActivity.java:30)
04-25 17:15:50.130: E/AndroidRuntime(8918): ... 14 more
04-25 17:15:52.140: I/dalvikvm(8918): threadid=4: reacting to signal 3
04-25 17:15:52.140: I/dalvikvm(8918): Wrote stack traces to '/data/anr/traces.txt'
好像是找不到clink.jar裡的org.cybergarage.upnp.ControlPoint?上google查了一些資料(1,2),也試過該如何import clink210.jar才是正確,但到目前為止都是相同錯訊息。於是就想去看看輸出的apk是否有將clink210.jar包進去?
解apk的步驟如下:
1.下載apktool.jar & apktool-install-windows
2.解壓縮apktool-install-windows至任意資料匣,apktool.jar也放在裡頭
3.apktool d xxx.apk output
解apk的結果,看到下列目錄
-res
-smali
AndroidManifest.xml
apktool.yml
找了一下,並無我想看到的,是否clink210.jar有包在裡頭。
04-25 17:15:50.130: W/dalvikvm(8918): threadid=1: thread exiting with uncaught exception (group=0x40275578)
04-25 17:15:50.130: E/AndroidRuntime(8918): FATAL EXCEPTION: main
04-25 17:15:50.130: E/AndroidRuntime(8918): java.lang.IllegalStateException: Could not execute method of the activity
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View$1.onClick(View.java:2178)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View.performClick(View.java:2574)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View$PerformClick.run(View.java:9223)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.os.Handler.handleCallback(Handler.java:587)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.os.Looper.loop(Looper.java:130)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.app.ActivityThread.main(ActivityThread.java:3691)
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 17:15:50.130: E/AndroidRuntime(8918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
04-25 17:15:50.130: E/AndroidRuntime(8918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
04-25 17:15:50.130: E/AndroidRuntime(8918): at dalvik.system.NativeStart.main(Native Method)
04-25 17:15:50.130: E/AndroidRuntime(8918): Caused by: java.lang.reflect.InvocationTargetException
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 17:15:50.130: E/AndroidRuntime(8918): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 17:15:50.130: E/AndroidRuntime(8918): at android.view.View$1.onClick(View.java:2173)
04-25 17:15:50.130: E/AndroidRuntime(8918): ... 11 more
04-25 17:15:50.130: E/AndroidRuntime(8918): Caused by: java.lang.NoClassDefFoundError: org.cybergarage.upnp.ControlPoint
04-25 17:15:50.130: E/AndroidRuntime(8918): at com.android.example.UpnpOnAndroidActivity.searchOnClick(UpnpOnAndroidActivity.java:30)
04-25 17:15:50.130: E/AndroidRuntime(8918): ... 14 more
04-25 17:15:52.140: I/dalvikvm(8918): threadid=4: reacting to signal 3
04-25 17:15:52.140: I/dalvikvm(8918): Wrote stack traces to '/data/anr/traces.txt'
好像是找不到clink.jar裡的org.cybergarage.upnp.ControlPoint?上google查了一些資料(1,2),也試過該如何import clink210.jar才是正確,但到目前為止都是相同錯訊息。於是就想去看看輸出的apk是否有將clink210.jar包進去?
解apk的步驟如下:
1.下載apktool.jar & apktool-install-windows
2.解壓縮apktool-install-windows至任意資料匣,apktool.jar也放在裡頭
3.apktool d xxx.apk output
解apk的結果,看到下列目錄
-res
-smali
AndroidManifest.xml
apktool.yml
找了一下,並無我想看到的,是否clink210.jar有包在裡頭。
2012年4月23日 星期一
如何使用eclipse直接上android code於實體手機測試
1.確認eclipse的OS平台有無安裝手機的driver
2.確認adb(D:\eclipse\android sdk\platform-tools)有無在環境變數下
-adb主要用來除錯用
3.於eclipse android專案下,於AndroidManifest.xml的<activity ... > 加入android:debuggable="true"
[2012-04-24 14:08:48 - MyHelloWorld] Please execute 'adb uninstall com.example' in a shell.
[2012-04-24 14:08:48 - MyHelloWorld] Launch canceled!
照做,就成功囉!
參考
走不到的世界線
Tsung's blog
android developer
2.確認adb(D:\eclipse\android sdk\platform-tools)有無在環境變數下
-adb主要用來除錯用
3.於eclipse android專案下,於AndroidManifest.xml的<activity ... > 加入android:debuggable="true"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...略
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MyHelloWorldActivity"
android:label="@string/app_name"
android:debuggable="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
...略
</manifest>
4.手機上,將設定 → 應用程式 → 開發 → USB 除錯 打勾
理論上,執行完這4個步驟就可以了。但我在執行時,還遇到eclipse跳出error
[2012-04-24 14:08:48 - MyHelloWorld] Please execute 'adb uninstall com.example' in a shell.
[2012-04-24 14:08:48 - MyHelloWorld] Launch canceled!
照做,就成功囉!
參考
走不到的世界線
Tsung's blog
android developer
訂閱:
意見 (Atom)
