Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to run an another class activity after toast message displayed?
    primarykey
    data
    text
    <pre><code> mainListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { String item = ((TextView)view).getText().toString(); Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show(); tcpSocket.SendMessage(FramePacket.FramesendMessageCmd(item)); } }); </code></pre> <p>herer is my code. i want to start another activity after click on the message item. i tried a lot. But not working. any one know help me please. how to solve this. I tried a lot. it give nullpointer exception error.</p> <p>catlog error here</p> <pre><code> 09-02 13:36:44.364: E/AndroidRuntime(28601): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dispatchsystem/com.dispatchsystem.JobStartedScreen}: java.lang.NullPointerException 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.ActivityThread.access$600(ActivityThread.java:127) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.os.Handler.dispatchMessage(Handler.java:99) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.os.Looper.loop(Looper.java:137) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.ActivityThread.main(ActivityThread.java:4448) 09-02 13:36:44.364: E/AndroidRuntime(28601): at java.lang.reflect.Method.invokeNative(Native Method) 09-02 13:36:44.364: E/AndroidRuntime(28601): at java.lang.reflect.Method.invoke(Method.java:511) 09-02 13:36:44.364: E/AndroidRuntime(28601): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 09-02 13:36:44.364: E/AndroidRuntime(28601): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 09-02 13:36:44.364: E/AndroidRuntime(28601): at dalvik.system.NativeStart.main(Native Method) 09-02 13:36:44.364: E/AndroidRuntime(28601): Caused by: java.lang.NullPointerException 09-02 13:36:44.364: E/AndroidRuntime(28601): at com.dispatchsystem.JobStartedScreen.onCreate(JobStartedScreen.java:65) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.Activity.performCreate(Activity.java:4465) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 09-02 13:36:44.364: E/AndroidRuntime(28601): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931) </code></pre> <p>jobstartedscreen</p> <pre><code> public class JobStartedScreen extends Activity implements OnMessageReceived{ TextView tv_JobNo; static TextView tv_JobKm; static TextView tv_JobwaitngTime; TextView tvjobstartedtime; Button btn_jobFinsh; Button btn_msg; boolean _ThreadFlag=false; boolean _ResumeThread=false; private Window w; Thread t=null; String tag="Jobstartscreen"; private static MyThread sThread; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.jobstartedscreen); if (savedInstanceState==null){ Contsants.VehicleStartOdometer=0.0F; sThread=new MyThread(mHandler); sThread.start(); } StateManager.DeviceStatus=StateManager.hired; tcpSocket.setmMessageListener(this); tv_JobNo =(TextView)findViewById(R.id.tvJobid); Bundle bundle = getIntent().getExtras(); tv_JobNo.setText(bundle.get("Jobno").toString()); tv_JobKm =(TextView)findViewById(R.id.tvjobKm); tv_JobwaitngTime =(TextView)findViewById(R.id.tvjobWaittime); tv_JobwaitngTime.setText("Waiting Time : 0:0"); //update the Km every 1 sec Log.d(tag, "On created "+_ResumeThread); tvjobstartedtime=(TextView)findViewById(R.id.tv_jobStarttime); tvjobstartedtime.setText("Start Time :"+Contsants.jobStartTime); btn_jobFinsh= (Button)findViewById(R.id.btn_jobFinsh); btn_jobFinsh.setOnClickListener(onClickListener); btn_msg= (Button)findViewById(R.id.btn_msg); btn_msg.setOnClickListener(onClickListener); // TODO Auto-generated method stub } @Override public void onStart() { super.onStart(); } @Override public void onResume() { super.onResume(); w = this.getWindow(); w.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD); w.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); w.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON); Log.d("job start on resume",_ThreadFlag+" "+_ResumeThread); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState){ super.onRestoreInstanceState(savedInstanceState); if (sThread.isAlive()){ sThread.setHandler(mHandler); } } @Override protected void onDestroy(){ super.onDestroy(); if (sThread.isAlive()){ sThread.setHandler(null); } } boolean _Paused=false; @Override public void onPause() { super.onPause(); _Paused=true; } @Override public void onBackPressed() { // do nothing. } private OnClickListener onClickListener = new OnClickListener() { @Override public void onClick(final View v) { switch(v.getId()){ case R.id.btn_jobFinsh: //DO something _ThreadFlag=true; StateManager.JobStatus=StateManager.jobstatus_dropped; tcpSocket.SendMessage(FramePacket.FrameJobStatusCmd(Contsants.Jobno,StateManager.JobStatus) ); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy HH:mm"); String currentDateandTime = sdf.format(new Date()); Contsants.jobEndTime=currentDateandTime; Intent i = new Intent(getApplicationContext(),JobCompletionScreen.class); startActivity(i); sThread.setHandler(null); finish(); break; case R.id.btn_msg: /*Intent iNAV = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=12.920629,77.610643&amp;daddr=12.990346, 77.589521") ); startActivity(iNAV);*/ Intent imsg = new Intent(getApplicationContext(),MessageList.class); startActivity(imsg); break; } } }; static Handler mHandler =new Handler(){ @Override public void handleMessage(Message message){ //update UI Bundle b = message.getData(); float odometer = b.getFloat("My Odometer"); int waiting =b.getInt("waiting Time"); tv_JobKm.setText(odometer+" Km"); tv_JobwaitngTime.setText("Waiting Time : "+Integer.toString((waiting / 60)) +":"+ Integer.toString((waiting% 60))); } }; private class MyThread extends Thread{ private Handler mHandler; public MyThread(Handler handler){ super(); mHandler=handler; } @Override public void run(){ //some long operation if (mHandler!=null) mHandler.sendEmptyMessage(0); _ResumeThread=true; while(!_ThreadFlag) { try { Thread.sleep(1000); Message msg = new Message(); Bundle b = new Bundle(); b.putFloat("My Odometer", (float) (gpsdataElements.Distance-Contsants.jobStartKm)); if(gpsdataElements.Speed==0.0) { Contsants.cont_WaitingTimeInSec++; } b.putInt("waiting Time", Contsants.cont_WaitingTimeInSec); // tv_JobwaitngTime.setText("Waiting Time : "+Integer.toString((Contsants.cont_WaitingTimeInSec / 60)) +":"+ Integer.toString((Contsants.cont_WaitingTimeInSec % 60))); //send message to the handler with the current message handler msg.setData(b); // send message to the handler with the current message handler mHandler.sendMessage(msg); } catch (Exception e) { Log.v("Error", e.toString()); } } } public void setHandler(Handler handler){ mHandler=handler; } } @Override public void messageReceived(String message) { // TODO Auto-generated method stub //Toast.makeText(getApplicationContext(), "Job StartScreem : Recived data :"+message, Toast.LENGTH_LONG).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload