我是Android / Java开发的新手,我遇到了这个错误。经过广泛的研究和玩我的方法后,我无法弄清楚出了什么问题。这是我的代码:
package org.flinthill.finalprojectv2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.text.method.DigitsKeyListener;
import android.text.InputFilter;
public class mainactivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
final Button SuSe = (Button) findViewById(R.id.SuSe);
SuSe.setOnClickListener()
{
new View.OnClickListener() {
@Override
public void onClick(View view){
}
};
}
}
如果有人知道我做错了什么,请告诉我!谢谢!
答案 0 :(得分:1)
将代码放入旁边<p:commandButton ajax="false" value="Descargar CSV"
icon="fa fa-arrow-circle-down"
actionListener="#{biblioF2.setBanderaDescarga(true)}">
<p:dataExporter type="csv" target="tablaDatos" fileName="libros" />
</p:commandButton>
<h:panelGroup id="btnsFGC">
....
</h:panelGroup>
onCreate()
答案 1 :(得分:0)
您的代码不在您的方法中,请将其更改为:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button SuSe = (Button) findViewById(R.id.SuSe);
SuSe.setOnClickListener()
{
new View.OnClickListener() {
@Override
public void onClick(View view){
}
};
}
}
答案 2 :(得分:0)
将您的代码放在 onCreate()方法
中请参阅android lifeCycle以了解原因:https://developer.android.com/guide/components/activities/activity-lifecycle.html
答案 3 :(得分:0)
执行Button
初始化并在listener
方法中将Button
添加到onCreate()
。
试试这个:
package org.flinthill.finalprojectv2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;
import android.text.method.DigitsKeyListener;
import android.text.InputFilter;
public class mainactivity extends AppCompatActivity {
Button SuSe;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SuSe = (Button) findViewById(R.id.SuSe);
SuSe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Do something
}
});
}
}