字符串声明VariableDeclaratorId预计此令牌后

编程入门 行业动态 更新时间:2024-10-27 23:25:12
本文介绍了字符串声明VariableDeclaratorId预计此令牌后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在这个简单的code问题,我宣布一个String,想改变它里面的onCreate但此后的onCreate我有错误此令牌后VariableDeclaratorId预期!如果我把项目= 222里面的onCreate我得到111null333时,显示吐司这里是我的code

i have problem in this simple code, I declare a String , and want change it inside onCreate but AFTER onCreate i have "VariableDeclaratorId expected after this token" Error !! And if i put item=222 inside onCreate i get "111null333" when Toast display here is my code

public class MainActivity extends Activity { static String item; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toast.makeText(getApplicationContext(), mStrings[0], Toast.LENGTH_SHORT).show(); } item="222"; private String[] mStrings={ "111"+item+"333", "test" };

}

推荐答案

能否请你花一些时间,正确格式化你的问题?我没有看清楚,如果该项目=222;是一种方法里面还是不行。

Can you please spend some time and format your question correctly ? i do not see clearly if the item = "222"; is inside a method or not.

但是如果你的格式是正确,那么你的问题是,一个值项变量的分配不能在方法或code的静态{}块外完成。所以,如果你分配一个值之前,使用该项目的变量另一个对象或类变量这将是默认值(NULL对象和0或假的原始值)。

But if your formatting is "correct" then your problem is that the assignation of a value to the item variable can not be done outside of a method or the static{} block of code. And so if you use the item variable in another object or class variable before assigning it a value it will be the default value (null for objects and 0 or false for the primitive values).

希望这有助于。

更新:

public class MainActivity extends Activity { static String item; private String[] mStrings; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); item = "222"; mStrings = new String[2]; mStrings[0] = "111" + item + "333"; mStrings[1] = "test"; Toast.makeText(getApplicationContext(), mStrings[0], Toast.LENGTH_SHORT).show(); } }

更多推荐

字符串声明VariableDeclaratorId预计此令牌后

本文发布于:2023-10-29 22:45:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   字符串   声明   VariableDeclaratorId

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!