gpt4 book ai didi

java - ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent )

转载 作者:行者123 更新时间:2023-12-02 08:17:52 25 4
gpt4 key购买 nike

据我所知,我的应用程序看起来已经完成,虽然它不是防弹的,但它应该可以完成测试工作,但问题是当我构建时,我遇到了这些错误。

Thread [<1> main] (Suspended (exception RuntimeException))  
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1573
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1667
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117
ActivityThread$H.handleMessage(Message) line: 935
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 3691
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 847
ZygoteInit.main(String[]) line: 605
NativeStart.main(String[]) line: not available [native method]

这是我的代码Main.java

package bitcoin.Virwox;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

public class Main extends Activity {

//Variables
ProgressDialog dialog = new ProgressDialog(null);
JSONObject jArray = new JSONObject();
int BTCSell;
int GBPBuy;
int Ammount;
int BTCSLLAmmount;
int GBPSLLAmmount;
int Total;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}


public void Start(View view) {
dialog.setTitle("Please Wait");
dialog.setIcon(R.drawable.icon);
dialog.setMessage("Loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();

Ammount = Integer.valueOf(findViewById(R.id.Amountinputtxt).toString());
GetInfo();
Process();

dialog.hide();
}

public void GetInfo() {
try {
BestBuySell();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final CheckBox checkBox = (CheckBox) findViewById(R.id.VirwoxFeeChk);
if (checkBox.isChecked()) {
ProcessEstimates();
Total = GBPSLLAmmount;
}
else {
int holder;
holder = BTCSell*Ammount;
Total = (int)(holder/GBPBuy);
}

}

private void ProcessEstimates() {
try {
BTCSLL();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
GBPSLL();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public void BTCSLL() throws Exception{
//retrieve data for BTC>SLL
try {
HttpClient httpclient = new DefaultHttpClient();
String http = "http://api.virwox.com/api/json.php?method=estimateMarketOrder&amount="+Ammount+"&orderType=SELL&instrument=BTC/SLL";
HttpGet httpget = new HttpGet(http);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

byte buffer[] = new byte[1024] ;
InputStream is = entity.getContent() ;
int numBytes = is.read(buffer) ;
is.close();

String entityContents = new String(buffer,0,numBytes) ;
Log.d("xxx",entityContents);

try {
jArray = new JSONObject(entityContents);

} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{}

//Parse Data
JSONArray result = jArray.getJSONArray("result");
//parse BTC>SLL
JSONObject f = result.getJSONObject(0);
BTCSLLAmmount = Integer.parseInt(f.getString("amount"));
}
public void GBPSLL() throws JSONException{
//retrieve data for SLL>GBP
try {
HttpClient httpclient = new DefaultHttpClient();
String http = "http://api.virwox.com/api/json.php?method=estimateMarketOrder&amount="+BTCSLLAmmount+"&orderType=BUY&instrument=SLL/GBP";
HttpGet httpget = new HttpGet(http);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

byte buffer[] = new byte[1024] ;
InputStream is = entity.getContent() ;
int numBytes = is.read(buffer) ;
is.close();

String entityContents = new String(buffer,0,numBytes) ;
Log.d("xxx",entityContents);

try {
jArray = new JSONObject(entityContents);

} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{}

//Parse Data
JSONArray result = jArray.getJSONArray("result");
//parse BTC>SLL
JSONObject e2 = result.getJSONObject(0);
GBPSLLAmmount = Integer.parseInt(e2.getString("amount"));
}

public void Process() {
CheckBox checkBox = (CheckBox) findViewById(R.id.PaypalFeeChk);
if (checkBox.isChecked()) {
Total = Total - 1;
}
TextView tv = (TextView)findViewById(R.id.Outputtxt);
tv.setText("Total: £" + Total + ".00");

CurrentRate();
}

public void CurrentRate(){
float holder;
holder = BTCSell/GBPBuy;
BigDecimal payment = new BigDecimal(holder);
NumberFormat n = NumberFormat.getCurrencyInstance(Locale.UK);
double doublePayment = payment.doubleValue();
String s = n.format(doublePayment);
TextView tv = (TextView)findViewById(R.id.CurrentRatetxt);
tv.setText(s);
}

public void BestBuySell() throws Exception, IOException{
//retrieve data
try {
HttpClient httpclient = new DefaultHttpClient();

HttpGet httpget = new HttpGet("http://api.virwox.com/api/json.php?method=getBestPrices&symbols[0]=BTC/SLL&symbols[1]=GBP/SLL");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

byte buffer[] = new byte[1024] ;
InputStream is = entity.getContent() ;
int numBytes = is.read(buffer) ;
is.close();

String entityContents = new String(buffer,0,numBytes) ;
Log.d("xxx",entityContents);

try {
jArray = new JSONObject(entityContents);

} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{}
}
finally{}
//parse info
JSONArray result = jArray.getJSONArray("result");
//parse BTC>SLL
JSONObject e = result.getJSONObject(0);
BTCSell = Integer.parseInt(e.getString("bestBuyPrice"));
//Parse SLL>GBP
e = result.getJSONObject(1);
GBPBuy = Integer.parseInt(e.getString("bestSellPrice"));
}
}

这是布局Main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget43" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:text="BTC-&gt;GBP" android:textSize="45sp" android:layout_width="fill_parent" android:layout_height="78px" android:layout_x="1dip" android:layout_y="20dip" android:gravity="center_horizontal" android:id="@+id/Title"></TextView>
<Button android:layout_width="350px" android:layout_height="wrap_content" android:layout_x="42dip" android:layout_y="298dip" android:text="Calculate" android:id="@+id/Button"></Button>
<TextView android:textSize="15sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="14dip" android:layout_y="388dip" android:text="Current Exchange rate: " android:id="@+id/Ratetxt"></TextView>
<CheckBox android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_y="148dip" android:layout_x="190dip" android:text="Paypal Fee" android:id="@+id/PaypalFeeChk"></CheckBox>
<CheckBox android:checked="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="190dip" android:layout_y="106dip" android:text="Virwox Fees" android:id="@+id/VirwoxFeeChk"></CheckBox>
<TextView android:layout_x="182dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_y="388dip" android:textSize="15sp" android:id="@+id/CurrentRatetxt" android:text="£0.00"></TextView>
<TextView android:layout_height="wrap_content" android:layout_x="1dip" android:layout_y="245dip" android:gravity="center" android:textSize="18sp" android:id="@+id/Outputtxt" android:text="£0.00" android:layout_width="fill_parent"></TextView>
<EditText android:text="EditText" android:layout_width="200px" android:layout_height="wrap_content" android:layout_x="48dip" android:layout_y="126dip" android:numeric="integer" android:id="@+id/Amountinputtxt"></EditText>
</AbsoluteLayout>

这是怎么造成的以及如何解决这个问题?

最佳答案

尝试在 onCreate 方法之前声明 Context 变量:

Context thisContext = this;             

@Override
public void onCreate(Bundle savedInstanceState) {

然后当你声明时:

AlertDialog.Builder builder = new AlertDialog.Builder(thisContext);

使用上下文变量。

不要使用:

AlertDialog.Builder(this);

关于java - ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6005818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com