我想创建一个方形单选按钮,按钮内有文本。那可能吗?我认为可以通过 css 更改按钮形状,但是文本呢?
任何提示?
出于某种原因,每次尝试启动我的应用程序时,我都会出现以下错误:
Unable to instantiate activity ComponentInfo{com.example.lifeahead/com.example.lifeahead.MainActivity}:java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
我检查了清单文件,并添加了所有活动.
我启动应用程序时使用的唯一方法是:
private void logIn(){
Button logIn = (Button) findViewById(R.id.login);
logIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent loginIntent = new Intent(MainActivity.this, HomeActivity.class);
loginIntent.putExtra("cmUN", cmUN);
loginIntent.putExtra("cmPW", cmPW);
startActivity(loginIntent);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是onCreate:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
logIn();
}
Run Code Online (Sandbox Code Playgroud)
完整日志:
Ë
/AndroidRuntime(1607): FATAL EXCEPTION: main
E/AndroidRuntime(1607): Process: com.example.lifeahead, PID: 1607
E/AndroidRuntime(1607): java.lang.RuntimeException: Unable to instantiate …Run Code Online (Sandbox Code Playgroud) 我在下面有一个xml字符串,其中包含html标签,如Bold和超链接href.
<string name"example"><b>%1$s</b> has been added to your clipboard and is valid until <b>%2$s</b><a href="http://www.google.com">Please see our +T\'s and C\'s+ </a> </string>
Run Code Online (Sandbox Code Playgroud)
当我格式化字符串以动态添加一些值时,它会删除我定义的粗体文本和href.
代码如下:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yy");
Date date = new Date(text.getValidTo());
String text = String.format(getString(R.string_dialog_text), text.getCode(), simpleDateFormat.format(date), "£30");
Run Code Online (Sandbox Code Playgroud)
然后我将其应用于警报对话框
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setNeutralButton(R.string.ok, onClickListener);
builder.setTitle(title);
builder.setMessage(text);
Run Code Online (Sandbox Code Playgroud)
如果我不格式化文本并直接使用字符串资源,这工作正常
我有以下情况:
QDate fixDate = QDate::fromString(QString("270912"), "ddMMyy");
Run Code Online (Sandbox Code Playgroud)
返回的那一年是1912.我不明白为什么以及如何得到正确的一年.
提前致谢
我是Java的新手,在尝试实现一个简单的游戏时遇到了一个问题.目前游戏的前提是,计时器用于添加汽车,并且还更频繁地更新汽车的运动.可以通过触摸选择汽车,并通过绘制它的路径来指示.更新功能将沿着路径移动汽车.
现在,游戏因IndexOutOfBoundsException而崩溃,我几乎可以肯定这是因为偶尔重新选择汽车时,会擦除当前路径,并允许绘制新路径.该路径存储为LinkedList,并在触摸汽车时清除.
我想如果路径是通过触摸事件清除的,而计时器线程正在更新汽车沿路径的移动,这就是错误发生的地方(两个线程访问这一个列表时也可能出现类似的其他问题.
我的问题,在Java中,处理这个问题的最佳方法是什么?是否存在我应该使用的特定类型的列表而不是LinkedList,或者是否存在c ++中的Mutex等对象,我可以在使用它时保护此列表?
我想将JSONObject传递给下面代码中else部分中的另一个活动,这样我就可以在其他活动中使用配置文件详细信息,
public void redirectToActivity(JSONObject result, JSONObject profile){
try {
String status = result.getString("status");
if (status.equals("204")) {
Intent intent = new Intent(this, ActivityMenu.class);
intent.putExtra("user", "email");
this.startActivity(intent);
}
else {
Intent intent = new Intent(this, RegisterActivity.class);
this.startActivity(intent);
//here I want to pass JSONObject profile to RegisterActivity
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 所以我试图在我的活动中膨胀布局,但我不断收到此错误"无法解决方法inflate(int)"
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View error = layoutInflater.inflate(R.layout.error_internet_connection);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
在我的应用程序中,我有几组变量属性和他们自己的代码.例如,有220个变量,它们将文本转换为数字:
P1 = Integer.parseInt(S1);
P2 = Integer.parseInt(S2);
...
P220 = Integer.parseInt(S220);
Run Code Online (Sandbox Code Playgroud)
是否可以用一个或两个字符串编写此代码,而不是220?像这样:
Pn = Integer.parseInt(Sn),其中n - 数字在1和220范围内.
当我试图验证我的用户名和密码时,我收到一个错误,说找不到setError,请你帮忙找出我的错误.我在androidstudio1.2.2中执行了这个
package com.example.poornima.bookmyticket;
import com.example.poornima.bookmyticket.util.SystemUiHider;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*
* @see SystemUiHider
*/
public class login extends Activity implements View.OnClickListener {
private Button bLogin, bRegister;
private EditText eusername, epassword; …Run Code Online (Sandbox Code Playgroud) 我将此代码添加到我的build.gradle模块:android {}部分中的app.
buildTypes.each
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', "f4a8ad01f485a8276a6dbc4d364b"
}
Run Code Online (Sandbox Code Playgroud)
但它造成了错误
错误:(14,57)错误:找不到符号变量f4a8ad01f485a8276a6dbc4d364b
"..."内部未生成OPEN_WEATHER_API_KEY值
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID ="com.example.weatherforecast";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
// Fields from build type: debug
public static final String OPEN_WEATHER_MAP_API_KEY = f4a8ad01f485a8276a6dbc4d364b;
}
Run Code Online (Sandbox Code Playgroud)
在类FetchWeatherTask.java中,我有这行代码,并没有显示任何错误.
private final String APP_ID = BuildConfig.OPEN_WEATHER_MAP_API_KEY;
Run Code Online (Sandbox Code Playgroud)
为什么在BuildConfig.java …