From 408a441f31644ce300691e4e1058dda9cc934b7f Mon Sep 17 00:00:00 2001 From: yehun Date: Fri, 24 Oct 2025 23:49:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8A=A5=E9=94=99mismatched=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/app.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/app.rs b/src/android/app.rs index e3c518b..7d41fd6 100644 --- a/src/android/app.rs +++ b/src/android/app.rs @@ -265,8 +265,9 @@ pub fn test() { let act2 = act.clone(); let runnable = RunnableImpl::from_fn(move || { act2.set_content_view(&edit); + Ok(()) }) - .unwrap(); + 。unwrap(); act.run_on_ui_thread(runnable.as_ref()); let wm: WindowManagerImpl = act.get_window_manager(); assert!(wm.to_string().starts_with("android.view.WindowManagerImpl")); From f520308bf01647636edaf1621bf6e7ab2a378470 Mon Sep 17 00:00:00 2001 From: yehun Date: Fri, 24 Oct 2025 23:59:49 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCI=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/app.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/android/app.rs b/src/android/app.rs index 7d41fd6..287f6ba 100644 --- a/src/android/app.rs +++ b/src/android/app.rs @@ -266,8 +266,7 @@ pub fn test() { let runnable = RunnableImpl::from_fn(move || { act2.set_content_view(&edit); Ok(()) - }) - 。unwrap(); + }).unwrap(); act.run_on_ui_thread(runnable.as_ref()); let wm: WindowManagerImpl = act.get_window_manager(); assert!(wm.to_string().starts_with("android.view.WindowManagerImpl")); From c7f7b85040a77745023948834800a00f1d0ce7c5 Mon Sep 17 00:00:00 2001 From: yehun Date: Sat, 25 Oct 2025 00:08:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=BAString=E7=B1=BB=E5=9E=8B=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E5=BF=85=E8=A6=81=E7=9A=84=20trait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/utils/src/lib.rs b/utils/src/lib.rs index fef20ed..4b330e0 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -284,6 +284,35 @@ macro_rules! impl_array { const OBJECT_SIG: &'static str = ::OBJECT_SIG; const DIM: u8 = $dim; } + + // 为 String 类型实现必要的 trait + impl JType for String { + const CLASS: &'static str = "java/lang/String"; + const OBJECT_SIG: &'static str = "Ljava/lang/String;"; + } + + impl JObjRef for String { + fn java_ref(&self) -> Result { + let mut env = vm_attach()?; + let jstring = env.new_string(self)?; + Ok(env.new_global_ref(&jstring)?) + } + } + + impl JObjNew for String { + type Fields = (); + + fn _new(this: &GlobalRef, _fields: Self::Fields) -> Result { + if this.is_null() { + return Ok(String::new()); + } + + let mut env = vm_attach()?; + let jstring = this.as_obj(); + let java_string = env.get_string(jstring.into())?; + Ok(java_string.to_str()?.to_string()) + } + } }; (u8, $dim:expr) => { From 9e55b7aba106b4d19e878211e8da3acd0f5e0805 Mon Sep 17 00:00:00 2001 From: yehun Date: Sat, 25 Oct 2025 00:27:39 +0800 Subject: [PATCH 4/4] =?UTF-8?q?String=E7=9A=84=E5=AE=9E=E7=8E=B0=E8=BD=AC?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=E5=9C=A8utils/lib.rs=20->=20impl=5Farray!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commented out the implementation of JObjRef, JObjNew, and JType traits for String. --- src/java/lang.rs | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/java/lang.rs b/src/java/lang.rs index 39b20f8..0584906 100644 --- a/src/java/lang.rs +++ b/src/java/lang.rs @@ -58,41 +58,41 @@ impl ObjectExt for Object { } } -impl JObjRef for String { - fn java_ref(&self) -> Result { - let mut env = vm_attach()?; - if self.is_empty() { - return null_value(&mut env); - } - - let s = env.new_string(self.as_str())?; - Ok(env.new_global_ref(&s)?) - } -} - -impl JObjNew for String { - type Fields = (); - - fn _new(this: &GlobalRef, _: Self::Fields) -> Result { - let mut env = vm_attach()?; - let s = env.get_string(this.as_obj().into())?; - Ok(s.to_str()?.to_string()) - } - - fn null() -> Result - where - Self: Sized, - Self::Fields: Default, - { - Ok(Default::default()) - } -} - -impl JType for String { - const CLASS: &'static str = "java/lang/String"; - //noinspection SpellCheckingInspection - const OBJECT_SIG: &'static str = "Ljava/lang/String;"; -} +// impl JObjRef for String { +// fn java_ref(&self) -> Result { +// let mut env = vm_attach()?; +// if self.is_empty() { +// return null_value(&mut env); +// } +// +// let s = env.new_string(self.as_str())?; +// Ok(env.new_global_ref(&s)?) +// } +// } +// +// impl JObjNew for String { +// type Fields = (); +// +// fn _new(this: &GlobalRef, _: Self::Fields) -> Result { +// let mut env = vm_attach()?; +// let s = env.get_string(this.as_obj().into())?; +// Ok(s.to_str()?.to_string()) +// } +// +// fn null() -> Result +// where +// Self: Sized, +// Self::Fields: Default, +// { +// Ok(Default::default()) +// } +// } +// +// impl JType for String { +// const CLASS: &'static str = "java/lang/String"; +// //noinspection SpellCheckingInspection +// const OBJECT_SIG: &'static str = "Ljava/lang/String;"; +// } /** Boolean 类将原始类型布尔值包装在对象中。布尔类型的对象包含一个类型为布尔的字段。此外,此类还提供了许多将布尔值转换为字符串和将字符串转换为布尔值的方法,以及处理布尔值时有用的其他常量和方法。