我刚开始进行android应用程序开发。我有使用java开发应用程序的新手经验。例如,我写了一个简单的Fibonacci程序,其中添加和显示数字。我在java中编写了用于迭代和递归的编码,在c中用于迭代和递归。并比较他们的执行时间。该程序安装在模拟器中,当我尝试计算该值时,它就会退出。在Logcat中,它显示以下异常和抛出的错误。任何人都可以告诉我这些是如何解决它们的。我在下面添加了编码。
FibActivity.java
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
public class FibActivity extends Activity implements OnClickListener {
private EditText input;
private RadioGroup type;
private TextView output;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.input = (EditText) super.findViewById(R.id.input);
this.type = (RadioGroup) super.findViewById(R.id.type);
this.output = (TextView) super.findViewById(R.id.output);
Button button = (Button) super.findViewById(R.id.button);
button.setOnClickListener(this);
}
public void onClick(View view) {
String s = this.input.getText().toString();
if(TextUtils.isEmpty(s)) {
return;
}
final ProgressDialog dialog = ProgressDialog.show(this, "", "Calculating...", true);
final long n = Long.parseLong(s);
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
long result = 0;
long t = System.currentTimeMillis();
switch(FibActivity.this.type.getCheckedRadioButtonId()) {
case R.id.type_fib_jr:
result = FibLib.fibJR(n);
case R.id.type_fib_ji:
result = FibLib.fibJI(n);
case R.id.type_fib_nr:
result = FibLib.fibNR(n);
case R.id.type_fib_ni:
result = FibLib.fibNI(n);
}
t = System.currentTimeMillis() - t;
return String.format("fib(%d)=%d in %d ms", n, result, t);
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
dialog.dismiss();
FibActivity.this.output.setText(result);
}
}.execute();
}
}
com_android_fibnat_FibLib.c
#include <com_android_fibnat_FibLib.h>
static jlong fib(jlong n) {
return n <= 0? 0 : n==1 ? 1 : fib(n-1) + fib(n-2);
}
JNIEXPORT jlong JNICALL Java_com_android_fibnat_FibLib_fibNR
(JNIEnv *env, jclass c, jlong n) {
return fib(n);
}
JNIEXPORT jlong JNICALL Java_com_android_fibnat_FibLib_fibNI
(JNIEnv *env, jclass c, jlong n) {
jlong p = -1;
jlong result = 1;
jlong i;
for(i=0;i<=n;i++) {
jlong sum = result + p;
p = result;
result = sum;
}
return result;
}
以下是我收到的错误列表 https://drive.google.com/file/d/0B3NEoejIh-a0S0dOcVlZOVFHU00/view?usp=sharing[ ^]
答案 0 :(得分:0)
您似乎缺少原生图书馆(libcom_android_fibnative_FibLib.so)。
它在你的APK里面吗? (在lib/(x86|armeabi|armeabi-v7a)/
下,您可以通过将其打开为.zip文件来查看您的APK。)