顯示具有 solution 標籤的文章。 顯示所有文章
顯示具有 solution 標籤的文章。 顯示所有文章

2016年4月22日 星期五

[C++] Visual Studio 遇到ATL Com Crash的問題(解決方案)

在做IMAPI的東西的時候,需要用到CoCOM的東西,

然後他又需要使用ATL....總之很麻煩0rz


好了,重點就是在trace bug的時候跑到atlcom.h這個檔案裡面的

class CComObjectCached : public Base
{
public:
typedef Base _BaseClass;
CComObjectCached(void* = NULL){}
// Set refcount to -(LONG_MAX/2) to protect destruction and
// also catch mismatched Release in debug builds
// This will be made virtual again for Beta 2
/*virtual*/ ~CComObjectCached()
{
m_dwRef = -(LONG_MAX/2);
FinalRelease();
#ifdef _ATL_DEBUG_INTERFACES
_AtlDebugInterfacesModule.DeleteNonAddRefThunk(_GetRawUnknown());
#endif
}
//If InternalAddRef or InternalRelease is undefined then your class
//doesn't derive from CComObjectRoot
STDMETHOD_(ULONG, AddRef)() throw()
{
ULONG l = InternalAddRef();
if (l == 2)
_pAtlModule->Lock();
return l;
}

沒錯,就是_pAtlModule->Lock();這邊,然後你發現他記憶體位址居然是0x000000

然後就crash了!


不要相信甚麼add ATL support to MFC 之類的鬼話(加了以後我不知道怎麼刪掉,只能重寫)

解決方法:

在你的主程式(.cpp)裡面,

#include .......

//在這邊新增
CComModule _Module;
extern __declspec(selectany) CAtlModule* _pAtlModule=&_Module;

//新增完成

主程式:建構子....

主程式.....

這樣就可以解決了

END

2015年5月26日 星期二

[iOS]NSString & EXC_BAD_ACCESS ERROR solution

問題:

使用全域變數NSString *string,使用時候出現exc_BAD_ACCESS???


答案:


@property (nonatomic,retain)NSString *string;

不可以使用assign 要使用retain!


解決!

end

2015年1月22日 星期四

[Android] "ClassNotFoundException" / " Binary XML file line # : Error inflating class” / " multiple dex files define"錯誤解決

在寫Android的時候會使用到別人所用的library,

常常會看到ClassNotFound or Binary XML line #數字 Error inflating class

他的意思就是說(如果我沒有會錯意的話)  :他找不到你import的那個library

為什麼呢?

可能性有幾種(我目前知道解決方式也只有兩種,所以就列出兩種)


1) 你沒有正確import Library


請確定這裡面有打勾了,而不是紅色的X (如果沒有正確import就remove掉重新import一次)



通常新建的專案都會有內建android-support-v4.jar 但是你library又有一份,所以就class not found

exception ,因為她不知道要用哪一個(應該是這樣吧?)

這個就簡單一點,把lib資料夾裡面的android-support-v4.jar 刪除就可以了!

當然會造成classnotfoundexception 跟 error inflating class可能原因有很多,只列舉我找到的解決

方式,紀錄一下 End



補充: multiple dex files define 也是有可能有重複的android-support-v4.jar(刪除即可)

2015年1月8日 星期四

[Android] 長按切換2個Activity-----intent.setClass錯誤排除-----onGestureListener監聽手勢


為了讓兩個activity能夠順利切換,花了一些時間研究,

當然中間也遇到一些問題,在這邊紀錄一下.


首先切換Activity是使用intent->startActivity()來做切換

觸發則是長按畫面任意地方


首先先看如何監聽手勢(gesture):

OnGestureListener listener = new OnGestureListener(){

@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
// TODO Auto-generated method stub
return false;
}

@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
       Intent intent = new Intent();
       intent.setClass(MainActivity.this, switch_target.class);
       startActivity(intent);
       overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
       MainActivity.this.finish();
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}

@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}};


別忘記要import 所需要的東西

import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;



動畫的部分,首先要在res/anim裡面新增兩個xml檔

第一個檔,檔名隨意設定
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/linear_interpolator"
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.7"
        android:toYScale="1.0"
        android:fillAfter="false"
        android:startOffset="200"
        android:duration="200" />
    <translate
        android:fromXDelta="50%"
        android:toXDelta="0"
        android:startOffset="200"
        android:duration="200"/>
</set>


第二個檔也是檔名隨意設定


有了動畫xml檔 + 手勢(觸發事件),我們還缺一樣東西,就是切換activity


       Intent intent = new Intent();
       intent.setClass(MainActivity.this, switch_target.class);
       startActivity(intent);
       overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
       MainActivity.this.finish();

切換Activity需要的就是intent,注意這邊

intent.setClass(MainActivity.this, switch_target.class);

是MainActivity.this, switch_target.class兩者是不一樣的,請不要搞錯了(搞錯他就會一直報錯)

 

The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments...............


這樣的錯誤訊息


另一端切換回來則是:

       Intent intent = new Intent();
       intent.setClass(switch_target.this,MainActivity.class);
       startActivity(intent);
       overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
       switch_target.this.finish();


當然為了避免還是有人看了以後還是出錯,這邊也附上source code 方便大家看

這次的教學就到此囉 End

2014年12月29日 星期一

[Android] No resource found that matches the given name '@style/Theme.AppCompat.Light' / 解決方法

剛開始安裝android / eclipse的時候通常都會遇到這個問題,

相信這個問題困擾許多人已久(包括我)...終於了解+找到解法以後把他寫起來以免下次又忘記!


首先,甚麼叫做IsLibrary?

這個選項打勾就代表說你把該專案當成library(所以不能亂勾,雖然勾了也沒太大影響(?))


Step1:
加入library(File->Import)



選擇sdk-extras-android-support-v7-appcompat資料夾,記得要勾選copy to workspace

Step2:

確認專案->右鍵Properties->anddroid(左側)->Library(isLibrary)是否勾選


Step3:

進到目標Project(就是有錯誤的那個project)

同樣也是properties->android->library->把錯誤的remove掉



add->剛剛新建立的android-support-v7-appcompat->OK (這邊請不要勾選is library)


Step4:

又發現錯誤!!



在builders這邊也有錯所以我們在Builders->Libraries->選擇錯誤的項目->edit->選圖片內的路徑

下面這個也有錯,所以也修正過來

Step5:

完成! 看到style.xml這邊完全沒有錯誤了,project也是沒有驚嘆號出現


就是這樣!幾個步驟做完就可以囉!

如果還是無法記得要去SDK Manager下載新的extras(要按install)

END