试图使用addHeaderView()和addFooterView()为ListView.如果我尝试使用我在XML中为页眉或页脚预定义的视图,我会得到一个空指针异常.但是,如果我使用代码动态创建一个视图,它工作正常......
// This doesn't work... nullPointerException
ListView lv = (ListView) findViewById(R.id.my_list_view);
TextView header = (TextView) findViewById(R.id.my_header);
lv.addHeaderView(header);
// This works fine
ListView lv = (ListView) findViewById(R.id.my_list_view);
TextView header = new TextView(this);
TextView.setHeight(30);
TextView.setText("my header text!");
lv.addHeaderView(header);
Run Code Online (Sandbox Code Playgroud)
我的堆栈跟踪:
Caused by: java.lang.NullPointerException
at android.widget.ListView.clearRecycledState(ListView.java:522)
at android.widget.ListView.resetList(ListView.java:508)
at android.widget.ListView.setAdapter(ListView.java:440)
at com.company.myapp.MyActivity.refreshList(MyActivity.java:85)
at com.company.myapp.MyActivity.onCreate(MyActivity.java:37)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Run Code Online (Sandbox Code Playgroud)
有线索吗?
我知道这this(...)用于从另一个构造函数调用一个类的构造函数.但我们可以使用new相同的吗?
为了更清楚这个问题,Line-2是否有效?如果是(因为编译器没有投诉),为什么输出null不是Hello?
class Test0 {
String name;
public Test0(String str) {
this.name= str;
}
public Test0() {
//this("Hello"); // Line-1
new Test0("Hello"){}; // Line-2
}
String getName(){
return name;
}
}
public class Test{
public static void main(String ags[]){
Test0 t = new Test0();
System.out.println(t.getName());
}
}
Run Code Online (Sandbox Code Playgroud) 当涉及到 Restful URI 上的尾部斜杠时,我可以引用权威立场吗?罗伊菲尔丁的一个会很棒。网络有两种方式的权威意见。这两个位置是: 尾部斜杠表示资源,而没有则没有。另一个论点是尾部斜杠没有语义价值。是哪个?例子:
@GetMapping(path = "/users/")
public List<User> getUsers() {
....
}
@GetMapping(path = "/users/{id}")
public User getUser(@PathVariable String type) {
.....
}
@PutMapping(path = "/users/")
public User updateUser(@RequestBody User user) {
....
}
@PostMapping(path = "/users/")
public User createUser(@RequestBody User user) {
....
}
@DeleteMapping(path = "/users/{id}")
public void deleteUser(@PathVariable Long id) {
....
}
Run Code Online (Sandbox Code Playgroud)
应该删除尾部斜杠吗?
我正试图通过我的.php页面向我的手机发送通知...一切都设置正确,但我收到错误:
{"multicast_id":7751536172966571167,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么因为发件人ID是对的,api也是(我已经尝试过服务器密钥和浏览器密钥,只是为了确定).
我真的不知道我哪里错了!
在我的应用程序中我只有发件人ID,所有都已经正确,在我的服务器中我已经获得了浏览器的密钥(现在):
<?php require_once("../pi_classes/commonSetting.php");
include('../pi_classes/User.php');
ini_set("display_errors",1);
class GCM{
function __construct(){}
public function send_notification($registatoin_ids,$message){
// GOOGLE API KEY
define("GOOGLE_API_KEY","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$url="https://android.googleapis.com/gcm/send";
$fields=array(
"registration_ids"=>$registatoin_ids,
"data"=>$message,
);
var_dump($fields);
$headers=array(
"Authorization: key=".GOOGLE_API_KEY,
"Content-Type: application/json"
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
$result=curl_exec($ch);
if($result===FALSE){
die("Curl failed: ".curl_error($ch));
}
curl_close($ch);
echo $result;
}
}
// ======================
//=INVIA LE NOTIFICHE AGLI UTENTI =
// ======================
$messaggio="Ciao, sono una notifica!";
$pushCounter=0;
$registatoin_ids=array();
$result=mysql_query("SELECT android_regi_id FROM user_details");
while($row=mysql_fetch_array($result)){
$token=$row["android_regi_id"];
if($token!=""){
$registatoin_ids[]=$token;
$pushCounter++;
}
}
if($pushCounter>0){
$gcm=new …Run Code Online (Sandbox Code Playgroud) // All required Imports
public class PuzzleActivity extends Activity implements OnClickListener{
private PuzzlerDB db;
private Puzzle puz;
private int puzId=1;
private String puzAns="";
private int score=0;
private TextView tvPuzContent;
private EditText etPuzAns;
private Button btnCheck;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_puzzle);
if ( customTitleSupported ) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
}
db = new PuzzlerDB(this);
puz = db.getPuzzle(puzId);
puzAns = puz.getAnswer();
tvPuzContent = (TextView) findViewById(R.id.tv_puz_content);
tvPuzContent.setText(puz.getContent());
btnCheck = (Button) findViewById(R.id.btn_check);
btnCheck.setOnClickListener(this);
android.util.Log.v("IN SIDE …Run Code Online (Sandbox Code Playgroud) 问题背景:
到目前为止,我是GitHub存储库的唯一所有者。我将代码从系统提交到了一个名为release的分支(实际上,如果需要的话,它是基于develop分支的标记)。在GitHub中,我创建了一个pull请求,其中base分支是master分支,而compare分支是release分支。
但是我只能对评论发表评论,而不能批准。可能是什么原因?
注意:没有合并冲突,并且在创建拉取请求时,显示可能合并的绿色信号。
这是master分支受我保护的方式:
我正在使用Canvas创建绘图应用程序的 android 类。这是我第一次尝试使用 Canvas 类。到目前为止,我使用的代码工作正常,绘图工作正常。但我在这段代码中意识到,它允许用户仅用一根手指进行绘画,我的意思是说,如果用户使用多于一根手指在画布上绘画,则不允许用户用多根手指进行绘画。我浏览了有关多个触摸事件的文档,但未能在我的代码中实现它。那么有人可以帮我解决这个问题吗?
我用于在画布上绘图的代码:
public class DrawView extends View implements OnTouchListener
{
private Canvas m_Canvas;
private Path m_Path;
private Paint m_Paint;
ArrayList<Pair<Path, Paint>> arrayListPaths = new ArrayList<Pair<Path, Paint>>();
ArrayList<Pair<Path, Paint>> undonePaths = new ArrayList<Pair<Path, Paint>>();
private float mX, mY;
private Bitmap bitmapToCanvas;
private static final float TOUCH_TOLERANCE = 4;
public DrawView(Context context)
{
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
onCanvasInitialization();
}
public void onCanvasInitialization()
{
m_Paint = new Paint();
m_Paint.setAntiAlias(true);
m_Paint.setDither(true);
m_Paint.setColor(Color.parseColor("#37A1D1"));
m_Paint.setStyle(Paint.Style.STROKE);
m_Paint.setStrokeJoin(Paint.Join.ROUND);
m_Paint.setStrokeCap(Paint.Cap.ROUND);
m_Paint.setStrokeWidth(2);
m_Path = …Run Code Online (Sandbox Code Playgroud) android ×4
constructor ×1
exception ×1
git ×1
github ×1
java ×1
listview ×1
mismatch ×1
multi-touch ×1
pull-request ×1
push ×1
rest ×1
restful-url ×1
sender-id ×1
settext ×1
textview ×1