public class UploadToServer extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_to_server);
uploadButton = (Button)findViewById(R.id.uploadButton);
messageText = (TextView)findViewById(R.id.messageText);
up= new Upload(this);
uploadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true);
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("uploading started.....");
}
});
up.uploadFile(uploadFilePath);
}
}).start();
}
});
我需要从另一个名为 UPLOAD.ineed 的类访问此类 ui,以访问上述类中的对话框并显示 toast。我该怎么做。请帮帮我
public class Upload {
public Upload(UploadToServer context) {
context=context;}
context.runOnUiThread(new Runnable() {public void run() {
String msg = "yes";
context.messageText.setText(msg);
Toast.makeText(context, "File Upload Complete.",
Toast.LENGTH_SHORT).show();
}
}); }
这就是我尝试过的。没关系。我想做的就是打印一个 Toast。但是当我真的这样做时,我得到了 NULPOINT 异常